mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 19:41:15 -03:00
argparse: Prevent duplicate error trailer
This was already printed by builtin_missing_argument/unknown_option. Since we need more control (because we add our own errors in other places), teach builtin_unknown_option to suppress the trailer, like missing_argument already could. And then use it. Fixes #8368.
This commit is contained in:
@@ -165,9 +165,11 @@ void builtin_print_help(parser_t &parser, const io_streams_t &streams, const wch
|
||||
|
||||
/// Perform error reporting for encounter with unknown option.
|
||||
void builtin_unknown_option(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_UNKNOWN, cmd, opt);
|
||||
builtin_print_error_trailer(parser, streams.err, cmd);
|
||||
if (print_hints) {
|
||||
builtin_print_error_trailer(parser, streams.err, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
/// Perform error reporting for encounter with missing argument.
|
||||
|
||||
@@ -94,7 +94,7 @@ void builtin_print_help(parser_t &parser, const io_streams_t &streams, const wch
|
||||
int builtin_count_args(const wchar_t *const *argv);
|
||||
|
||||
void builtin_unknown_option(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_missing_argument(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
|
||||
const wchar_t *opt, bool print_hints = true);
|
||||
|
||||
@@ -411,11 +411,11 @@ static int parse_cmd_opts(argparse_cmd_opts_t &opts, int *optind, //!OCLINT(hig
|
||||
break;
|
||||
}
|
||||
case ':': {
|
||||
builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]);
|
||||
builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1], /* print_hints */false);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
case '?': {
|
||||
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
|
||||
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1], /* print_hints */false);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
|
||||
Reference in New Issue
Block a user