Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,16 @@ fn cmd_run(
if command.is_empty() {
anyhow::bail!("No command specified");
}

let status = Command::new(&command[0])

// Resolve command alias: if command[0] matches a `commands:` key
// in any resolved package, substitute it with the full path.
let commands_map = resolved.commands();
let executable = commands_map
.get(&command[0])
.cloned()
.unwrap_or_else(|| command[0].clone());

let status = Command::new(&executable)
.args(&command[1..])
.envs(&env)
.status()?;
Expand Down Expand Up @@ -167,7 +175,13 @@ fn cmd_info(config: &Config, package: &str) -> Result<()> {
println!(" {}: {}", key, value);
}
}

if !pkg.commands.is_empty() {
println!("Commands:");
for (alias, target) in &pkg.commands {
println!(" {}: {}", alias, target);
}
}

Ok(())
}

Expand Down
18 changes: 18 additions & 0 deletions src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ impl ResolvedPackages {
pub fn packages(&self) -> &[Package] {
&self.packages
}

/// Build a merged command alias map from all resolved packages.
///
/// Command values are expanded against the resolved environment so that
/// references like `${PACKAGE_ROOT}` and `${PATH}` resolve to real paths.
pub fn commands(&self) -> HashMap<String, String> {
let env = self.environment();
let mut commands = HashMap::new();

for package in &self.packages {
for (alias, target) in &package.commands {
let expanded = package.expand_env_value(target, &env);
commands.insert(alias.clone(), expanded);
}
}

commands
}
}

/// Package resolver
Expand Down
Loading