mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
Fix options after --argument-names to function (#6188)
This stops reading argument names after another option appears. It does not break any previous uses and in fact fixes uses like ```fish function foo --argument-names bar --description baz ``` * `function` command handles options after argument names (Fixes #6186) * Removed unneccesary test
This commit is contained in:
parent
3d1e9423c2
commit
15ed682bfa
@ -35,9 +35,9 @@ struct function_cmd_opts_t {
|
|||||||
wcstring_list_t wrap_targets;
|
wcstring_list_t wrap_targets;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This command is atypical in using the "+" (REQUIRE_ORDER) option for flag parsing.
|
// 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.
|
// 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 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, NULL, 'd'},
|
static const struct woption long_options[] = {{L"description", required_argument, NULL, 'd'},
|
||||||
{L"on-signal", required_argument, NULL, 's'},
|
{L"on-signal", required_argument, NULL, 's'},
|
||||||
{L"on-job-exit", required_argument, NULL, 'j'},
|
{L"on-job-exit", required_argument, NULL, 'j'},
|
||||||
@ -56,8 +56,20 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig
|
|||||||
const wchar_t *cmd = L"function";
|
const wchar_t *cmd = L"function";
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
|
bool handling_named_arguments = false;
|
||||||
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
|
||||||
|
if (opt != 'a' && opt != 1) handling_named_arguments = false;
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
case 1: {
|
||||||
|
if (handling_named_arguments) {
|
||||||
|
opts.named_arguments.push_back(w.woptarg);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
streams.err.append_format(_(L"%ls: Unexpected positional argument '%ls'"), cmd,
|
||||||
|
w.woptarg);
|
||||||
|
return STATUS_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
}
|
||||||
case 'd': {
|
case 'd': {
|
||||||
opts.description = w.woptarg;
|
opts.description = w.woptarg;
|
||||||
break;
|
break;
|
||||||
@ -122,6 +134,7 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'a': {
|
case 'a': {
|
||||||
|
handling_named_arguments = true;
|
||||||
opts.named_arguments.push_back(w.woptarg);
|
opts.named_arguments.push_back(w.woptarg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,3 @@
|
|||||||
function t --argument-names a b c
|
function t --argument-names a b c
|
||||||
echo t
|
echo t
|
||||||
end
|
end
|
||||||
|
|
||||||
function t2 --argument-names a b c --no-scope-shadowing
|
|
||||||
echo t2
|
|
||||||
end
|
|
||||||
#CHECKERR: {{.*/?}}function.fish (line {{\d+}}): function: Variable name '--no-scope-shadowing' is not valid. See `help identifiers`.
|
|
||||||
#CHECKERR: function t2 --argument-names a b c --no-scope-shadowing
|
|
||||||
#CHECKERR: ^
|
|
||||||
|
|
||||||
functions -q t2 && echo exists || echo does not exist
|
|
||||||
#CHECK: does not exist
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user