Skip to content

Commit

Permalink
preserve -- in ARGS when it follows a non-option argument (#45335)
Browse files Browse the repository at this point in the history
Co-authored-by: Kirill Simonov <[email protected]>
  • Loading branch information
KristofferC and xitology committed May 17, 2022
1 parent 7bff5cd commit 1476e58
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
4 changes: 0 additions & 4 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ function incomplete_tag(ex::Expr)
end

function exec_options(opts)
if !isempty(ARGS)
idxs = findall(x -> x == "--", ARGS)
length(idxs) > 0 && deleteat!(ARGS, idxs[1])
end
quiet = (opts.quiet != 0)
startup = (opts.startupfile != 2)
history_file = (opts.historyfile != 0)
Expand Down
9 changes: 0 additions & 9 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,8 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
const char **cmds = NULL;
int codecov = JL_LOG_NONE;
int malloclog = JL_LOG_NONE;
// getopt handles argument parsing up to -- delineator
int argc = *argcp;
char **argv = *argvp;
if (argc > 0) {
for (int i = 0; i < argc; i++) {
if (!strcmp(argv[i], "--")) {
argc = i;
break;
}
}
}
char *endptr;
opterr = 0; // suppress getopt warning messages
while (1) {
Expand Down
14 changes: 11 additions & 3 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,27 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
withenv("JULIA_DEPOT_PATH" => dir) do
output = "[\"foo\", \"-bar\", \"--baz\"]"
@test readchomp(`$exename $testfile foo -bar --baz`) == output
@test readchomp(`$exename $testfile -- foo -bar --baz`) == output
@test readchomp(`$exename -- $testfile foo -bar --baz`) == output
@test readchomp(`$exename -L $testfile -e 'exit(0)' -- foo -bar --baz`) ==
output
@test readchomp(`$exename --startup-file=yes -e 'exit(0)' -- foo -bar --baz`) ==
output

output = "[\"foo\", \"--\", \"-bar\", \"--baz\"]"
@test readchomp(`$exename $testfile foo -- -bar --baz`) == output
@test readchomp(`$exename -- $testfile foo -- -bar --baz`) == output
@test readchomp(`$exename -L $testfile -e 'exit(0)' foo -- -bar --baz`) ==
output
@test readchomp(`$exename -L $testfile -e 'exit(0)' -- foo -- -bar --baz`) ==
output
@test readchomp(`$exename --startup-file=yes -e 'exit(0)' foo -- -bar --baz`) ==
output

output = "String[]\nString[]"
@test readchomp(`$exename -L $testfile $testfile`) == output
@test readchomp(`$exename --startup-file=yes $testfile`) == output

@test !success(`$exename --foo $testfile`)
@test readchomp(`$exename -L $testfile -e 'exit(0)' -- foo -bar -- baz`) ==
"[\"foo\", \"-bar\", \"--\", \"baz\"]"
end
end

Expand Down

0 comments on commit 1476e58

Please sign in to comment.