mirror of
https://github.com/casey/just.git
synced 2024-11-26 11:43:43 +03:00
Add {:#} format printing to justfile for --show
This commit is contained in:
parent
a8a5c342e7
commit
01df3d5e4a
2
justfile
2
justfile
@ -1,7 +1,7 @@
|
||||
test-all: test test-integration
|
||||
|
||||
test:
|
||||
cargo test --lib --test integration
|
||||
cargo test --lib
|
||||
|
||||
test-integration: build
|
||||
cargo test --test integration
|
||||
|
7
notes
7
notes
@ -2,11 +2,10 @@ notes
|
||||
-----
|
||||
|
||||
- integration testing
|
||||
. --show should not display variable and expression values
|
||||
. 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
|
||||
. test that a few error messages are correct
|
||||
. test full output
|
||||
. underline problem token in error messages
|
||||
|
||||
- figure out argument passing:
|
||||
@ -61,6 +60,8 @@ notes
|
||||
enhancements:
|
||||
|
||||
- save result of commands in variables
|
||||
- multi line strings
|
||||
- raw strings
|
||||
- iteration: {{x for x in y}}
|
||||
- allow calling recipes in a justfile in a different directory:
|
||||
. just ../foo # ../justfile:foo
|
||||
|
@ -108,7 +108,7 @@ pub fn app() {
|
||||
if let Some(name) = matches.value_of("show") {
|
||||
match justfile.get(name) {
|
||||
Some(recipe) => {
|
||||
warn!("{}", recipe);
|
||||
println!("{}", recipe);
|
||||
process::exit(0);
|
||||
}
|
||||
None => die!("justfile contains no recipe \"{}\"", name)
|
||||
|
@ -120,21 +120,45 @@ c: b";
|
||||
);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn show() {
|
||||
// let text =
|
||||
// r#"hello = "foo"
|
||||
// recipe:
|
||||
// echo {{hello}}"#;
|
||||
// integration_test(
|
||||
// "show",
|
||||
// &["--show", "recipe"],
|
||||
// text,
|
||||
// 0,
|
||||
// "foo\n",
|
||||
// "",
|
||||
// );
|
||||
// }
|
||||
#[test]
|
||||
fn select() {
|
||||
let text =
|
||||
"b:
|
||||
@echo b
|
||||
a:
|
||||
@echo a
|
||||
d:
|
||||
@echo d
|
||||
c:
|
||||
@echo c";
|
||||
integration_test(
|
||||
"select",
|
||||
&["d", "c"],
|
||||
text,
|
||||
0,
|
||||
"d\nc\n",
|
||||
"",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show() {
|
||||
let text =
|
||||
r#"hello = "foo"
|
||||
bar = hello + hello
|
||||
recipe:
|
||||
echo {{hello + "bar" + bar}}"#;
|
||||
integration_test(
|
||||
"show",
|
||||
&["--show", "recipe"],
|
||||
text,
|
||||
0,
|
||||
r#"recipe:
|
||||
echo {{hello + "bar" + bar}}
|
||||
"#,
|
||||
"",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status() {
|
||||
|
27
src/lib.rs
27
src/lib.rs
@ -238,10 +238,17 @@ impl<'a> Display for Recipe<'a> {
|
||||
if j == 0 {
|
||||
try!(write!(f, " "));
|
||||
}
|
||||
match *piece {
|
||||
Fragment::Text{ref text} => try!(write!(f, "{}", text.lexeme)),
|
||||
Fragment::Expression{ref expression, value: None} => try!(write!(f, "{}{} # ? {}", "{{", expression, "}}")),
|
||||
Fragment::Expression{ref expression, value: Some(ref string)} => try!(write!(f, "{}{} # \"{}\"{}", "{{", expression, string, "}}")),
|
||||
if f.alternate() {
|
||||
match *piece {
|
||||
Fragment::Text{ref text} => try!(write!(f, "{}", text.lexeme)),
|
||||
Fragment::Expression{ref expression, value: None} => try!(write!(f, "{}{} # ? {}", "{{", expression, "}}")),
|
||||
Fragment::Expression{ref expression, value: Some(ref string)} => try!(write!(f, "{}{} # \"{}\"{}", "{{", expression, string, "}}")),
|
||||
}
|
||||
} else {
|
||||
match *piece {
|
||||
Fragment::Text{ref text} => try!(write!(f, "{}", text.lexeme)),
|
||||
Fragment::Expression{ref expression, ..} => try!(write!(f, "{}{}{}", "{{", expression, "}}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
if i + 1 < self.lines.len() {
|
||||
@ -630,14 +637,22 @@ impl<'a> Display for Justfile<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
let mut items = self.recipes.len() + self.assignments.len();
|
||||
for (name, expression) in &self.assignments {
|
||||
try!(write!(f, "{} = {} # \"{}\"", name, expression, self.values.get(name).unwrap()));
|
||||
if f.alternate() {
|
||||
try!(write!(f, "{} = {} # \"{}\"", name, expression, self.values.get(name).unwrap()));
|
||||
} else {
|
||||
try!(write!(f, "{} = {}", name, expression));
|
||||
}
|
||||
items -= 1;
|
||||
if items != 0 {
|
||||
try!(write!(f, "\n"));
|
||||
}
|
||||
}
|
||||
for recipe in self.recipes.values() {
|
||||
try!(write!(f, "{}", recipe));
|
||||
if f.alternate() {
|
||||
try!(write!(f, "{:#}", recipe));
|
||||
} else {
|
||||
try!(write!(f, "{}", recipe));
|
||||
}
|
||||
items -= 1;
|
||||
if items != 0 {
|
||||
try!(write!(f, "\n"));
|
||||
|
@ -62,7 +62,7 @@ fn parse_success(text: &str) -> Justfile {
|
||||
|
||||
fn parse_summary(input: &str, output: &str) {
|
||||
let justfile = parse_success(input);
|
||||
let s = justfile.to_string();
|
||||
let s = format!("{:#}", justfile);
|
||||
if s != output {
|
||||
println!("got:\n\"{}\"\n", s);
|
||||
println!("\texpected:\n\"{}\"", output);
|
||||
|
Loading…
Reference in New Issue
Block a user