REBOL3 tracker
  0.9.12 beta
Ticket #0002227 User: anonymous

Project:

Previous Next
rss
TypeBug Statussubmitted Date26-Jul-2015 06:15
Versionr3 master CategoryPlatform Submitted byabolka
PlatformAll Severityminor Priorityhigh

Summary Interpreter too eagerly consumes command-line arguments
Description Currently, the interpreter tries to parse _all_ command-line arguments as arguments to the interpreter. See the example code for a few example cases.

Example cases (1), (2), and (3), in combination, are arguably bugs. The bug being, that there must be a way to pass arguments of every shape (OS limitations notwithstanding) to a script. Otherwise, making Rebol scripts fit nicely into other, non-Rebol command-line interfaces is close to impossible.

I suggest the following two improvements:

1. "--" should stop options parsing for the interpreter. If no scriptname was passed as argument before the "--", the first argument after the "--" is consumed as the scriptname. All remaining arguments after the scriptname are passed as-is to the script (via system/options/args).

2. More generally, after having processed a command-line argument as scriptname, all remaining arguments are passed as-is to the script (via system/options/args).

Discussion:

Suggestion (1) causes no important or tangible breakage. "--" is currently parsed as an unknown argument, always causing the usage to be shown. That will be gone, and no one will miss it.

Change (2) is arguably what is generally the expected behaviour for an interpreter. (It's how Factor, Julia, Lua, Perl, PHP, Python, Ruby behave, to just name a few I had at hand to double-check. This change would cause one _minor_ breakage I can think of: whereas you can currently write `rebol3 script.r --args "some -args here"`, you'd have to then write `rebol3 --args "some -args here" script.r`, if you absolutely want/have to use --args. Of course, _with_ the fix you could also just write the much simpler "rebol3 script.r some -args here", in this case. I think that playing more nicely with the wider world is well worth this tiny breakage.

--

Priority "high" as this is one thing that hit me each and every time I try to write nice CLI scripts. It's not just me: others (http://git.io/vYzTc) resort to ugly workarounds (like using Windows-style "/foo" switches), too. Also, it leaves a bad first impression for people coming from other languages, as this is a thing that's generally expected to work and there's never been a good reason for Rebol to break with that particular expectation.
Example code
;; Example 1 (bug): known argument to the interpreter, consumed
$ rebol3 script.r -v
Rebol 3 2.102.0.4.40
$

;; Example 2 (bug): unknown argument, prints usage
$ rebol3 script.r -x
REBOL 3.0 A0 25-Jul-2015/21:13:42

Command line usage:

	REBOL |options| |script| |arguments|
..
>>

;; Example 3 (bug): consumes args even after "--" (-- is a common Unix
;; convention, to end option parameters;
;; cf http://unix.stackexchange.com/questions/11376/)
$ rebol3 script.r -- -v
Rebol 3 2.102.0.4.40
$

;; Example 4 (for reference): arguments not starting with "-"  or "--" _are_
;; passed to the script
$ rebol3 probe-args.r 10 foo
["10" "foo"]
$

;; Example 5 (for reference): --args can be used to pass arguments, even after
;; a script (a string which is split into a block of args by Rebol; but that's
;; another issue)
$ rebol3 probe-args.r --args "-v -x"
["-v" "-x"]
$

;; Example 6: suggested behaviour with improvement (1) "stop options parsing for the interpreter on --"
$ rebol3 -- probe-args.r -v -x
["-v" "-x"]
$

;; Example 7: suggested behaviour with improvement (2) "stop options parsing after having found a scriptname"
$ rebol3 probe-args.r -v -x
["-v" "-x"]
$

;; Example 8: suggested behaviour with (2) and (1), when a scriptname is found, all further args are passed to the script, even a --
$ rebol3 probe-args.r -- -v -x
["--" "-v" "-x"]
$ rebol3 probe-args.r -v -- -x
["-v" "--" "-x"]
$

Assigned ton/a Fixed in- Last Update14-Aug-2015 22:46


Comments

Date User Field Action Change
14-Aug-2015 22:46 abolka Description Modified -
14-Aug-2015 22:44 abolka Code Modified -
14-Aug-2015 22:43 abolka Description Modified -
14-Aug-2015 22:43 abolka Code Modified -
14-Aug-2015 21:50 abolka Description Modified -
26-Jul-2015 06:25 abolka Category Modified Unspecified => Platform
26-Jul-2015 06:18 abolka Code Modified -
26-Jul-2015 06:17 abolka Code Modified -
26-Jul-2015 06:17 abolka Description Modified -
26-Jul-2015 06:17 abolka Code Modified -
26-Jul-2015 06:15 abolka Ticket Added -