more wgetopt_long() normalization

This commit is contained in:
Kurtis Rader 2017-06-29 21:49:57 -07:00
parent bf2a9f3835
commit dd191a9d4b
15 changed files with 83 additions and 25 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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'},

View file

@ -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

View file

@ -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;

View file

@ -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;
}