mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
refactor builtin_argparse to remove lint
This commit is contained in:
parent
69ecda5082
commit
ed38db3370
1 changed files with 29 additions and 18 deletions
|
@ -227,23 +227,11 @@ static bool parse_flag_modifiers(argparse_cmd_opts_t &opts, option_spec_t *opt_s
|
|||
return true;
|
||||
}
|
||||
|
||||
// This parses an option spec string into a struct option_spec.
|
||||
static bool parse_option_spec(argparse_cmd_opts_t &opts, wcstring option_spec,
|
||||
/// Parse the text following the short flag letter.
|
||||
static bool parse_option_spec_sep(argparse_cmd_opts_t &opts, option_spec_t *opt_spec,
|
||||
wcstring &option_spec, const wchar_t **opt_spec_str,
|
||||
io_streams_t &streams) {
|
||||
if (option_spec.empty()) {
|
||||
streams.err.append_format(_(L"%ls: An option spec must have a short flag letter\n"),
|
||||
opts.name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
const wchar_t *s = option_spec.c_str();
|
||||
if (!iswalnum(*s) && *s != L'#') {
|
||||
streams.err.append_format(_(L"%ls: Short flag '%lc' invalid, must be alphanum or '#'\n"),
|
||||
opts.name.c_str(), *s);
|
||||
return false;
|
||||
}
|
||||
option_spec_t *opt_spec = new option_spec_t(*s++);
|
||||
|
||||
const wchar_t *s = *opt_spec_str;
|
||||
if (*(s - 1) == L'#') {
|
||||
if (*s != L'-') {
|
||||
streams.err.append_format(
|
||||
|
@ -279,6 +267,29 @@ static bool parse_option_spec(argparse_cmd_opts_t &opts, wcstring option_spec,
|
|||
return parse_flag_modifiers(opts, opt_spec, option_spec, s, streams);
|
||||
}
|
||||
|
||||
*opt_spec_str = s;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// This parses an option spec string into a struct option_spec.
|
||||
static bool parse_option_spec(argparse_cmd_opts_t &opts, wcstring option_spec,
|
||||
io_streams_t &streams) {
|
||||
if (option_spec.empty()) {
|
||||
streams.err.append_format(_(L"%ls: An option spec must have a short flag letter\n"),
|
||||
opts.name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
const wchar_t *s = option_spec.c_str();
|
||||
if (!iswalnum(*s) && *s != L'#') {
|
||||
streams.err.append_format(_(L"%ls: Short flag '%lc' invalid, must be alphanum or '#'\n"),
|
||||
opts.name.c_str(), *s);
|
||||
return false;
|
||||
}
|
||||
|
||||
option_spec_t *opt_spec = new option_spec_t(*s++);
|
||||
if (!parse_option_spec_sep(opts, opt_spec, option_spec, &s, streams)) return false;
|
||||
|
||||
// Collect the long flag name.
|
||||
const wchar_t *e = s;
|
||||
while (*e && (*e == L'-' || *e == L'_' || iswalnum(*e))) e++;
|
||||
|
|
Loading…
Reference in a new issue