1
1
mirror of https://github.com/casey/just.git synced 2024-11-23 11:04:09 +03:00

Display alias target with --show (#443)

This commit is contained in:
Casey Rodarmor 2019-05-15 15:43:47 -04:00 committed by GitHub
parent 22e96447b4
commit 9b08ce6fd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 11 deletions

View File

@ -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>,

View File

@ -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);

View File

@ -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",