From e8c25423b8a46aafb3e044ec5f97fe3e0eaf3e8c Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 23 Aug 2019 20:45:57 -0700 Subject: [PATCH] Display alias with `--show NAME` if one exists 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!' --- src/justfile.rs | 4 ++++ src/run.rs | 25 ++++++++++++++----------- tests/integration.rs | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/justfile.rs b/src/justfile.rs index 288a9c6..6bf733e 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -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) diff --git a/src/run.rs b/src/run.rs index 13e205d..61324c6 100644 --- a/src/run.rs +++ b/src/run.rs @@ -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) } } diff --git a/tests/integration.rs b/tests/integration.rs index 76db1a4..5cd5df3 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -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: "",