Skip to content

Commit

Permalink
Display alias target with --show (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored May 15, 2019
1 parent 22e9644 commit 9b08ce6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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>,
Expand Down
2 changes: 1 addition & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9b08ce6

Please sign in to comment.