Revert "argparse: let builtin_run() handle help."

This reverts commit bbc6bda843.
This commit is contained in:
Kurtis Rader 2017-07-19 11:13:59 -07:00
parent bbc6bda843
commit f78ab085b5
2 changed files with 12 additions and 1 deletions

View file

@ -493,7 +493,7 @@ bool builtin_exists(const wcstring &cmd) { return static_cast<bool>(builtin_look
/// Is the command a keyword or a builtin we need to special-case the handling of `-h` and `--help`. /// Is the command a keyword or a builtin we need to special-case the handling of `-h` and `--help`.
static const wcstring_list_t help_builtins({L"for", L"while", L"function", L"if", L"end", L"switch", static const wcstring_list_t help_builtins({L"for", L"while", L"function", L"if", L"end", L"switch",
L"case", L"printf", L"argparse"}); L"case", L"printf"});
static bool cmd_needs_help(const wchar_t *cmd) { return contains(help_builtins, cmd); } static bool cmd_needs_help(const wchar_t *cmd) { return contains(help_builtins, cmd); }
/// Execute a builtin command /// Execute a builtin command

View file

@ -57,6 +57,7 @@ class option_spec_t {
class argparse_cmd_opts_t { class argparse_cmd_opts_t {
public: public:
bool print_help = false;
bool stop_nonopt = false; bool stop_nonopt = false;
size_t min_args = 0; size_t min_args = 0;
size_t max_args = SIZE_MAX; size_t max_args = SIZE_MAX;
@ -79,6 +80,7 @@ static const wchar_t *short_options = L"+:hn:sx:N:X:";
static const struct woption long_options[] = {{L"stop-nonopt", no_argument, NULL, 's'}, static const struct woption long_options[] = {{L"stop-nonopt", no_argument, NULL, 's'},
{L"name", required_argument, NULL, 'n'}, {L"name", required_argument, NULL, 'n'},
{L"exclusive", required_argument, NULL, 'x'}, {L"exclusive", required_argument, NULL, 'x'},
{L"help", no_argument, NULL, 'h'},
{L"min-args", required_argument, NULL, 'N'}, {L"min-args", required_argument, NULL, 'N'},
{L"max-args", required_argument, NULL, 'X'}, {L"max-args", required_argument, NULL, 'X'},
{NULL, 0, NULL, 0}}; {NULL, 0, NULL, 0}};
@ -356,6 +358,10 @@ static int parse_cmd_opts(argparse_cmd_opts_t &opts, int *optind, //!OCLINT(hig
opts.raw_exclusive_flags.push_back(w.woptarg); opts.raw_exclusive_flags.push_back(w.woptarg);
break; break;
} }
case 'h': {
opts.print_help = true;
break;
}
case 'N': { case 'N': {
long x = fish_wcstol(w.woptarg); long x = fish_wcstol(w.woptarg);
if (errno || x < 0) { if (errno || x < 0) {
@ -657,6 +663,11 @@ int builtin_argparse(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {
builtin_print_help(parser, streams, cmd, streams.out);
return STATUS_CMD_OK;
}
wcstring_list_t args; wcstring_list_t args;
args.push_back(opts.name); args.push_back(opts.name);
while (optind < argc) args.push_back(argv[optind++]); while (optind < argc) args.push_back(argv[optind++]);