@@ -114,6 +114,8 @@ define abstract class <command> (<object>)
114
114
slot command-subcommands :: <sequence> = #[],
115
115
init-keyword: subcommands:;
116
116
slot selected-subcommand :: false-or (<subcommand>) = #f ;
117
+ // All arguments following the first "--" positional argument, if any.
118
+ slot unconsumed-arguments :: <sequence> = #();
117
119
end class ;
118
120
119
121
// The --help option is added by default but we provide a way to turn it off here.
@@ -598,8 +600,10 @@ end;
598
600
// ======================================================================
599
601
600
602
// Break up our arguments around '--' in the traditional fashion.
601
- define function split-args (argv)
603
+ define function split-args (argv)
602
604
=> (clean-args :: <sequence> , extra-args :: <sequence> )
605
+ // TODO(cgay): A <parameter-option> "--foo --" should be valid.
606
+ // https://github.com/dylan-lang/command-line-parser/issues/47
603
607
let splitter = find-key (argv, curry (\=, "--" ));
604
608
if (splitter)
605
609
let clean-args = copy-sequence (argv, end: splitter);
@@ -710,9 +714,9 @@ define open generic parse-command-line
710
714
(parser :: <command-line-parser>, argv :: <sequence> )
711
715
=> ();
712
716
713
- // Parse the command line, side-effecting the parser, its options, and its
714
- // subcommands with the parsed values. `args` is a sequence of command line
715
- // arguments (strings). It must not include the command name.
717
+ // Parse the command line, side-effecting the parser, its options, and its subcommands
718
+ // with the parsed values. `args` is a sequence of command line arguments (strings) that
719
+ // does not include the command name.
716
720
define method parse-command-line
717
721
(parser :: <command-line-parser>, args :: <sequence> )
718
722
=> ()
@@ -721,24 +725,9 @@ define method parse-command-line
721
725
let chopped-args = chop-args(clean-args);
722
726
tokenize-args(parser, chopped-args);
723
727
process-tokens(program-name(), parser, #f );
724
-
725
728
if (~empty? (extra-args))
726
- // Append any more positional options from after the '--'. If there's a
727
- // subcommand the extra args go with that.
728
- // (This feels hackish. Can we handle this directly in process-tokens?)
729
729
let command = parser.selected-subcommand | parser;
730
- let option = last (command.command-options);
731
- if (~(instance? (option, <positional-option>)
732
- & option.option-repeated?))
733
- let opts = command.positional-options;
734
- usage-error("Only %d positional argument%s allowed." ,
735
- opts.size ,
736
- if (opts.size = 1 ) "" else "s" end );
737
- end ;
738
- for (arg in extra-args)
739
- option.option-value := add! (option.option-value,
740
- parse-option-value(arg, option.option-type));
741
- end for ;
730
+ command.unconsumed-arguments := extra-args;
742
731
end ;
743
732
end method ;
744
733
@@ -838,7 +827,7 @@ end function;
838
827
839
828
Parameterless options:
840
829
-b, --bar, --no-bar
841
- Present or absent. May have opposites; latter values override
830
+ Present or absent. May have opposites; later values override
842
831
previous values.
843
832
844
833
Parameter options:
0 commit comments