From 3c80f7f7ae2e46d2f2b102088373ae976e2df7d7 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 28 Oct 2016 16:41:46 -0700 Subject: [PATCH] Add '--debug' flag to print justfile with evaluated expressions and variables --- notes | 1 - src/app.rs | 8 ++++++++ src/lib.rs | 4 ++-- src/tests.rs | 10 +++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/notes b/notes index 86a958b..fc113b8 100644 --- a/notes +++ b/notes @@ -3,7 +3,6 @@ notes - integration testing . get value of variable --evaluate --variable - . --info that prints whole justfile . run app with command line options and test full output (stderr and stdout) . exercise all features and all command line options . underline problem token in error messages diff --git a/src/app.rs b/src/app.rs index 6e621f2..77d71ea 100644 --- a/src/app.rs +++ b/src/app.rs @@ -28,6 +28,9 @@ pub fn app() { .short("l") .long("list") .help("Lists available recipes")) + .arg(Arg::with_name("debug") + .long("debug") + .help("Prints the justfile with debugging information, such as evaluated expression and assignment")) .arg(Arg::with_name("show") .short("s") .long("show") @@ -96,6 +99,11 @@ pub fn app() { let justfile = super::parse(&text).unwrap_or_else(|error| die!("{}", error)); + if matches.is_present("debug") { + println!("{:#}", justfile); + process::exit(0); + } + if matches.is_present("list") { if justfile.count() == 0 { warn!("Justfile contains no recipes"); diff --git a/src/lib.rs b/src/lib.rs index fdce1ee..3ef5b04 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -644,7 +644,7 @@ impl<'a> Display for Justfile<'a> { } items -= 1; if items != 0 { - try!(write!(f, "\n")); + try!(write!(f, "\n\n")); } } for recipe in self.recipes.values() { @@ -655,7 +655,7 @@ impl<'a> Display for Justfile<'a> { } items -= 1; if items != 0 { - try!(write!(f, "\n")); + try!(write!(f, "\n\n")); } } Ok(()) diff --git a/src/tests.rs b/src/tests.rs index d7f9196..34b68d1 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -246,8 +246,11 @@ hello a b c : x y z #hello 2 3 ", "bar = foo # \"xx\" + foo = \"xx\" # \"xx\" + goodbye = \"y\" # \"y\" + hello a b c: x y z #! blah #blarg @@ -255,8 +258,11 @@ hello a b c: x y z 1 2 3 + x: + y: + z:"); } @@ -269,7 +275,9 @@ b = "1" "#, r#"a = "0" # "0" + b = "1" # "1" + c = a + b + a + b # "0101""#); } @@ -301,7 +309,7 @@ fn missing_eol() { #[test] fn eof_test() { - parse_summary("x:\ny:\nz:\na b c: x y z", "a b c: x y z\nx:\ny:\nz:"); + parse_summary("x:\ny:\nz:\na b c: x y z", "a b c: x y z\n\nx:\n\ny:\n\nz:"); } #[test]