From 6e8289c624e98b3af08c05a73ffc9bcb1fa1ebf3 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 12 Nov 2016 11:40:52 -0800 Subject: [PATCH] Make `--list` print recipes with arguments (#88) Added `--summary` which just prints recipe names, like `--list` previous to this change. Fixes #75 --- README.md | 7 ++++++- justfile | 4 ++-- src/app.rs | 31 ++++++++++++++++++++++++++----- src/integration.rs | 23 +++++++++++++++++++++-- src/lib.rs | 7 ++----- src/unit.rs | 4 ++-- 6 files changed, 59 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e282ca1a..94fab36f 100644 --- a/README.md +++ b/README.md @@ -302,7 +302,12 @@ Hello from ruby! ```sh $ just --list -js perl polyglot python ruby +Available recipes: + js + perl + polyglot + python + ruby $ just --show perl perl: #!/usr/bin/env perl diff --git a/justfile b/justfile index 1175b054..17199605 100644 --- a/justfile +++ b/justfile @@ -17,8 +17,8 @@ build: check: cargo check -watch command='test': - cargo watch {{command}} +watch COMMAND='test': + cargo watch {{COMMAND}} version = `sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/v\1/p' Cargo.toml` diff --git a/src/app.rs b/src/app.rs index 9131a110..62e5feac 100644 --- a/src/app.rs +++ b/src/app.rs @@ -57,13 +57,15 @@ pub fn app() { .arg(Arg::with_name("list") .short("l") .long("list") - .help("Lists available recipes") + .help("Lists available recipes and their arguments") .conflicts_with("dump") - .conflicts_with("show")) + .conflicts_with("show") + .conflicts_with("summary")) .arg(Arg::with_name("dump") .long("dump") .help("Prints entire justfile") .conflicts_with("show") + .conflicts_with("summary") .conflicts_with("list")) .arg(Arg::with_name("show") .short("s") @@ -72,6 +74,13 @@ pub fn app() { .value_name("recipe") .help("Shows information about ") .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")) .arg(Arg::with_name("quiet") .short("q") @@ -170,9 +179,9 @@ pub fn app() { } ); - if matches.is_present("list") { + if matches.is_present("summary") { if justfile.count() == 0 { - warn!("Justfile contains no recipes"); + warn!("Justfile contains no recipes."); } else { println!("{}", justfile.recipes().join(" ")); } @@ -184,8 +193,20 @@ pub fn app() { 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") { - match justfile.get(name) { + match justfile.recipes.get(name) { Some(recipe) => { println!("{}", recipe); process::exit(0); diff --git a/src/integration.rs b/src/integration.rs index 5d48c3e7..5d054f52 100644 --- a/src/integration.rs +++ b/src/integration.rs @@ -193,14 +193,14 @@ c: b } #[test] -fn list() { +fn summary() { let text = "b: a a: d: c c: b"; integration_test( - &["--list"], + &["--summary"], text, 0, "a b c d\n", @@ -1074,3 +1074,22 @@ hello a b='B' c='C': "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' +", + "", + ); +} diff --git a/src/lib.rs b/src/lib.rs index f48943af..3fbb6e10 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,7 +84,8 @@ impl<'a> Display for Parameter<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { write!(f, "{}", self.name)?; if let Some(ref default) = self.default { - write!(f, r#"="{}""#, default)?; + let escaped = default.chars().flat_map(char::escape_default).collect::();; + write!(f, r#"='{}'"#, escaped)?; } Ok(()) } @@ -1141,10 +1142,6 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b { ran.insert(recipe.name); Ok(()) } - - fn get(&self, name: &str) -> Option<&Recipe<'a>> { - self.recipes.get(name) - } } impl<'a> Display for Justfile<'a> { diff --git a/src/unit.rs b/src/unit.rs index 26208766..2bf074e8 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -262,7 +262,7 @@ fn parse_string_default() { foo a="b\t": - "#, r#"foo a="b ":"#); + "#, r#"foo a='b\t':"#); } #[test] @@ -272,7 +272,7 @@ fn parse_raw_string_default() { foo a='b\t': - "#, r#"foo a="b\t":"#); + "#, r#"foo a='b\\t':"#); } #[test]