Remove the "flag" field from woption

The "flag" field enables an option to discover which flag it was invoked
with. However in practice none of our options use multiple flags so this
parameter was always nullptr. Remove it and fix up all the builtins to
stop passing this.

No functional change here.
This commit is contained in:
ridiculousfish
2022-11-28 16:35:49 -08:00
parent e4cde861a4
commit 39b7f112c7
29 changed files with 274 additions and 285 deletions

View File

@@ -105,7 +105,7 @@ void builtin_wperror(const wchar_t *program_name, io_streams_t &streams) {
}
static const wchar_t *const short_options = L"+:h";
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, {}};
static const struct woption long_options[] = {{L"help", no_argument, 'h'}, {}};
int parse_help_only_cmd_opts(struct help_only_cmd_opts_t &opts, int *optind, int argc,
const wchar_t **argv, parser_t &parser, io_streams_t &streams) {

View File

@@ -62,10 +62,10 @@ struct argparse_cmd_opts_t {
static const wchar_t *const short_options = L"+:hn:six:N:X:";
static const struct woption long_options[] = {
{L"stop-nonopt", no_argument, nullptr, 's'}, {L"ignore-unknown", no_argument, nullptr, 'i'},
{L"name", required_argument, nullptr, 'n'}, {L"exclusive", required_argument, nullptr, 'x'},
{L"help", no_argument, nullptr, 'h'}, {L"min-args", required_argument, nullptr, 'N'},
{L"max-args", required_argument, nullptr, 'X'}, {}};
{L"stop-nonopt", no_argument, 's'}, {L"ignore-unknown", no_argument, 'i'},
{L"name", required_argument, 'n'}, {L"exclusive", required_argument, 'x'},
{L"help", no_argument, 'h'}, {L"min-args", required_argument, 'N'},
{L"max-args", required_argument, 'X'}, {}};
// Check if any pair of mutually exclusive options was seen. Note that since every option must have
// a short name we only need to check those.
@@ -462,8 +462,7 @@ static void populate_option_strings(const argparse_cmd_opts_t &opts, wcstring *s
}
if (!opt_spec->long_flag.empty()) {
long_options->push_back(
{opt_spec->long_flag.c_str(), arg_type, nullptr, opt_spec->short_flag});
long_options->push_back({opt_spec->long_flag.c_str(), arg_type, opt_spec->short_flag});
}
}
long_options->push_back(woption{});

View File

@@ -62,11 +62,13 @@ class builtin_bind_t {
bool erase(const wchar_t *const *seq, bool all, const wchar_t *mode, bool use_terminfo,
bool user, io_streams_t &streams);
bool get_terminfo_sequence(const wcstring &seq, wcstring *out_seq, io_streams_t &streams) const;
bool insert(int optind, int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams);
bool insert(int optind, int argc, const wchar_t **argv, parser_t &parser,
io_streams_t &streams);
void list_modes(io_streams_t &streams);
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, parser_t &parser, io_streams_t &streams);
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset, parser_t &parser,
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, parser_t &parser,
io_streams_t &streams);
bool list_one(const wcstring &seq, const wcstring &bind_mode, bool user, bool preset,
parser_t &parser, io_streams_t &streams);
};
/// List a single key binding.
@@ -141,7 +143,8 @@ bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bo
}
/// List all current key bindings.
void builtin_bind_t::list(const wchar_t *bind_mode, bool user, parser_t &parser, io_streams_t &streams) {
void builtin_bind_t::list(const wchar_t *bind_mode, bool user, parser_t &parser,
io_streams_t &streams) {
const std::vector<input_mapping_name_t> lst = input_mappings_->get_names(user);
for (const input_mapping_name_t &binding : lst) {
@@ -255,7 +258,8 @@ bool builtin_bind_t::erase(const wchar_t *const *seq, bool all, const wchar_t *m
return res;
}
bool builtin_bind_t::insert(int optind, int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
bool builtin_bind_t::insert(int optind, int argc, const wchar_t **argv, parser_t &parser,
io_streams_t &streams) {
const wchar_t *cmd = argv[0];
int arg_count = argc - optind;
@@ -342,18 +346,18 @@ static int parse_cmd_opts(bind_cmd_opts_t &opts, int *optind, //!OCLINT(high nc
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
const wchar_t *cmd = argv[0];
static const wchar_t *const short_options = L":aehkKfM:Lm:s";
static const struct woption long_options[] = {{L"all", no_argument, nullptr, 'a'},
{L"erase", no_argument, nullptr, 'e'},
{L"function-names", no_argument, nullptr, 'f'},
{L"help", no_argument, nullptr, 'h'},
{L"key", no_argument, nullptr, 'k'},
{L"key-names", no_argument, nullptr, 'K'},
{L"list-modes", no_argument, nullptr, 'L'},
{L"mode", required_argument, nullptr, 'M'},
{L"preset", no_argument, nullptr, 'p'},
{L"sets-mode", required_argument, nullptr, 'm'},
{L"silent", no_argument, nullptr, 's'},
{L"user", no_argument, nullptr, 'u'},
static const struct woption long_options[] = {{L"all", no_argument, 'a'},
{L"erase", no_argument, 'e'},
{L"function-names", no_argument, 'f'},
{L"help", no_argument, 'h'},
{L"key", no_argument, 'k'},
{L"key-names", no_argument, 'K'},
{L"list-modes", no_argument, 'L'},
{L"mode", required_argument, 'M'},
{L"preset", no_argument, 'p'},
{L"sets-mode", required_argument, 'm'},
{L"silent", no_argument, 's'},
{L"user", no_argument, 'u'},
{}};
int opt;

View File

@@ -26,10 +26,10 @@ static int parse_cmd_opts(block_cmd_opts_t &opts, int *optind, //!OCLINT(high n
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {
const wchar_t *cmd = argv[0];
static const wchar_t *const short_options = L":eghl";
static const struct woption long_options[] = {{L"erase", no_argument, nullptr, 'e'},
{L"local", no_argument, nullptr, 'l'},
{L"global", no_argument, nullptr, 'g'},
{L"help", no_argument, nullptr, 'h'},
static const struct woption long_options[] = {{L"erase", no_argument, 'e'},
{L"local", no_argument, 'l'},
{L"global", no_argument, 'g'},
{L"help", no_argument, 'h'},
{}};
int opt;

View File

@@ -20,10 +20,8 @@ struct builtin_cmd_opts_t {
bool query = false;
};
static const wchar_t *const short_options = L":hnq";
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'},
{L"names", no_argument, nullptr, 'n'},
{L"query", no_argument, nullptr, 'q'},
{}};
static const struct woption long_options[] = {
{L"help", no_argument, 'h'}, {L"names", no_argument, 'n'}, {L"query", no_argument, 'q'}, {}};
static int parse_cmd_opts(builtin_cmd_opts_t &opts, int *optind, int argc, const wchar_t **argv,
parser_t &parser, io_streams_t &streams) {

View File

@@ -24,9 +24,8 @@ struct command_cmd_opts_t {
};
static const wchar_t *const short_options = L":ahqsv";
static const struct woption long_options[] = {
{L"help", no_argument, nullptr, 'h'}, {L"all", no_argument, nullptr, 'a'},
{L"quiet", no_argument, nullptr, 'q'}, {L"query", no_argument, nullptr, 'q'},
{L"search", no_argument, nullptr, 's'}, {}};
{L"help", no_argument, 'h'}, {L"all", no_argument, 'a'}, {L"quiet", no_argument, 'q'},
{L"query", no_argument, 'q'}, {L"search", no_argument, 's'}, {}};
static int parse_cmd_opts(command_cmd_opts_t &opts, int *optind, int argc, const wchar_t **argv,
parser_t &parser, io_streams_t &streams) {

View File

@@ -155,27 +155,27 @@ maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, const
const auto &ld = parser.libdata();
static const wchar_t *const short_options = L":abijpctforhI:CBELSsP";
static const struct woption long_options[] = {{L"append", no_argument, nullptr, 'a'},
{L"insert", no_argument, nullptr, 'i'},
{L"replace", no_argument, nullptr, 'r'},
{L"current-buffer", no_argument, nullptr, 'b'},
{L"current-job", no_argument, nullptr, 'j'},
{L"current-process", no_argument, nullptr, 'p'},
{L"current-selection", no_argument, nullptr, 's'},
{L"current-token", no_argument, nullptr, 't'},
{L"cut-at-cursor", no_argument, nullptr, 'c'},
{L"function", no_argument, nullptr, 'f'},
{L"tokenize", no_argument, nullptr, 'o'},
{L"help", no_argument, nullptr, 'h'},
{L"input", required_argument, nullptr, 'I'},
{L"cursor", no_argument, nullptr, 'C'},
{L"selection-start", no_argument, nullptr, 'B'},
{L"selection-end", no_argument, nullptr, 'E'},
{L"line", no_argument, nullptr, 'L'},
{L"search-mode", no_argument, nullptr, 'S'},
{L"paging-mode", no_argument, nullptr, 'P'},
{L"paging-full-mode", no_argument, nullptr, 'F'},
{L"is-valid", no_argument, nullptr, 1},
static const struct woption long_options[] = {{L"append", no_argument, 'a'},
{L"insert", no_argument, 'i'},
{L"replace", no_argument, 'r'},
{L"current-buffer", no_argument, 'b'},
{L"current-job", no_argument, 'j'},
{L"current-process", no_argument, 'p'},
{L"current-selection", no_argument, 's'},
{L"current-token", no_argument, 't'},
{L"cut-at-cursor", no_argument, 'c'},
{L"function", no_argument, 'f'},
{L"tokenize", no_argument, 'o'},
{L"help", no_argument, 'h'},
{L"input", required_argument, 'I'},
{L"cursor", no_argument, 'C'},
{L"selection-start", no_argument, 'B'},
{L"selection-end", no_argument, 'E'},
{L"line", no_argument, 'L'},
{L"search-mode", no_argument, 'S'},
{L"paging-mode", no_argument, 'P'},
{L"paging-full-mode", no_argument, 'F'},
{L"is-valid", no_argument, 1},
{}};
int opt;

View File

@@ -150,29 +150,28 @@ maybe_t<int> builtin_complete(parser_t &parser, io_streams_t &streams, const wch
bool unescape_output = true;
static const wchar_t *const short_options = L":a:c:p:s:l:o:d:fFrxeuAn:C::w:hk";
static const struct woption long_options[] = {
{L"exclusive", no_argument, nullptr, 'x'},
{L"no-files", no_argument, nullptr, 'f'},
{L"force-files", no_argument, nullptr, 'F'},
{L"require-parameter", no_argument, nullptr, 'r'},
{L"path", required_argument, nullptr, 'p'},
{L"command", required_argument, nullptr, 'c'},
{L"short-option", required_argument, nullptr, 's'},
{L"long-option", required_argument, nullptr, 'l'},
{L"old-option", required_argument, nullptr, 'o'},
{L"subcommand", required_argument, nullptr, 'S'},
{L"description", required_argument, nullptr, 'd'},
{L"arguments", required_argument, nullptr, 'a'},
{L"erase", no_argument, nullptr, 'e'},
{L"unauthoritative", no_argument, nullptr, 'u'},
{L"authoritative", no_argument, nullptr, 'A'},
{L"condition", required_argument, nullptr, 'n'},
{L"wraps", required_argument, nullptr, 'w'},
{L"do-complete", optional_argument, nullptr, 'C'},
{L"help", no_argument, nullptr, 'h'},
{L"keep-order", no_argument, nullptr, 'k'},
{L"escape", no_argument, nullptr, opt_escape},
{}};
static const struct woption long_options[] = {{L"exclusive", no_argument, 'x'},
{L"no-files", no_argument, 'f'},
{L"force-files", no_argument, 'F'},
{L"require-parameter", no_argument, 'r'},
{L"path", required_argument, 'p'},
{L"command", required_argument, 'c'},
{L"short-option", required_argument, 's'},
{L"long-option", required_argument, 'l'},
{L"old-option", required_argument, 'o'},
{L"subcommand", required_argument, 'S'},
{L"description", required_argument, 'd'},
{L"arguments", required_argument, 'a'},
{L"erase", no_argument, 'e'},
{L"unauthoritative", no_argument, 'u'},
{L"authoritative", no_argument, 'A'},
{L"condition", required_argument, 'n'},
{L"wraps", required_argument, 'w'},
{L"do-complete", optional_argument, 'C'},
{L"help", no_argument, 'h'},
{L"keep-order", no_argument, 'k'},
{L"escape", no_argument, opt_escape},
{}};
bool have_x = false;
@@ -356,8 +355,7 @@ maybe_t<int> builtin_complete(parser_t &parser, io_streams_t &streams, const wch
prefix.append(L": ");
if (maybe_t<wcstring> err_text = parse_util_detect_errors_in_argument_list(comp, prefix)) {
streams.err.append_format(L"%ls: %ls: contains a syntax error\n", cmd,
comp);
streams.err.append_format(L"%ls: %ls: contains a syntax error\n", cmd, comp);
streams.err.append(*err_text);
streams.err.push_back(L'\n');
return STATUS_CMD_ERROR;
@@ -423,8 +421,8 @@ maybe_t<int> builtin_complete(parser_t &parser, io_streams_t &streams, const wch
// Append any description.
if (!next.description.empty()) {
faux_cmdline_with_completion.reserve(
faux_cmdline_with_completion.size() + 2 + next.description.size());
faux_cmdline_with_completion.reserve(faux_cmdline_with_completion.size() + 2 +
next.description.size());
faux_cmdline_with_completion.push_back(L'\t');
faux_cmdline_with_completion.append(next.description);
}

View File

@@ -19,7 +19,7 @@ struct contains_cmd_opts_t {
};
static const wchar_t *const short_options = L"+:hi";
static const struct woption long_options[] = {
{L"help", no_argument, nullptr, 'h'}, {L"index", no_argument, nullptr, 'i'}, {}};
{L"help", no_argument, 'h'}, {L"index", no_argument, 'i'}, {}};
static int parse_cmd_opts(contains_cmd_opts_t &opts, int *optind, int argc, const wchar_t **argv,
parser_t &parser, io_streams_t &streams) {

View File

@@ -18,7 +18,7 @@ struct exit_cmd_opts_t {
bool print_help = false;
};
static const wchar_t *const short_options = L":h";
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, {}};
static const struct woption long_options[] = {{L"help", no_argument, 'h'}, {}};
static int parse_cmd_opts(exit_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {

View File

@@ -47,19 +47,18 @@ struct function_cmd_opts_t {
// This command is atypical in using the "-" (RETURN_IN_ORDER) option for flag parsing.
// This is needed due to the semantics of the -a/--argument-names flag.
static const wchar_t *const short_options = L"-:a:d:e:hj:p:s:v:w:SV:";
static const struct woption long_options[] = {
{L"description", required_argument, nullptr, 'd'},
{L"on-signal", required_argument, nullptr, 's'},
{L"on-job-exit", required_argument, nullptr, 'j'},
{L"on-process-exit", required_argument, nullptr, 'p'},
{L"on-variable", required_argument, nullptr, 'v'},
{L"on-event", required_argument, nullptr, 'e'},
{L"wraps", required_argument, nullptr, 'w'},
{L"help", no_argument, nullptr, 'h'},
{L"argument-names", required_argument, nullptr, 'a'},
{L"no-scope-shadowing", no_argument, nullptr, 'S'},
{L"inherit-variable", required_argument, nullptr, 'V'},
{}};
static const struct woption long_options[] = {{L"description", required_argument, 'd'},
{L"on-signal", required_argument, 's'},
{L"on-job-exit", required_argument, 'j'},
{L"on-process-exit", required_argument, 'p'},
{L"on-variable", required_argument, 'v'},
{L"on-event", required_argument, 'e'},
{L"wraps", required_argument, 'w'},
{L"help", no_argument, 'h'},
{L"argument-names", required_argument, 'a'},
{L"no-scope-shadowing", no_argument, 'S'},
{L"inherit-variable", required_argument, 'V'},
{}};
/// \return the internal_job_id for a pid, or 0 if none.
/// This looks through both active and finished jobs.
@@ -222,9 +221,8 @@ static int validate_function_name(int argc, const wchar_t *const *argv, wcstring
/// Define a function. Calls into `function.cpp` to perform the heavy lifting of defining a
/// function.
int builtin_function(parser_t &parser, io_streams_t &streams,
const wcstring_list_t &c_args, const parsed_source_ref_t &source,
const ast::block_statement_t &func_node) {
int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args,
const parsed_source_ref_t &source, const ast::block_statement_t &func_node) {
assert(source && "Missing source in builtin_function");
// The wgetopt function expects 'function' as the first argument. Make a new wcstring_list with
// that property. This is needed because this builtin has a different signature than the other

View File

@@ -40,18 +40,18 @@ struct functions_cmd_opts_t {
const wchar_t *description = nullptr;
};
static const wchar_t *const short_options = L":Ht:Dacd:ehnqv";
static const struct woption long_options[] = {{L"erase", no_argument, nullptr, 'e'},
{L"description", required_argument, nullptr, 'd'},
{L"names", no_argument, nullptr, 'n'},
{L"all", no_argument, nullptr, 'a'},
{L"help", no_argument, nullptr, 'h'},
{L"query", no_argument, nullptr, 'q'},
{L"copy", no_argument, nullptr, 'c'},
{L"details", no_argument, nullptr, 'D'},
{L"no-details", no_argument, nullptr, 1},
{L"verbose", no_argument, nullptr, 'v'},
{L"handlers", no_argument, nullptr, 'H'},
{L"handlers-type", required_argument, nullptr, 't'},
static const struct woption long_options[] = {{L"erase", no_argument, 'e'},
{L"description", required_argument, 'd'},
{L"names", no_argument, 'n'},
{L"all", no_argument, 'a'},
{L"help", no_argument, 'h'},
{L"query", no_argument, 'q'},
{L"copy", no_argument, 'c'},
{L"details", no_argument, 'D'},
{L"no-details", no_argument, 1},
{L"verbose", no_argument, 'v'},
{L"handlers", no_argument, 'H'},
{L"handlers-type", required_argument, 't'},
{}};
static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)

View File

@@ -57,20 +57,20 @@ struct history_cmd_opts_t {
/// supported at least until fish 3.0 and possibly longer to avoid breaking everyones
/// config.fish and other scripts.
static const wchar_t *const short_options = L":CRcehmn:pt::z";
static const struct woption long_options[] = {{L"prefix", no_argument, nullptr, 'p'},
{L"contains", no_argument, nullptr, 'c'},
{L"help", no_argument, nullptr, 'h'},
{L"show-time", optional_argument, nullptr, 't'},
{L"exact", no_argument, nullptr, 'e'},
{L"max", required_argument, nullptr, 'n'},
{L"null", no_argument, nullptr, 'z'},
{L"case-sensitive", no_argument, nullptr, 'C'},
{L"delete", no_argument, nullptr, 1},
{L"search", no_argument, nullptr, 2},
{L"save", no_argument, nullptr, 3},
{L"clear", no_argument, nullptr, 4},
{L"merge", no_argument, nullptr, 5},
{L"reverse", no_argument, nullptr, 'R'},
static const struct woption long_options[] = {{L"prefix", no_argument, 'p'},
{L"contains", no_argument, 'c'},
{L"help", no_argument, 'h'},
{L"show-time", optional_argument, 't'},
{L"exact", no_argument, 'e'},
{L"max", required_argument, 'n'},
{L"null", no_argument, 'z'},
{L"case-sensitive", no_argument, 'C'},
{L"delete", no_argument, 1},
{L"search", no_argument, 2},
{L"save", no_argument, 3},
{L"clear", no_argument, 4},
{L"merge", no_argument, 5},
{L"reverse", no_argument, 'R'},
{}};
/// Remember the history subcommand and disallow selecting more than one history subcommand.

View File

@@ -126,10 +126,10 @@ maybe_t<int> builtin_jobs(parser_t &parser, io_streams_t &streams, const wchar_t
static const wchar_t *const short_options = L":cghlpq";
static const struct woption long_options[] = {
{L"command", no_argument, nullptr, 'c'}, {L"group", no_argument, nullptr, 'g'},
{L"help", no_argument, nullptr, 'h'}, {L"last", no_argument, nullptr, 'l'},
{L"pid", no_argument, nullptr, 'p'}, {L"quiet", no_argument, nullptr, 'q'},
{L"query", no_argument, nullptr, 'q'}, {}};
{L"command", no_argument, 'c'}, {L"group", no_argument, 'g'},
{L"help", no_argument, 'h'}, {L"last", no_argument, 'l'},
{L"pid", no_argument, 'p'}, {L"quiet", no_argument, 'q'},
{L"query", no_argument, 'q'}, {}};
int opt;
wgetopter_t w;

View File

@@ -36,9 +36,9 @@ struct math_cmd_opts_t {
// This command is atypical in using the "+" (REQUIRE_ORDER) option for flag parsing.
// This is needed because of the minus, `-`, operator in math expressions.
static const wchar_t *const short_options = L"+:hs:b:";
static const struct woption long_options[] = {{L"scale", required_argument, nullptr, 's'},
{L"base", required_argument, nullptr, 'b'},
{L"help", no_argument, nullptr, 'h'},
static const struct woption long_options[] = {{L"scale", required_argument, 's'},
{L"base", required_argument, 'b'},
{L"help", no_argument, 'h'},
{}};
static int parse_cmd_opts(math_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
@@ -259,7 +259,8 @@ static int evaluate_expression(const wchar_t *cmd, const parser_t &parser, io_st
streams.err.append_format(L"'%ls'\n", expression.c_str());
if (error.len >= 2) {
wcstring tildes(error.len - 2, L'~');
streams.err.append_format(L"%*ls%ls%ls%ls\n", error.position - 1, L" ", L"^", tildes.c_str(), L"^");
streams.err.append_format(L"%*ls%ls%ls%ls\n", error.position - 1, L" ", L"^",
tildes.c_str(), L"^");
} else {
streams.err.append_format(L"%*ls%ls\n", error.position - 1, L" ", L"^");
}

View File

@@ -428,16 +428,16 @@ static wcstring construct_short_opts(options_t *opts) { //!OCLINT(high npath co
// Note that several long flags share the same short flag. That is okay. The caller is expected
// to indicate that a max of one of the long flags sharing a short flag is valid.
// Remember: adjust the completions in share/completions/ when options change
static const struct woption long_options[] = {{L"quiet", no_argument, nullptr, 'q'},
{L"null-in", no_argument, nullptr, 'z'},
{L"null-out", no_argument, nullptr, 'Z'},
{L"perm", required_argument, nullptr, 'p'},
{L"type", required_argument, nullptr, 't'},
{L"invert", no_argument, nullptr, 'v'},
{L"relative", no_argument, nullptr, 'R'},
{L"reverse", no_argument, nullptr, 'r'},
{L"unique", no_argument, nullptr, 'u'},
{L"key", required_argument, nullptr, 1},
static const struct woption long_options[] = {{L"quiet", no_argument, 'q'},
{L"null-in", no_argument, 'z'},
{L"null-out", no_argument, 'Z'},
{L"perm", required_argument, 'p'},
{L"type", required_argument, 't'},
{L"invert", no_argument, 'v'},
{L"relative", no_argument, 'R'},
{L"reverse", no_argument, 'r'},
{L"unique", no_argument, 'u'},
{L"key", required_argument, 1},
{}};
static const std::unordered_map<char, decltype(*handle_flag_q)> flag_to_function = {

View File

@@ -20,9 +20,9 @@
/// The pwd builtin. Respect -P to resolve symbolic links. Respect -L to not do that (the default).
static const wchar_t *const short_options = L"LPh";
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'},
{L"logical", no_argument, nullptr, 'L'},
{L"physical", no_argument, nullptr, 'P'},
static const struct woption long_options[] = {{L"help", no_argument, 'h'},
{L"logical", no_argument, 'L'},
{L"physical", no_argument, 'P'},
{}};
maybe_t<int> builtin_pwd(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
UNUSED(parser);

View File

@@ -52,26 +52,26 @@ struct read_cmd_opts_t {
} // namespace
static const wchar_t *const short_options = L":ac:d:fghiLln:p:sStuxzP:UR:L";
static const struct woption long_options[] = {{L"array", no_argument, nullptr, 'a'},
{L"command", required_argument, nullptr, 'c'},
{L"delimiter", required_argument, nullptr, 'd'},
{L"export", no_argument, nullptr, 'x'},
{L"function", no_argument, nullptr, 'f'},
{L"global", no_argument, nullptr, 'g'},
{L"help", no_argument, nullptr, 'h'},
{L"line", no_argument, nullptr, 'L'},
{L"list", no_argument, nullptr, 'a'},
{L"local", no_argument, nullptr, 'l'},
{L"nchars", required_argument, nullptr, 'n'},
{L"null", no_argument, nullptr, 'z'},
{L"prompt", required_argument, nullptr, 'p'},
{L"prompt-str", required_argument, nullptr, 'P'},
{L"right-prompt", required_argument, nullptr, 'R'},
{L"shell", no_argument, nullptr, 'S'},
{L"silent", no_argument, nullptr, 's'},
{L"tokenize", no_argument, nullptr, 't'},
{L"unexport", no_argument, nullptr, 'u'},
{L"universal", no_argument, nullptr, 'U'},
static const struct woption long_options[] = {{L"array", no_argument, 'a'},
{L"command", required_argument, 'c'},
{L"delimiter", required_argument, 'd'},
{L"export", no_argument, 'x'},
{L"function", no_argument, 'f'},
{L"global", no_argument, 'g'},
{L"help", no_argument, 'h'},
{L"line", no_argument, 'L'},
{L"list", no_argument, 'a'},
{L"local", no_argument, 'l'},
{L"nchars", required_argument, 'n'},
{L"null", no_argument, 'z'},
{L"prompt", required_argument, 'p'},
{L"prompt-str", required_argument, 'P'},
{L"right-prompt", required_argument, 'R'},
{L"shell", no_argument, 'S'},
{L"silent", no_argument, 's'},
{L"tokenize", no_argument, 't'},
{L"unexport", no_argument, 'u'},
{L"universal", no_argument, 'U'},
{}};
static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)

View File

@@ -25,7 +25,7 @@ struct realpath_cmd_opts_t {
static const wchar_t *const short_options = L"+:hs";
static const struct woption long_options[] = {
{L"no-symlinks", no_argument, nullptr, 's'}, {L"help", no_argument, nullptr, 'h'}, {}};
{L"no-symlinks", no_argument, 's'}, {L"help", no_argument, 'h'}, {}};
static int parse_cmd_opts(realpath_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {

View File

@@ -4,8 +4,8 @@
#include "return.h"
#include <cerrno>
#include <cstdlib>
#include <cmath>
#include <cstdlib>
#include <deque>
#include "../builtin.h"
@@ -21,7 +21,7 @@ struct return_cmd_opts_t {
bool print_help = false;
};
static const wchar_t *const short_options = L":h";
static const struct woption long_options[] = {{L"help", no_argument, nullptr, 'h'}, {}};
static const struct woption long_options[] = {{L"help", no_argument, 'h'}, {}};
static int parse_cmd_opts(return_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
int argc, const wchar_t **argv, parser_t &parser, io_streams_t &streams) {

View File

@@ -56,22 +56,22 @@ enum {
// (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 *const short_options = L"+:LSUaefghlnpqux";
static const struct woption long_options[] = {{L"export", no_argument, nullptr, 'x'},
{L"global", no_argument, nullptr, 'g'},
{L"function", no_argument, nullptr, 'f'},
{L"local", no_argument, nullptr, 'l'},
{L"erase", no_argument, nullptr, 'e'},
{L"names", no_argument, nullptr, 'n'},
{L"unexport", no_argument, nullptr, 'u'},
{L"universal", no_argument, nullptr, 'U'},
{L"long", no_argument, nullptr, 'L'},
{L"query", no_argument, nullptr, 'q'},
{L"show", no_argument, nullptr, 'S'},
{L"append", no_argument, nullptr, 'a'},
{L"prepend", no_argument, nullptr, 'p'},
{L"path", no_argument, nullptr, opt_path},
{L"unpath", no_argument, nullptr, opt_unpath},
{L"help", no_argument, nullptr, 'h'},
static const struct woption long_options[] = {{L"export", no_argument, 'x'},
{L"global", no_argument, 'g'},
{L"function", no_argument, 'f'},
{L"local", no_argument, 'l'},
{L"erase", no_argument, 'e'},
{L"names", no_argument, 'n'},
{L"unexport", no_argument, 'u'},
{L"universal", no_argument, 'U'},
{L"long", no_argument, 'L'},
{L"query", no_argument, 'q'},
{L"show", no_argument, 'S'},
{L"append", no_argument, 'a'},
{L"prepend", no_argument, 'p'},
{L"path", no_argument, opt_path},
{L"unpath", no_argument, opt_unpath},
{L"help", no_argument, 'h'},
{}};
// Hint for invalid path operation with a colon.
@@ -545,8 +545,8 @@ static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams
// For our purposes it's read-only.
if (env_var_t::flags_for(var_name) & env_var_t::flag_read_only) {
streams.out.append(_(L" (read-only)\n"));
}
else streams.out.push_back(L'\n');
} else
streams.out.push_back(L'\n');
for (size_t i = 0; i < vals.size(); i++) {
if (vals.size() > 100) {
@@ -626,8 +626,8 @@ static int builtin_set_erase(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
int ret = STATUS_CMD_OK;
env_mode_flags_t scopes = compute_scope(opts);
// `set -e` is allowed to be called with multiple scopes.
for (int bit = 0; 1<<bit <= ENV_USER; ++bit) {
int scope = scopes & 1<<bit;
for (int bit = 0; 1 << bit <= ENV_USER; ++bit) {
int scope = scopes & 1 << bit;
if (scope == 0 || (scope == ENV_USER && scopes != ENV_USER)) continue;
for (int i = 0; i < argc; i++) {
auto split = split_var_and_indexes(argv[i], scope, parser.vars(), streams);

View File

@@ -91,15 +91,15 @@ static void print_colors(io_streams_t &streams, wcstring_list_t args, bool bold,
}
static const wchar_t *const short_options = L":b:hvoidrcu";
static const struct woption long_options[] = {{L"background", required_argument, nullptr, 'b'},
{L"help", no_argument, nullptr, 'h'},
{L"bold", no_argument, nullptr, 'o'},
{L"underline", no_argument, nullptr, 'u'},
{L"italics", no_argument, nullptr, 'i'},
{L"dim", no_argument, nullptr, 'd'},
{L"reverse", no_argument, nullptr, 'r'},
{L"version", no_argument, nullptr, 'v'},
{L"print-colors", no_argument, nullptr, 'c'},
static const struct woption long_options[] = {{L"background", required_argument, 'b'},
{L"help", no_argument, 'h'},
{L"bold", no_argument, 'o'},
{L"underline", no_argument, 'u'},
{L"italics", no_argument, 'i'},
{L"dim", no_argument, 'd'},
{L"reverse", no_argument, 'r'},
{L"version", no_argument, 'v'},
{L"print-colors", no_argument, 'c'},
{}};
/// set_color builtin.

View File

@@ -120,23 +120,23 @@ struct status_cmd_opts_t {
/// scripts.
static const wchar_t *const short_options = L":L:cbilfnhj:t";
static const struct woption long_options[] = {
{L"help", no_argument, nullptr, 'h'},
{L"current-filename", no_argument, nullptr, 'f'},
{L"current-line-number", no_argument, nullptr, 'n'},
{L"filename", no_argument, nullptr, 'f'},
{L"fish-path", no_argument, nullptr, STATUS_FISH_PATH},
{L"is-block", no_argument, nullptr, 'b'},
{L"is-command-substitution", no_argument, nullptr, 'c'},
{L"is-full-job-control", no_argument, nullptr, STATUS_IS_FULL_JOB_CTRL},
{L"is-interactive", no_argument, nullptr, 'i'},
{L"is-interactive-job-control", no_argument, nullptr, STATUS_IS_INTERACTIVE_JOB_CTRL},
{L"is-login", no_argument, nullptr, 'l'},
{L"is-no-job-control", no_argument, nullptr, STATUS_IS_NO_JOB_CTRL},
{L"job-control", required_argument, nullptr, 'j'},
{L"level", required_argument, nullptr, 'L'},
{L"line", no_argument, nullptr, 'n'},
{L"line-number", no_argument, nullptr, 'n'},
{L"print-stack-trace", no_argument, nullptr, 't'},
{L"help", no_argument, 'h'},
{L"current-filename", no_argument, 'f'},
{L"current-line-number", no_argument, 'n'},
{L"filename", no_argument, 'f'},
{L"fish-path", no_argument, STATUS_FISH_PATH},
{L"is-block", no_argument, 'b'},
{L"is-command-substitution", no_argument, 'c'},
{L"is-full-job-control", no_argument, STATUS_IS_FULL_JOB_CTRL},
{L"is-interactive", no_argument, 'i'},
{L"is-interactive-job-control", no_argument, STATUS_IS_INTERACTIVE_JOB_CTRL},
{L"is-login", no_argument, 'l'},
{L"is-no-job-control", no_argument, STATUS_IS_NO_JOB_CTRL},
{L"job-control", required_argument, 'j'},
{L"level", required_argument, 'L'},
{L"line", no_argument, 'n'},
{L"line-number", no_argument, 'n'},
{L"print-stack-trace", no_argument, 't'},
{}};
/// Remember the status subcommand and disallow selecting more than one status subcommand.

View File

@@ -590,32 +590,32 @@ static wcstring construct_short_opts(options_t *opts) { //!OCLINT(high npath co
// Note that several long flags share the same short flag. That is okay. The caller is expected
// to indicate that a max of one of the long flags sharing a short flag is valid.
// Remember: adjust share/completions/string.fish when `string` options change
static const struct woption long_options[] = {{L"all", no_argument, nullptr, 'a'},
{L"chars", required_argument, nullptr, 'c'},
{L"count", required_argument, nullptr, 'n'},
{L"entire", no_argument, nullptr, 'e'},
{L"end", required_argument, nullptr, 'e'},
{L"filter", no_argument, nullptr, 'f'},
{L"groups-only", no_argument, nullptr, 'g'},
{L"ignore-case", no_argument, nullptr, 'i'},
{L"index", no_argument, nullptr, 'n'},
{L"invert", no_argument, nullptr, 'v'},
{L"visible", no_argument, nullptr, 'V'},
{L"left", no_argument, nullptr, 'l'},
{L"length", required_argument, nullptr, 'l'},
{L"max", required_argument, nullptr, 'm'},
{L"no-empty", no_argument, nullptr, 'n'},
{L"no-newline", no_argument, nullptr, 'N'},
{L"no-quoted", no_argument, nullptr, 'n'},
{L"quiet", no_argument, nullptr, 'q'},
{L"regex", no_argument, nullptr, 'r'},
{L"right", no_argument, nullptr, 'r'},
{L"start", required_argument, nullptr, 's'},
{L"style", required_argument, nullptr, 1},
{L"no-trim-newlines", no_argument, nullptr, 'N'},
{L"fields", required_argument, nullptr, 'f'},
{L"allow-empty", no_argument, nullptr, 'a'},
{L"width", required_argument, nullptr, 'w'},
static const struct woption long_options[] = {{L"all", no_argument, 'a'},
{L"chars", required_argument, 'c'},
{L"count", required_argument, 'n'},
{L"entire", no_argument, 'e'},
{L"end", required_argument, 'e'},
{L"filter", no_argument, 'f'},
{L"groups-only", no_argument, 'g'},
{L"ignore-case", no_argument, 'i'},
{L"index", no_argument, 'n'},
{L"invert", no_argument, 'v'},
{L"visible", no_argument, 'V'},
{L"left", no_argument, 'l'},
{L"length", required_argument, 'l'},
{L"max", required_argument, 'm'},
{L"no-empty", no_argument, 'n'},
{L"no-newline", no_argument, 'N'},
{L"no-quoted", no_argument, 'n'},
{L"quiet", no_argument, 'q'},
{L"regex", no_argument, 'r'},
{L"right", no_argument, 'r'},
{L"start", required_argument, 's'},
{L"style", required_argument, 1},
{L"no-trim-newlines", no_argument, 'N'},
{L"fields", required_argument, 'f'},
{L"allow-empty", no_argument, 'a'},
{L"width", required_argument, 'w'},
{}};
static flag_handler_t get_handler_for_flag(char c) {

View File

@@ -34,11 +34,11 @@ struct type_cmd_opts_t {
};
static const wchar_t *const short_options = L":hasftpPq";
static const struct woption long_options[] = {
{L"help", no_argument, nullptr, 'h'}, {L"all", no_argument, nullptr, 'a'},
{L"short", no_argument, nullptr, 's'}, {L"no-functions", no_argument, nullptr, 'f'},
{L"type", no_argument, nullptr, 't'}, {L"path", no_argument, nullptr, 'p'},
{L"force-path", no_argument, nullptr, 'P'}, {L"query", no_argument, nullptr, 'q'},
{L"quiet", no_argument, nullptr, 'q'}, {}};
{L"help", no_argument, 'h'}, {L"all", no_argument, 'a'},
{L"short", no_argument, 's'}, {L"no-functions", no_argument, 'f'},
{L"type", no_argument, 't'}, {L"path", no_argument, 'p'},
{L"force-path", no_argument, 'P'}, {L"query", no_argument, 'q'},
{L"quiet", no_argument, 'q'}, {}};
static int parse_cmd_opts(type_cmd_opts_t &opts, int *optind, int argc, const wchar_t **argv,
parser_t &parser, io_streams_t &streams) {

View File

@@ -196,32 +196,31 @@ maybe_t<int> builtin_ulimit(parser_t &parser, io_streams_t &streams, const wchar
int what = RLIMIT_FSIZE;
static const wchar_t *const short_options = L":HSabcdefilmnqrstuvwyKPTh";
static const struct woption long_options[] = {
{L"all", no_argument, nullptr, 'a'},
{L"hard", no_argument, nullptr, 'H'},
{L"soft", no_argument, nullptr, 'S'},
{L"socket-buffers", no_argument, nullptr, 'b'},
{L"core-size", no_argument, nullptr, 'c'},
{L"data-size", no_argument, nullptr, 'd'},
{L"nice", no_argument, nullptr, 'e'},
{L"file-size", no_argument, nullptr, 'f'},
{L"pending-signals", no_argument, nullptr, 'i'},
{L"lock-size", no_argument, nullptr, 'l'},
{L"resident-set-size", no_argument, nullptr, 'm'},
{L"file-descriptor-count", no_argument, nullptr, 'n'},
{L"queue-size", no_argument, nullptr, 'q'},
{L"realtime-priority", no_argument, nullptr, 'r'},
{L"stack-size", no_argument, nullptr, 's'},
{L"cpu-time", no_argument, nullptr, 't'},
{L"process-count", no_argument, nullptr, 'u'},
{L"virtual-memory-size", no_argument, nullptr, 'v'},
{L"swap-size", no_argument, nullptr, 'w'},
{L"realtime-maxtime", no_argument, nullptr, 'y'},
{L"kernel-queues", no_argument, nullptr, 'K'},
{L"ptys", no_argument, nullptr, 'P'},
{L"threads", no_argument, nullptr, 'T'},
{L"help", no_argument, nullptr, 'h'},
{}};
static const struct woption long_options[] = {{L"all", no_argument, 'a'},
{L"hard", no_argument, 'H'},
{L"soft", no_argument, 'S'},
{L"socket-buffers", no_argument, 'b'},
{L"core-size", no_argument, 'c'},
{L"data-size", no_argument, 'd'},
{L"nice", no_argument, 'e'},
{L"file-size", no_argument, 'f'},
{L"pending-signals", no_argument, 'i'},
{L"lock-size", no_argument, 'l'},
{L"resident-set-size", no_argument, 'm'},
{L"file-descriptor-count", no_argument, 'n'},
{L"queue-size", no_argument, 'q'},
{L"realtime-priority", no_argument, 'r'},
{L"stack-size", no_argument, 's'},
{L"cpu-time", no_argument, 't'},
{L"process-count", no_argument, 'u'},
{L"virtual-memory-size", no_argument, 'v'},
{L"swap-size", no_argument, 'w'},
{L"realtime-maxtime", no_argument, 'y'},
{L"kernel-queues", no_argument, 'K'},
{L"ptys", no_argument, 'P'},
{L"threads", no_argument, 'T'},
{L"help", no_argument, 'h'},
{}};
int opt;
wgetopter_t w;

View File

@@ -137,7 +137,7 @@ maybe_t<int> builtin_wait(parser_t &parser, io_streams_t &streams, const wchar_t
static const wchar_t *const short_options = L":nh";
static const struct woption long_options[] = {
{L"any", no_argument, nullptr, 'n'}, {L"help", no_argument, nullptr, 'h'}, {}};
{L"any", no_argument, 'n'}, {L"help", no_argument, 'h'}, {}};
int opt;
wgetopter_t w;

View File

@@ -292,12 +292,7 @@ void wgetopter_t::_update_long_opt(int argc, string_array_t argv, const struct w
nextchar += std::wcslen(nextchar);
if (longind != nullptr) *longind = option_index;
if (pfound->flag) {
*(pfound->flag) = pfound->val;
*retval = 0;
} else {
*retval = pfound->val;
}
*retval = pfound->val;
}
// Find a matching long opt.

View File

@@ -160,14 +160,12 @@ struct woption {
const wchar_t *name{nullptr};
/// Must be one of no_argument, required_argument or optional_argument.
woption_argument_t has_arg{};
/// If non-null, the flag whose value should be set if this switch is encountered.
int *flag{nullptr};
/// If \c flag is non-null, this is the value that flag will be set to. Otherwise, this is the
/// return-value of the function call.
wchar_t val{L'\0'};
constexpr woption(const wchar_t *name, woption_argument_t has_arg, int *flag, wchar_t val)
: name(name), has_arg(has_arg), flag(flag), val(val) {}
constexpr woption(const wchar_t *name, woption_argument_t has_arg, wchar_t val)
: name(name), has_arg(has_arg), val(val) {}
constexpr woption() = default;
};