diff --git a/Cargo.lock b/Cargo.lock index b1e2b21..351722c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -268,7 +268,7 @@ dependencies = [ [[package]] name = "dotree" -version = "0.6.0" +version = "0.7.0" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index bc2a918..e31884b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dotree" -version = "0.6.0" +version = "0.7.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/grammar.pest b/grammar.pest index 22bdb88..1a75aa7 100644 --- a/grammar.pest +++ b/grammar.pest @@ -36,7 +36,7 @@ cmd_body = { ((cmd_settings|vars_def|shell_def) ~ NEWLINE)* ~ quick_command } vars_def = { "vars" ~ var_def ~ (DEF_SEP* ~ var_def)* } DEF_SEP = _{"," ~ NEWLINE*} var_def = { symbol ~ default_var? } -default_var = { "=" ~ normal_string } +default_var = { "=" ~ string } cmd_settings = { "set" ~ symbol ~ (DEF_SEP* ~ symbol)* } shell_def = {"shell" ~ (string|word)+ } diff --git a/src/core.rs b/src/core.rs index 82468d2..24d870c 100644 --- a/src/core.rs +++ b/src/core.rs @@ -257,10 +257,10 @@ fn query_env_var( if line.is_empty() { if let Some(default_val) = default_val { hist.push(default_val.to_string()); + return Ok(hist); } - } else { - hist.push(line); } + hist.push(line); Ok(hist) } diff --git a/src/parser.rs b/src/parser.rs index 83659b3..7b14a1f 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -294,8 +294,7 @@ fn parse_vars_def(p: Pair<'_, Rule>) -> Vec { let name = name_def.as_str().to_string(); let value = value_def.map(|v| { assert!(v.as_rule() == Rule::default_var, "unexpected rule: {p:#?}"); - // v(default_var) -> normal_string -> normal_content - v.inext().inext().as_str().to_string() + from_string(v.inext()) }); VarDef { name, value } @@ -685,8 +684,14 @@ Config { name: None, shell: None, env_vars: [ - "foo", - "bar", + VarDef { + name: "foo", + value: None, + }, + VarDef { + name: "bar", + value: None, + }, ], }, ), diff --git a/tests/bash_tests/arg_test.bash b/tests/bash_tests/arg_test.bash new file mode 100644 index 0000000..555e27c --- /dev/null +++ b/tests/bash_tests/arg_test.bash @@ -0,0 +1,8 @@ +$DT -c arg_test.dt f alpha beta gamma + +printf "lala\n" | $DT -c arg_test.dt f alpha beta + +printf "\n" | $DT -c arg_test.dt f alpha beta + +printf "\n\n\n" | $DT -c arg_test.dt f + diff --git a/tests/bash_tests/arg_test.dt b/tests/bash_tests/arg_test.dt new file mode 100644 index 0000000..0402a78 --- /dev/null +++ b/tests/bash_tests/arg_test.dt @@ -0,0 +1,6 @@ +menu root { + f: cmd { + vars a, b, c="foo" + "echo $a $b $c" + } +} diff --git a/tests/bash_tests/arg_test.out b/tests/bash_tests/arg_test.out new file mode 100644 index 0000000..3a94b59 --- /dev/null +++ b/tests/bash_tests/arg_test.out @@ -0,0 +1,4 @@ +[?25l[?25halpha beta gamma +[?25l[?25h alpha beta lala +[?25l[?25h alpha beta foo +[?25l[?25h   foo