@@ -6,6 +6,7 @@ copyright: See LICENSE file in this distribution.
66// ======================================================================
77// The All-Singing, All-Dancing Argument Parser
88// ======================================================================
9+ //
910// Ole J. Tetlie wrote an option parser, and it was pretty good. But it
1011// didn't support all the option types required by d2c, and besides, we
1112// felt a need to overdo something.
@@ -29,20 +30,12 @@ copyright: See LICENSE file in this distribution.
2930// All the tokens on that command line are arguments. "-x" and "--y"
3031// are options, and "bar" is a parameter. "baz" is a positional argument.
3132
32- // todo -- There is no indication of default values in the generated synopsis,
33- // and the syntax for specifying "syntax" and docstring is bizarre at
34- // best. --cgay 2006.11.27
35-
3633// TODO(cgay): <choice-option>: --foo=a|b|c (#f as choice means option
3734// value is optional?)
3835
3936// TODO(cgay): Add a required: (or required?: ?) init keyword that
4037// makes non-positional args required else an error is generated.
4138
42- // TODO(cgay): This error sucks: "<unknown-option>" is not present as
43- // a key for {<string-table>: size 12}. How about "<unknown-option>
44- // is not a recognized command-line option." See next item.
45-
4639// TODO(cgay): With an option that has negative options (e.g.,
4740// --verbose and --quiet in the same option) just show the positive
4841// option in the synopsis but add a comment to the doc about the
@@ -747,14 +740,14 @@ define function process-tokens
747740 option.option-present? := #t ;
748741 end ;
749742 <short-option-token>, <long-option-token> =>
750- let option = find-option(parser, value)
743+ let option = find-option(subcmd | parser, value)
751744 | usage-error("Unrecognized option: %s%s" ,
752745 if (value.size = 1 ) "-" else "--" end ,
753746 value);
754747 if (instance? (option, <help-option>))
755748 // Handle --help early in case the remainder of the command line is
756749 // invalid or there are missing required arguments.
757- print-synopsis (parser, subcmd);
750+ print-help (parser, subcmd);
758751 abort-command(0 );
759752 end ;
760753 parse-option(option, parser);
0 commit comments