Skip to content

Commit

Permalink
Display alias with --show NAME if one exists
Browse files Browse the repository at this point in the history
Given the following justfile:

    alias b := build
    build:
        echo 'Building!'

Just will show the alias along with the recipe:

    $ just --show b
    alias b := build
    build:
        echo 'Building!'
  • Loading branch information
casey committed Aug 24, 2019
1 parent 04a2b64 commit e8c2542
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ impl<'a> Justfile<'a> where {
Ok(())
}

pub fn get_alias(&self, name: &str) -> Option<&Alias> {
self.aliases.get(name)
}

pub fn get_recipe(&self, name: &str) -> Option<&Recipe<'a>> {
if let Some(recipe) = self.recipes.get(name) {
Some(recipe)
Expand Down
25 changes: 14 additions & 11 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,18 +446,21 @@ pub fn run() {
}

if let Some(name) = matches.value_of("SHOW") {
match justfile.get_recipe(name) {
Some(recipe) => {
println!("{}", recipe);
process::exit(EXIT_SUCCESS);
}
None => {
eprintln!("Justfile does not contain recipe `{}`.", name);
if let Some(suggestion) = justfile.suggest(name) {
eprintln!("Did you mean `{}`?", suggestion);
}
process::exit(EXIT_FAILURE)
if let Some(alias) = justfile.get_alias(name) {
let recipe = justfile.get_recipe(alias.target).unwrap();
println!("{}", alias);
println!("{}", recipe);
process::exit(EXIT_SUCCESS);
}
if let Some(recipe) = justfile.get_recipe(name) {
println!("{}", recipe);
process::exit(EXIT_SUCCESS);
} else {
eprintln!("Justfile does not contain recipe `{}`.", name);
if let Some(suggestion) = justfile.suggest(name) {
eprintln!("Did you mean `{}`?", suggestion);
}
process::exit(EXIT_FAILURE)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ integration_test! {
justfile: "foo:\n bar\nalias f := foo",
args: ("--show", "f"),
stdin: "",
stdout: "foo:
stdout: "alias f := foo\nfoo:
bar
",
stderr: "",
Expand Down

0 comments on commit e8c2542

Please sign in to comment.