From e91eb85949e1271f2b7c6fa7fca5f8018820de75 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 3 May 2019 16:20:40 +0200 Subject: [PATCH] argparse: Fix `--` regression I was a tad overzealous there with not appending the remaining arguments. Weird that we didn't test it, though. Fixes #5857. --- src/builtin_argparse.cpp | 6 ++---- tests/argparse.err | 3 +++ tests/argparse.in | 6 ++++++ tests/argparse.out | 6 ++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/builtin_argparse.cpp b/src/builtin_argparse.cpp index 3b38c0e0b..d1a9ec576 100644 --- a/src/builtin_argparse.cpp +++ b/src/builtin_argparse.cpp @@ -634,10 +634,8 @@ static int argparse_parse_args(argparse_cmd_opts_t &opts, const wcstring_list_t retval = check_for_mutually_exclusive_flags(opts, streams); if (retval != STATUS_CMD_OK) return retval; - if (opts.stop_nonopt) { - for (int i = optind; argv[i]; i++) { - opts.argv.push_back(argv[i]); - } + for (int i = optind; argv[i]; i++) { + opts.argv.push_back(argv[i]); } return STATUS_CMD_OK; diff --git a/tests/argparse.err b/tests/argparse.err index 14120e58e..417c205a0 100644 --- a/tests/argparse.err +++ b/tests/argparse.err @@ -118,3 +118,6 @@ in function 'notargparse' #################### # Check for crash when last option is unknown + +#################### +# Checking arguments after -- diff --git a/tests/argparse.in b/tests/argparse.in index 3b9c0d811..01d9aba3b 100644 --- a/tests/argparse.in +++ b/tests/argparse.in @@ -189,3 +189,9 @@ echo $_flag_a logmsg Check for crash when last option is unknown argparse -i b/break -- "-b kubectl get pods -l name=foo" + +begin + logmsg Checking arguments after "--" + argparse a/alpha -- a --alpha -- b -a + printf '%s\n' $argv +end diff --git a/tests/argparse.out b/tests/argparse.out index 2a1f9b8c7..c70257994 100644 --- a/tests/argparse.out +++ b/tests/argparse.out @@ -140,3 +140,9 @@ alpha aaaa #################### # Check for crash when last option is unknown + +#################### +# Checking arguments after -- +a +b +-a