Skip to content

Commit 9933803

Browse files
committed
FIX: Command line consumes first argument when --script is used
resolves: Oldes/Rebol-issues#2469
1 parent 3af8beb commit 9933803

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/os/host-args.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,16 @@ const struct arg_chr arg_chars2[] = {
278278
}
279279
else {
280280
// script filename
281-
rargs->script = arg;
282-
// after having processed a command-line argument as scriptname,
283-
// all remaining arguments are passed as-is to the script (via system/options/args)
281+
if (rargs->script) {
282+
// we already have the script from --script option
283+
// so this should be first arg instead.
284+
--i; // revert the counter so this value is collected later
285+
}
286+
else {
287+
rargs->script = arg;
288+
// after having processed a command-line argument as scriptname,
289+
// all remaining arguments are passed as-is to the script (via system/options/args)
290+
}
284291
break;
285292
}
286293
}

src/tests/units/call-test.r3

+6
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ rebol-cmd: func[cmd][
5454
--assert out-buffer = {["-v" "--" "-x"]^/["-v" "--" "-x"]^/}
5555
--assert 0 = rebol-cmd {--args "a b" units/files/print-args.r3 -v}
5656
--assert out-buffer = {["a b" "-v"]^/["a b"]^/}
57+
; providing script using --script option
58+
;@@ https://github.com/Oldes/Rebol-issues/issues/2469
5759
--assert 0 = rebol-cmd {--script units/files/print-args.r3 --args "a b" -- -v}
5860
--assert out-buffer = {["a b" "-v"]^/["a b"]^/}
61+
--assert 0 = rebol-cmd {--script units/files/print-args.r3 1 2}
62+
--assert out-buffer = {["1" "2"]^/["1" "2"]^/}
63+
--assert 0 = rebol-cmd {--args 1 --script units/files/print-args.r3 2}
64+
--assert out-buffer = {["1" "2"]^/["1"]^/}
5965
--test-- "script args 3"
6066
;@@ https://github.com/Oldes/Rebol-issues/issues/2140
6167
cmd: "units/files/print-args.r3"

0 commit comments

Comments
 (0)