diff --git a/src/argc_value.rs b/src/argc_value.rs index 0d4ef21c..cfba8a13 100644 --- a/src/argc_value.rs +++ b/src/argc_value.rs @@ -10,6 +10,7 @@ pub enum ArgcValue { PositionalSingle(String, String), PositionalSingleFn(String, String), PositionalMultiple(String, Vec), + ExtraPositionalMultiple(Vec), CmdFn(String), ParamFn(String), Error((String, i32)), @@ -81,7 +82,20 @@ impl ArgcValue { )); positional_args.extend(values); } + ArgcValue::ExtraPositionalMultiple(values) => { + let values = values + .iter() + .map(|v| escape_shell_words(v)) + .collect::>(); + positional_args.extend(values); + } ArgcValue::CmdFn(name) => { + variables.push(format!( + "{}__args=( {} )", + VARIABLE_PREFIX, + positional_args.join(" ") + )); + variables.push(format!("{}__fn={}", VARIABLE_PREFIX, name)); if positional_args.is_empty() { variables.push(name.to_string()); } else { diff --git a/src/matcher.rs b/src/matcher.rs index 4f1f40cf..9ac226db 100644 --- a/src/matcher.rs +++ b/src/matcher.rs @@ -185,8 +185,7 @@ impl<'a, 'b> Matcher<'a, 'b> { let (cmd, cmd_paths) = self.get_cmd_and_paths(self.cmds.len() - 1); let mut output = if cmd.without_params_or_subcommands() && !self.positional_args.is_empty() { - vec![ArgcValue::PositionalMultiple( - "_args".into(), + vec![ArgcValue::ExtraPositionalMultiple( self.positional_args.iter().map(|v| v.to_string()).collect(), )] } else { diff --git a/tests/main_fn_test.rs b/tests/main_fn_test.rs deleted file mode 100644 index 02ace84b..00000000 --- a/tests/main_fn_test.rs +++ /dev/null @@ -1,66 +0,0 @@ -#[test] -fn test_no_main_no_subcommands() { - let script = r###" -# @flag --foo - "###; - plain!(script, &["prog"], ""); -} - -#[test] -fn test_with_main_no_subcommands() { - let script = r###" -# @flag --foo - -main() { - -} - "###; - plain!(script, &["prog"], "main"); -} - -#[test] -fn test_with_main_and_subcommands() { - let script = r###" -# @flag --foo - - -# @cmd -cmd() { -} - -main() { - -} - "###; - plain!(script, &["prog", "cmd"], "cmd"); - snapshot!(None, script, &["prog", "-h"], None); -} - -#[test] -fn test_without_main_but_with_subcommands() { - let script = r###" -# @flag --foo - - -# @cmd -cmd() { -} - - "###; - plain!(script, &["prog", "cmd"], "cmd"); - snapshot!(None, script, &["prog"], None); -} - -#[test] -fn test_without_main_but_with_subcommands2() { - let script = r###" -# @flag --foo - - -# @cmd -cmd() { -} - - "###; - snapshot!(None, script, &["prog", "-h"], None); -} diff --git a/tests/snapshots/integration__main_fn_test__with_main_and_subcommands.snap b/tests/snapshots/integration__main_fn_test__with_main_and_subcommands.snap deleted file mode 100644 index 5f913344..00000000 --- a/tests/snapshots/integration__main_fn_test__with_main_and_subcommands.snap +++ /dev/null @@ -1,21 +0,0 @@ ---- -source: tests/main_fn_test.rs -expression: output ---- -RUN -prog -h - -OUTPUT -cat >&2 <<-'EOF' -USAGE: prog [OPTIONS] - -OPTIONS: - --foo - -h, --help - -COMMANDS: - cmd - -EOF -exit 0 - diff --git a/tests/snapshots/integration__main_fn_test__without_main_but_with_subcommands.snap b/tests/snapshots/integration__main_fn_test__without_main_but_with_subcommands.snap deleted file mode 100644 index d9863840..00000000 --- a/tests/snapshots/integration__main_fn_test__without_main_but_with_subcommands.snap +++ /dev/null @@ -1,21 +0,0 @@ ---- -source: tests/main_fn_test.rs -expression: output ---- -RUN -prog - -OUTPUT -cat >&2 <<-'EOF' -USAGE: prog [OPTIONS] - -OPTIONS: - --foo - -h, --help - -COMMANDS: - cmd - -EOF -exit 0 - diff --git a/tests/snapshots/integration__main_fn_test__without_main_but_with_subcommands2.snap b/tests/snapshots/integration__main_fn_test__without_main_but_with_subcommands2.snap deleted file mode 100644 index 5f913344..00000000 --- a/tests/snapshots/integration__main_fn_test__without_main_but_with_subcommands2.snap +++ /dev/null @@ -1,21 +0,0 @@ ---- -source: tests/main_fn_test.rs -expression: output ---- -RUN -prog -h - -OUTPUT -cat >&2 <<-'EOF' -USAGE: prog [OPTIONS] - -OPTIONS: - --foo - -h, --help - -COMMANDS: - cmd - -EOF -exit 0 - diff --git a/tests/snapshots/integration__spec_test__spec_cmd_alias.snap b/tests/snapshots/integration__spec_test__spec_cmd_alias.snap index 9047a295..c9e07da0 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_alias.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_alias.snap @@ -6,5 +6,7 @@ RUN spec alias OUTPUT +argc__args=( ) +argc__fn=cmd_alias cmd_alias diff --git a/tests/snapshots/integration__spec_test__spec_cmd_combine_shorts.snap b/tests/snapshots/integration__spec_test__spec_cmd_combine_shorts.snap index 112b04b0..bc121fc1 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_combine_shorts.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_combine_shorts.snap @@ -8,5 +8,7 @@ spec cmd_combine_shorts -ac yes OUTPUT argc_a=1 argc_c=yes +argc__args=( ) +argc__fn=cmd_combine_shorts cmd_combine_shorts diff --git a/tests/snapshots/integration__spec_test__spec_cmd_flag_formats_count.snap b/tests/snapshots/integration__spec_test__spec_cmd_flag_formats_count.snap index 9f62e2c1..98f8ee73 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_flag_formats_count.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_flag_formats_count.snap @@ -7,5 +7,7 @@ spec cmd_flag_formats --foo5 --foo5 --foo5 OUTPUT argc_foo5=3 +argc__args=( ) +argc__fn=cmd_flag_formats cmd_flag_formats diff --git a/tests/snapshots/integration__spec_test__spec_cmd_option_names_exec.snap b/tests/snapshots/integration__spec_test__spec_cmd_option_names_exec.snap index 156af944..5d26a483 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_option_names_exec.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_option_names_exec.snap @@ -15,5 +15,7 @@ argc_opt7=a argc_opt8=a argc_opt9=`_fn_foo` argc_op11=a1 +argc__args=( ) +argc__fn=cmd_option_names cmd_option_names diff --git a/tests/snapshots/integration__spec_test__spec_cmd_option_names_exec_eval.snap b/tests/snapshots/integration__spec_test__spec_cmd_option_names_exec_eval.snap index 156af944..5d26a483 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_option_names_exec_eval.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_option_names_exec_eval.snap @@ -15,5 +15,7 @@ argc_opt7=a argc_opt8=a argc_opt9=`_fn_foo` argc_op11=a1 +argc__args=( ) +argc__fn=cmd_option_names cmd_option_names diff --git a/tests/snapshots/integration__spec_test__spec_cmd_option_notations2.snap b/tests/snapshots/integration__spec_test__spec_cmd_option_notations2.snap index 2c1d62b8..2287f9ef 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_option_notations2.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_option_notations2.snap @@ -7,5 +7,7 @@ spec cmd_option_notations --opt2 foo bar OUTPUT argc_opt2=( foo bar ) +argc__args=( ) +argc__fn=cmd_option_notations cmd_option_notations diff --git a/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_and_default_exec.snap b/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_and_default_exec.snap index fc93ba72..243a7ebc 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_and_default_exec.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_and_default_exec.snap @@ -7,5 +7,7 @@ spec cmd_positional_with_choices_and_default OUTPUT argc_arg=a +argc__args=( a ) +argc__fn=cmd_positional_with_choices_and_default cmd_positional_with_choices_and_default a diff --git a/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_exec.snap b/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_exec.snap index e5fd55a9..ba098183 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_exec.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_exec.snap @@ -7,5 +7,7 @@ spec cmd_positional_with_choices a OUTPUT argc_arg=a +argc__args=( a ) +argc__fn=cmd_positional_with_choices cmd_positional_with_choices a diff --git a/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_fn2.snap b/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_fn2.snap index 69cd63ca..7c739867 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_fn2.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_positional_with_choices_fn2.snap @@ -7,5 +7,7 @@ spec cmd_positional_with_choices_fn2 xyz OUTPUT argc_arg=xyz +argc__args=( xyz ) +argc__fn=cmd_positional_with_choices_fn2 cmd_positional_with_choices_fn2 xyz diff --git a/tests/snapshots/integration__spec_test__spec_cmd_positional_with_default_exec.snap b/tests/snapshots/integration__spec_test__spec_cmd_positional_with_default_exec.snap index 475dc73b..5bda7bc0 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_positional_with_default_exec.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_positional_with_default_exec.snap @@ -7,5 +7,7 @@ spec cmd_positional_with_default OUTPUT argc_arg=a +argc__args=( a ) +argc__fn=cmd_positional_with_default cmd_positional_with_default a diff --git a/tests/snapshots/integration__spec_test__spec_cmd_preferred_exec.snap b/tests/snapshots/integration__spec_test__spec_cmd_preferred_exec.snap index f12ab71f..0d79b47c 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_preferred_exec.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_preferred_exec.snap @@ -9,5 +9,7 @@ OUTPUT argc_flag1=1 argc_opt1=A argc_arg1=( AB 'C D' ) +argc__args=( AB 'C D' ) +argc__fn=cmd_preferred cmd_preferred AB 'C D' diff --git a/tests/snapshots/integration__spec_test__spec_cmd_single_dash.snap b/tests/snapshots/integration__spec_test__spec_cmd_single_dash.snap index 1ee89521..06932aa3 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_single_dash.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_single_dash.snap @@ -8,5 +8,7 @@ spec cmd_single_dash -flag1 -opt1 abc OUTPUT argc_flag1=1 argc_opt1=abc +argc__args=( ) +argc__fn=cmd_single_dash cmd_single_dash diff --git a/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals.snap b/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals.snap index 1ee78ec4..2e6f9f8f 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals.snap @@ -8,5 +8,7 @@ spec cmd_two_multiple_positionals abc def cjk OUTPUT argc_val1=( abc def ) argc_val2=( cjk ) +argc__args=( abc def cjk ) +argc__fn=cmd_two_multiple_positionals cmd_two_multiple_positionals abc def cjk diff --git a/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals2.snap b/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals2.snap index 1f80b9a1..0d136149 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals2.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals2.snap @@ -8,5 +8,7 @@ spec cmd_two_multiple_positionals -- abc def cjk OUTPUT argc_val1=( abc def ) argc_val2=( cjk ) +argc__args=( abc def cjk ) +argc__fn=cmd_two_multiple_positionals cmd_two_multiple_positionals abc def cjk diff --git a/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals3.snap b/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals3.snap index 3767959e..48fa136d 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals3.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_two_multiple_positionals3.snap @@ -8,5 +8,7 @@ spec cmd_two_multiple_positionals abc -- def cjk OUTPUT argc_val1=( abc ) argc_val2=( def cjk ) +argc__args=( abc def cjk ) +argc__fn=cmd_two_multiple_positionals cmd_two_multiple_positionals abc def cjk diff --git a/tests/snapshots/integration__spec_test__spec_cmd_with_hyphens.snap b/tests/snapshots/integration__spec_test__spec_cmd_with_hyphens.snap index 8e699ddf..20140878 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_with_hyphens.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_with_hyphens.snap @@ -9,5 +9,7 @@ OUTPUT argc_hyphen_flag=1 argc_hyphen_option=bar argc_hyphen_positional=foo +argc__args=( foo ) +argc__fn=cmd_with_hyphens cmd_with_hyphens foo diff --git a/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg.snap b/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg.snap index d434fb95..c5f7cca7 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg.snap @@ -6,5 +6,7 @@ RUN spec cmd_without_any_arg OUTPUT +argc__args=( ) +argc__fn=cmd_without_any_arg cmd_without_any_arg diff --git a/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg2.snap b/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg2.snap index b5d02d8f..944a4682 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg2.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg2.snap @@ -7,5 +7,6 @@ spec cmd_without_any_arg --opt2 foo bar OUTPUT argc__args=( --opt2 foo bar ) +argc__fn=cmd_without_any_arg cmd_without_any_arg --opt2 foo bar diff --git a/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg_exec.snap b/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg_exec.snap index 8aa136bc..62f5ad16 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg_exec.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg_exec.snap @@ -7,5 +7,6 @@ spec cmd_without_any_arg foo bar OUTPUT argc__args=( foo bar ) +argc__fn=cmd_without_any_arg cmd_without_any_arg foo bar diff --git a/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg_exec_eval.snap b/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg_exec_eval.snap index 8aa136bc..62f5ad16 100644 --- a/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg_exec_eval.snap +++ b/tests/snapshots/integration__spec_test__spec_cmd_without_any_arg_exec_eval.snap @@ -7,5 +7,6 @@ spec cmd_without_any_arg foo bar OUTPUT argc__args=( foo bar ) +argc__fn=cmd_without_any_arg cmd_without_any_arg foo bar diff --git a/tests/snapshots/integration__spec_test__spec_nested_command2.snap b/tests/snapshots/integration__spec_test__spec_nested_command2.snap index 0385a420..0821e050 100644 --- a/tests/snapshots/integration__spec_test__spec_nested_command2.snap +++ b/tests/snapshots/integration__spec_test__spec_nested_command2.snap @@ -6,5 +6,7 @@ RUN spec cmd_nested_command2 OUTPUT +argc__args=( ) +argc__fn=cmd_nested_command2::main cmd_nested_command2::main diff --git a/tests/snapshots/integration__spec_test__spec_nested_command_exec.snap b/tests/snapshots/integration__spec_test__spec_nested_command_exec.snap index 8cdfbdbb..d28af19a 100644 --- a/tests/snapshots/integration__spec_test__spec_nested_command_exec.snap +++ b/tests/snapshots/integration__spec_test__spec_nested_command_exec.snap @@ -7,5 +7,7 @@ spec cmd_nested_command foo --opt1 abc OUTPUT argc_opt1=abc +argc__args=( ) +argc__fn=cmd_nested_command::foo cmd_nested_command::foo diff --git a/tests/tests.rs b/tests/tests.rs index c2d16c73..e3fda005 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -13,7 +13,6 @@ mod export; mod fail_test; #[cfg(unix)] mod interrupt; -mod main_fn_test; mod param_fn_test; mod spec_test;