diff --git a/src/justfile.rs b/src/justfile.rs index 8dddad7..288a9c6 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -91,16 +91,7 @@ impl<'a> Justfile<'a> where { let mut rest = arguments; while let Some((argument, mut tail)) = rest.split_first() { - let get_recipe = |name| { - if let Some(recipe) = self.recipes.get(name) { - Some(recipe) - } else if let Some(alias) = self.aliases.get(name) { - self.recipes.get(alias.target) - } else { - None - } - }; - if let Some(recipe) = get_recipe(argument) { + if let Some(recipe) = self.get_recipe(argument) { if recipe.parameters.is_empty() { grouped.push((recipe, &tail[0..0])); } else { @@ -150,6 +141,16 @@ impl<'a> Justfile<'a> where { Ok(()) } + pub fn get_recipe(&self, name: &str) -> Option<&Recipe<'a>> { + if let Some(recipe) = self.recipes.get(name) { + Some(recipe) + } else if let Some(alias) = self.aliases.get(name) { + self.recipes.get(alias.target) + } else { + None + } + } + fn run_recipe<'b>( &self, context: &'b RecipeContext<'a>, diff --git a/src/run.rs b/src/run.rs index 14e899c..35d5d9e 100644 --- a/src/run.rs +++ b/src/run.rs @@ -449,7 +449,7 @@ pub fn run() { } if let Some(name) = matches.value_of("SHOW") { - match justfile.recipes.get(name) { + match justfile.get_recipe(name) { Some(recipe) => { println!("{}", recipe); process::exit(EXIT_SUCCESS); diff --git a/tests/integration.rs b/tests/integration.rs index 1062cb0..0eac478 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -272,6 +272,32 @@ integration_test! { status: EXIT_FAILURE, } +integration_test! { + name: alias_show, + justfile: "foo:\n bar\nalias f := foo", + args: ("--show", "f"), + stdin: "", + stdout: "foo: + bar +", + stderr: "", + status: EXIT_SUCCESS, +} + +integration_test! { + name: alias_show_missing_target, + justfile: "alias f := foo", + args: ("--show", "f"), + stdin: "", + stdout: "", + stderr: "error: Alias `f` has an unknown target `foo` + | +1 | alias f := foo + | ^ +", + status: EXIT_FAILURE, +} + integration_test! { name: default, justfile: "default:\n echo hello\nother: \n echo bar",