diff --git a/src/main.rs b/src/main.rs index e0d9329..d2d720c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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()?; @@ -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(()) } diff --git a/src/resolver.rs b/src/resolver.rs index 7334a72..ad96ad3 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -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 { + 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