Make --list print recipes with arguments (#88)

Added `--summary` which just prints recipe names, like `--list` previous
to this change.

Fixes #75
This commit is contained in:
Casey Rodarmor 2016-11-12 11:40:52 -08:00 committed by GitHub
parent a44640b613
commit 6e8289c624
6 changed files with 59 additions and 17 deletions

View File

@ -302,7 +302,12 @@ Hello from ruby!
```sh ```sh
$ just --list $ just --list
js perl polyglot python ruby Available recipes:
js
perl
polyglot
python
ruby
$ just --show perl $ just --show perl
perl: perl:
#!/usr/bin/env perl #!/usr/bin/env perl

View File

@ -17,8 +17,8 @@ build:
check: check:
cargo check cargo check
watch command='test': watch COMMAND='test':
cargo watch {{command}} cargo watch {{COMMAND}}
version = `sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/v\1/p' Cargo.toml` version = `sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/v\1/p' Cargo.toml`

View File

@ -57,13 +57,15 @@ pub fn app() {
.arg(Arg::with_name("list") .arg(Arg::with_name("list")
.short("l") .short("l")
.long("list") .long("list")
.help("Lists available recipes") .help("Lists available recipes and their arguments")
.conflicts_with("dump") .conflicts_with("dump")
.conflicts_with("show")) .conflicts_with("show")
.conflicts_with("summary"))
.arg(Arg::with_name("dump") .arg(Arg::with_name("dump")
.long("dump") .long("dump")
.help("Prints entire justfile") .help("Prints entire justfile")
.conflicts_with("show") .conflicts_with("show")
.conflicts_with("summary")
.conflicts_with("list")) .conflicts_with("list"))
.arg(Arg::with_name("show") .arg(Arg::with_name("show")
.short("s") .short("s")
@ -72,6 +74,13 @@ pub fn app() {
.value_name("recipe") .value_name("recipe")
.help("Shows information about <recipe>") .help("Shows information about <recipe>")
.conflicts_with("dump") .conflicts_with("dump")
.conflicts_with("summary")
.conflicts_with("list"))
.arg(Arg::with_name("summary")
.long("summary")
.help("Lists names of available recipes")
.conflicts_with("dump")
.conflicts_with("show")
.conflicts_with("list")) .conflicts_with("list"))
.arg(Arg::with_name("quiet") .arg(Arg::with_name("quiet")
.short("q") .short("q")
@ -170,9 +179,9 @@ pub fn app() {
} }
); );
if matches.is_present("list") { if matches.is_present("summary") {
if justfile.count() == 0 { if justfile.count() == 0 {
warn!("Justfile contains no recipes"); warn!("Justfile contains no recipes.");
} else { } else {
println!("{}", justfile.recipes().join(" ")); println!("{}", justfile.recipes().join(" "));
} }
@ -184,8 +193,20 @@ pub fn app() {
process::exit(0); process::exit(0);
} }
if matches.is_present("list") {
println!("Available recipes:");
for (name, recipe) in &justfile.recipes {
print!(" {}", name);
for parameter in &recipe.parameters {
print!(" {}", parameter);
}
println!("");
}
process::exit(0);
}
if let Some(name) = matches.value_of("show") { if let Some(name) = matches.value_of("show") {
match justfile.get(name) { match justfile.recipes.get(name) {
Some(recipe) => { Some(recipe) => {
println!("{}", recipe); println!("{}", recipe);
process::exit(0); process::exit(0);

View File

@ -193,14 +193,14 @@ c: b
} }
#[test] #[test]
fn list() { fn summary() {
let text = let text =
"b: a "b: a
a: a:
d: c d: c
c: b"; c: b";
integration_test( integration_test(
&["--list"], &["--summary"],
text, text,
0, 0,
"a b c d\n", "a b c d\n",
@ -1074,3 +1074,22 @@ hello a b='B' c='C':
"echo 0 1 2\n", "echo 0 1 2\n",
); );
} }
#[test]
fn list() {
integration_test(
&["--list"],
r#"
hello a b='B ' c='C':
echo {{a}} {{b}} {{c}}
a Z="\t z":
"#,
0,
r"Available recipes:
a Z='\t z'
hello a b='B\t' c='C'
",
"",
);
}

View File

@ -84,7 +84,8 @@ impl<'a> Display for Parameter<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}", self.name)?; write!(f, "{}", self.name)?;
if let Some(ref default) = self.default { if let Some(ref default) = self.default {
write!(f, r#"="{}""#, default)?; let escaped = default.chars().flat_map(char::escape_default).collect::<String>();;
write!(f, r#"='{}'"#, escaped)?;
} }
Ok(()) Ok(())
} }
@ -1141,10 +1142,6 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b {
ran.insert(recipe.name); ran.insert(recipe.name);
Ok(()) Ok(())
} }
fn get(&self, name: &str) -> Option<&Recipe<'a>> {
self.recipes.get(name)
}
} }
impl<'a> Display for Justfile<'a> { impl<'a> Display for Justfile<'a> {

View File

@ -262,7 +262,7 @@ fn parse_string_default() {
foo a="b\t": foo a="b\t":
"#, r#"foo a="b ":"#); "#, r#"foo a='b\t':"#);
} }
#[test] #[test]
@ -272,7 +272,7 @@ fn parse_raw_string_default() {
foo a='b\t': foo a='b\t':
"#, r#"foo a="b\t":"#); "#, r#"foo a='b\\t':"#);
} }
#[test] #[test]