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!'
This commit is contained in:
parent
04a2b6461e
commit
e8c25423b8
@ -141,6 +141,10 @@ impl<'a> Justfile<'a> where {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_alias(&self, name: &str) -> Option<&Alias> {
|
||||||
|
self.aliases.get(name)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_recipe(&self, name: &str) -> Option<&Recipe<'a>> {
|
pub fn get_recipe(&self, name: &str) -> Option<&Recipe<'a>> {
|
||||||
if let Some(recipe) = self.recipes.get(name) {
|
if let Some(recipe) = self.recipes.get(name) {
|
||||||
Some(recipe)
|
Some(recipe)
|
||||||
|
25
src/run.rs
25
src/run.rs
@ -446,18 +446,21 @@ pub fn run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(name) = matches.value_of("SHOW") {
|
if let Some(name) = matches.value_of("SHOW") {
|
||||||
match justfile.get_recipe(name) {
|
if let Some(alias) = justfile.get_alias(name) {
|
||||||
Some(recipe) => {
|
let recipe = justfile.get_recipe(alias.target).unwrap();
|
||||||
println!("{}", recipe);
|
println!("{}", alias);
|
||||||
process::exit(EXIT_SUCCESS);
|
println!("{}", recipe);
|
||||||
}
|
process::exit(EXIT_SUCCESS);
|
||||||
None => {
|
}
|
||||||
eprintln!("Justfile does not contain recipe `{}`.", name);
|
if let Some(recipe) = justfile.get_recipe(name) {
|
||||||
if let Some(suggestion) = justfile.suggest(name) {
|
println!("{}", recipe);
|
||||||
eprintln!("Did you mean `{}`?", suggestion);
|
process::exit(EXIT_SUCCESS);
|
||||||
}
|
} else {
|
||||||
process::exit(EXIT_FAILURE)
|
eprintln!("Justfile does not contain recipe `{}`.", name);
|
||||||
|
if let Some(suggestion) = justfile.suggest(name) {
|
||||||
|
eprintln!("Did you mean `{}`?", suggestion);
|
||||||
}
|
}
|
||||||
|
process::exit(EXIT_FAILURE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ integration_test! {
|
|||||||
justfile: "foo:\n bar\nalias f := foo",
|
justfile: "foo:\n bar\nalias f := foo",
|
||||||
args: ("--show", "f"),
|
args: ("--show", "f"),
|
||||||
stdin: "",
|
stdin: "",
|
||||||
stdout: "foo:
|
stdout: "alias f := foo\nfoo:
|
||||||
bar
|
bar
|
||||||
",
|
",
|
||||||
stderr: "",
|
stderr: "",
|
||||||
|
Loading…
Reference in New Issue
Block a user