mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-28 04:35:09 +00:00
unbreak missing argument error on long option
This commit is contained in:
parent
fdf398e435
commit
75fa3b6bae
5 changed files with 16 additions and 8 deletions
|
@ -178,9 +178,14 @@ void builtin_unknown_option(parser_t &parser, io_streams_t &streams, const wchar
|
||||||
|
|
||||||
/// Perform error reporting for encounter with missing argument.
|
/// Perform error reporting for encounter with missing argument.
|
||||||
void builtin_missing_argument(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
|
void builtin_missing_argument(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
|
||||||
const wchar_t *opt) {
|
const wchar_t *opt, bool print_hints) {
|
||||||
streams.err.append_format(BUILTIN_ERR_MISSING, cmd, opt + std::wcslen(opt) - 1);
|
if (opt[0] == L'-' && opt[1] != L'-') {
|
||||||
builtin_print_error_trailer(parser, streams.err, cmd);
|
opt += std::wcslen(opt) - 1;
|
||||||
|
}
|
||||||
|
streams.err.append_format(BUILTIN_ERR_MISSING, cmd, opt);
|
||||||
|
if (print_hints) {
|
||||||
|
builtin_print_error_trailer(parser, streams.err, cmd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Print the backtrace and call for help that we use at the end of error messages.
|
/// Print the backtrace and call for help that we use at the end of error messages.
|
||||||
|
|
|
@ -96,7 +96,7 @@ void builtin_unknown_option(parser_t &parser, io_streams_t &streams, const wchar
|
||||||
const wchar_t *opt);
|
const wchar_t *opt);
|
||||||
|
|
||||||
void builtin_missing_argument(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
|
void builtin_missing_argument(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
|
||||||
const wchar_t *opt);
|
const wchar_t *opt, bool print_hints = true);
|
||||||
|
|
||||||
void builtin_print_error_trailer(parser_t &parser, output_stream_t &b, const wchar_t *cmd);
|
void builtin_print_error_trailer(parser_t &parser, output_stream_t &b, const wchar_t *cmd);
|
||||||
|
|
||||||
|
|
|
@ -550,8 +550,8 @@ static int argparse_parse_flags(parser_t &parser, argparse_cmd_opts_t &opts,
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, &long_idx)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, &long_idx)) != -1) {
|
||||||
if (opt == ':') {
|
if (opt == ':') {
|
||||||
const wchar_t *arg = argv[w.woptind - 1];
|
builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1],
|
||||||
streams.err.append_format(BUILTIN_ERR_MISSING, cmd, arg + std::wcslen(arg) - 1);
|
false /* print_hints */);
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
} else if (opt == '?') {
|
} else if (opt == '?') {
|
||||||
// It's not a recognized flag. See if it's an implicit int flag.
|
// It's not a recognized flag. See if it's an implicit int flag.
|
||||||
|
|
|
@ -458,8 +458,8 @@ static int parse_opts(options_t *opts, int *optind, int n_req_args, int argc, wc
|
||||||
int retval = fn->second(argv, parser, streams, w, opts);
|
int retval = fn->second(argv, parser, streams, w, opts);
|
||||||
if (retval != STATUS_CMD_OK) return retval;
|
if (retval != STATUS_CMD_OK) return retval;
|
||||||
} else if (opt == ':') {
|
} else if (opt == ':') {
|
||||||
const wchar_t *arg = argv[w.woptind - 1];
|
streams.err.append(L"string "); // clone of string_error
|
||||||
string_error(streams, BUILTIN_ERR_MISSING, cmd, arg + std::wcslen(arg) - 1);
|
builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1], false /* print_hints */);
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
} else if (opt == '?') {
|
} else if (opt == '?') {
|
||||||
string_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
|
string_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
|
||||||
|
|
|
@ -307,3 +307,6 @@ end
|
||||||
# #6483 - error messages for missing arguments
|
# #6483 - error messages for missing arguments
|
||||||
argparse -n foo q r/required= -- foo -qr
|
argparse -n foo q r/required= -- foo -qr
|
||||||
# CHECKERR: foo: Expected argument for option r
|
# CHECKERR: foo: Expected argument for option r
|
||||||
|
|
||||||
|
argparse r/required= -- foo --required
|
||||||
|
# CHECKERR: argparse: Expected argument for option --required
|
||||||
|
|
Loading…
Reference in a new issue