argparse: fix error message for missing option argument

case #1 in #6483
This commit is contained in:
Johannes Altmanninger 2020-01-08 14:37:04 +01:00
parent d8e93a5956
commit 0e707b88f0
2 changed files with 9 additions and 2 deletions

View File

@ -550,7 +550,7 @@ static int argparse_parse_flags(parser_t &parser, argparse_cmd_opts_t &opts,
wgetopter_t w;
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, &long_idx)) != -1) {
if (opt == ':') {
builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]);
streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]);
return STATUS_INVALID_ARGS;
} else if (opt == '?') {
// It's not a recognized flag. See if it's an implicit int flag.
@ -611,7 +611,7 @@ static int argparse_parse_args(argparse_cmd_opts_t &opts, const wcstring_list_t
// "+" means stop at nonopt, "-" means give nonoptions the option character code `1`, and don't
// reorder.
wcstring short_options = opts.stop_nonopt ? L"+:" : L"-";
wcstring short_options = opts.stop_nonopt ? L"+:" : L"-:";
std::vector<woption> long_options;
populate_option_strings(opts, &short_options, &long_options);

View File

@ -1,5 +1,8 @@
#RUN: %fish %s
##########
set -g LANG C
# Start by verifying a bunch of error conditions.
# No args is an error
@ -300,3 +303,7 @@ begin
# CHECK: argv
# CHECK: saved_status 57
end
# #6483 - error messages for missing arguments
argparse -n foo r/required= -- foo -r
# CHECKERR: foo: Expected argument for option -r