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:
parent
22e96447b4
commit
9b08ce6fd8
@ -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>,
|
||||
|
@ -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);
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user