diff --git a/src/builtin.cpp b/src/builtin.cpp index 1ee4a4bc7..0fb131e2b 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -106,7 +106,7 @@ void builtin_wperror(const wchar_t *s, io_streams_t &streams) { } } -static const wchar_t *short_options = L"h"; +static const wchar_t *short_options = L":h"; static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}}; @@ -121,6 +121,10 @@ int parse_help_only_cmd_opts(struct help_only_cmd_opts_t &opts, int *optind, int opts.print_help = true; break; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; diff --git a/src/builtin_bind.cpp b/src/builtin_bind.cpp index 2ff8a7d2f..86978e857 100644 --- a/src/builtin_bind.cpp +++ b/src/builtin_bind.cpp @@ -269,7 +269,7 @@ static void builtin_bind_list_modes(io_streams_t &streams) { static int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; - static const wchar_t *short_options = L"aehkKfM:Lm:"; + static const wchar_t *short_options = L":aehkKfM:Lm:"; static const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'}, {L"erase", no_argument, NULL, 'e'}, {L"function-names", no_argument, NULL, 'f'}, @@ -330,6 +330,10 @@ static int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high nc opts.list_modes = true; return STATUS_CMD_OK; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case L'?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; diff --git a/src/builtin_block.cpp b/src/builtin_block.cpp index 28e2b93fe..8e06c8b3e 100644 --- a/src/builtin_block.cpp +++ b/src/builtin_block.cpp @@ -23,7 +23,7 @@ struct block_cmd_opts_t { static int parse_cmd_opts(block_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method) int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; - static const wchar_t *short_options = L"eghl"; + static const wchar_t *short_options = L":eghl"; static const struct woption long_options[] = {{L"erase", no_argument, NULL, 'e'}, {L"local", no_argument, NULL, 'l'}, {L"global", no_argument, NULL, 'g'}, @@ -50,6 +50,10 @@ static int parse_cmd_opts(block_cmd_opts_t &opts, int *optind, //!OCLINT(high n opts.erase = true; break; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; diff --git a/src/builtin_builtin.cpp b/src/builtin_builtin.cpp index 6bc187aae..6d888fac5 100644 --- a/src/builtin_builtin.cpp +++ b/src/builtin_builtin.cpp @@ -18,7 +18,7 @@ struct builtin_cmd_opts_t { bool print_help = false; bool list_names = false; }; -static const wchar_t *short_options = L"hn"; +static const wchar_t *short_options = L":hn"; static const struct woption long_options[] = { {L"help", no_argument, NULL, 'h'}, {L"names", no_argument, NULL, 'n'}, {NULL, 0, NULL, 0}}; @@ -37,6 +37,10 @@ static int parse_cmd_opts(builtin_cmd_opts_t &opts, int *optind, int argc, wchar opts.list_names = true; break; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; diff --git a/src/builtin_command.cpp b/src/builtin_command.cpp index 3e53b55a4..b53cec1e8 100644 --- a/src/builtin_command.cpp +++ b/src/builtin_command.cpp @@ -51,6 +51,10 @@ static int parse_cmd_opts(command_cmd_opts_t &opts, int *optind, int argc, wchar opts.find_path = true; break; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; diff --git a/src/builtin_commandline.cpp b/src/builtin_commandline.cpp index 1bd5640b1..39b693ae2 100644 --- a/src/builtin_commandline.cpp +++ b/src/builtin_commandline.cpp @@ -210,7 +210,7 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) return STATUS_CMD_ERROR; } - static const wchar_t *short_options = L"abijpctwforhI:CLSsP"; + static const wchar_t *short_options = L":abijpctwforhI:CLSsP"; static const struct woption long_options[] = {{L"append", no_argument, NULL, 'a'}, {L"insert", no_argument, NULL, 'i'}, {L"replace", no_argument, NULL, 'r'}, @@ -303,6 +303,10 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) builtin_print_help(parser, streams, cmd, streams.out); return STATUS_CMD_OK; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case L'?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; diff --git a/src/builtin_contains.cpp b/src/builtin_contains.cpp index a4009593b..060abbfaa 100644 --- a/src/builtin_contains.cpp +++ b/src/builtin_contains.cpp @@ -16,7 +16,7 @@ struct contains_cmd_opts_t { bool print_help = false; bool print_index = false; }; -static const wchar_t *short_options = L"+hi"; +static const wchar_t *short_options = L"+:hi"; static const struct woption long_options[] = { {L"help", no_argument, NULL, 'h'}, {L"index", no_argument, NULL, 'i'}, {NULL, 0, NULL, 0}}; @@ -35,6 +35,10 @@ static int parse_cmd_opts(contains_cmd_opts_t &opts, int *optind, int argc, wcha opts.print_index = true; break; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; diff --git a/src/builtin_echo.cpp b/src/builtin_echo.cpp index 7b1d377a5..76ee71056 100644 --- a/src/builtin_echo.cpp +++ b/src/builtin_echo.cpp @@ -17,13 +17,14 @@ struct echo_cmd_opts_t { bool print_spaces = true; bool interpret_special_chars = false; }; -static const wchar_t *short_options = L"+Eens"; +static const wchar_t *short_options = L"+:Eens"; static const struct woption *long_options = NULL; static int parse_cmd_opts(echo_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { UNUSED(parser); UNUSED(streams); + wchar_t *cmd = argv[0]; int opt; wgetopter_t w; while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { @@ -44,6 +45,10 @@ static int parse_cmd_opts(echo_cmd_opts_t &opts, int *optind, int argc, wchar_t opts.interpret_special_chars = false; break; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { *optind = w.woptind - 1; return STATUS_CMD_OK; diff --git a/src/builtin_exit.cpp b/src/builtin_exit.cpp index a77aa40cf..3390b44e7 100644 --- a/src/builtin_exit.cpp +++ b/src/builtin_exit.cpp @@ -17,7 +17,7 @@ struct exit_cmd_opts_t { bool print_help = false; }; -static const wchar_t *short_options = L"h"; +static const wchar_t *short_options = L":h"; static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}}; @@ -34,6 +34,10 @@ static int parse_cmd_opts(exit_cmd_opts_t &opts, int *optind, //!OCLINT(high nc opts.print_help = true; break; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { // We would normally invoke builtin_unknown_option() and return an error. // But for this command we want to let it try and parse the value as a negative diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index 4cd1b0485..92dbd57f9 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -37,7 +37,7 @@ struct functions_cmd_opts_t { bool verbose = false; wchar_t *description = NULL; }; -static const wchar_t *short_options = L"Dacehnqv"; +static const wchar_t *short_options = L":Dacehnqv"; static const struct woption long_options[] = { {L"erase", no_argument, NULL, 'e'}, {L"description", required_argument, NULL, 'd'}, {L"names", no_argument, NULL, 'n'}, {L"all", no_argument, NULL, 'a'}, @@ -88,6 +88,10 @@ static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(hi opts.copy = true; break; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; diff --git a/src/builtin_jobs.cpp b/src/builtin_jobs.cpp index eb5d71c0b..2f97ac7ec 100644 --- a/src/builtin_jobs.cpp +++ b/src/builtin_jobs.cpp @@ -115,7 +115,7 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int mode = JOBS_DEFAULT; int print_last = 0; - static const wchar_t *short_options = L"cghlp"; + static const wchar_t *short_options = L":cghlp"; static const struct woption long_options[] = { {L"pid", no_argument, NULL, 'p'}, {L"command", no_argument, NULL, 'c'}, {L"group", no_argument, NULL, 'g'}, {L"last", no_argument, NULL, 'l'}, @@ -145,6 +145,10 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) { builtin_print_help(parser, streams, cmd, streams.out); return STATUS_CMD_OK; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index b204f746d..5e5c51655 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -45,7 +45,7 @@ struct read_cmd_opts_t { int nchars = 0; }; -static const wchar_t *short_options = L"ac:ghilm:n:p:suxzP:UR:"; +static const wchar_t *short_options = L":ac:ghilm:n:p:suxzP:UR:"; static const struct woption long_options[] = {{L"export", no_argument, NULL, 'x'}, {L"global", no_argument, NULL, 'g'}, {L"local", no_argument, NULL, 'l'}, diff --git a/src/builtin_return.cpp b/src/builtin_return.cpp index d0ed090a1..2eabaf38d 100644 --- a/src/builtin_return.cpp +++ b/src/builtin_return.cpp @@ -17,7 +17,7 @@ struct return_cmd_opts_t { bool print_help = false; }; -static const wchar_t *short_options = L"h"; +static const wchar_t *short_options = L":h"; static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}}; @@ -34,6 +34,10 @@ static int parse_cmd_opts(return_cmd_opts_t &opts, int *optind, //!OCLINT(high opts.print_help = true; break; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { // We would normally invoke builtin_unknown_option() and return an error. // But for this command we want to let it try and parse the value as a negative diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index cc206dacb..c24483743 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -335,7 +335,7 @@ int builtin_set(parser_t &parser, io_streams_t &streams, wchar_t **argv) { // Variables used for parsing the argument list. This command is atypical in using the "+" // (REQUIRE_ORDER) option for flag parsing. This is not typical of most fish commands. It means // we stop scanning for flags when the first non-flag argument is seen. - static const wchar_t *short_options = L"+LUeghlnqux"; + static const wchar_t *short_options = L"+:LUeghlnqux"; static const struct woption long_options[] = {{L"export", no_argument, NULL, 'x'}, {L"global", no_argument, NULL, 'g'}, {L"local", no_argument, NULL, 'l'}, @@ -396,6 +396,10 @@ int builtin_set(parser_t &parser, io_streams_t &streams, wchar_t **argv) { builtin_print_help(parser, streams, cmd, streams.out); return STATUS_CMD_OK; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; diff --git a/src/builtin_set_color.cpp b/src/builtin_set_color.cpp index e8b6606d7..4505509f6 100644 --- a/src/builtin_set_color.cpp +++ b/src/builtin_set_color.cpp @@ -49,24 +49,25 @@ static int set_color_builtin_outputter(char c) { return 0; } +static const wchar_t *short_options = L":b:hvoidrcu"; +static const struct woption long_options[] = {{L"background", required_argument, NULL, 'b'}, + {L"help", no_argument, NULL, 'h'}, + {L"bold", no_argument, NULL, 'o'}, + {L"underline", no_argument, NULL, 'u'}, + {L"italics", no_argument, NULL, 'i'}, + {L"dim", no_argument, NULL, 'd'}, + {L"reverse", no_argument, NULL, 'r'}, + {L"version", no_argument, NULL, 'v'}, + {L"print-colors", no_argument, NULL, 'c'}, + {NULL, 0, NULL, 0}}; + /// set_color builtin. int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) { // By the time this is called we should have initialized the curses subsystem. assert(curses_initialized); // Variables used for parsing the argument list. - static const wchar_t *short_options = L"b:hvoidrcu"; - static const struct woption long_options[] = {{L"background", required_argument, NULL, 'b'}, - {L"help", no_argument, NULL, 'h'}, - {L"bold", no_argument, NULL, 'o'}, - {L"underline", no_argument, NULL, 'u'}, - {L"italics", no_argument, NULL, 'i'}, - {L"dim", no_argument, NULL, 'd'}, - {L"reverse", no_argument, NULL, 'r'}, - {L"version", no_argument, NULL, 'v'}, - {L"print-colors", no_argument, NULL, 'c'}, - {NULL, 0, NULL, 0}}; - + wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); // Some code passes variables to set_color that don't exist, like $fish_user_whatever. As a @@ -115,6 +116,10 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) { print_colors(streams); return STATUS_CMD_OK; } + case ':': { + streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]); + return STATUS_INVALID_ARGS; + } case '?': { return STATUS_INVALID_ARGS; }