From 0e707b88f0e82a92d3370b803a4a189662971655 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 8 Jan 2020 14:37:04 +0100 Subject: [PATCH] argparse: fix error message for missing option argument case #1 in #6483 --- src/builtin_argparse.cpp | 4 ++-- tests/checks/argparse.fish | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/builtin_argparse.cpp b/src/builtin_argparse.cpp index befb98722..1858242fa 100644 --- a/src/builtin_argparse.cpp +++ b/src/builtin_argparse.cpp @@ -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 long_options; populate_option_strings(opts, &short_options, &long_options); diff --git a/tests/checks/argparse.fish b/tests/checks/argparse.fish index 62352b7ae..ad628a51c 100644 --- a/tests/checks/argparse.fish +++ b/tests/checks/argparse.fish @@ -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