cs3110/tools — pull request #118 by mwhittaker (2014-10-18 04:03:17+00:00)
Title: Added `--` bare double dash flag.

Issue #117 discusses the errors that can arise when `Core.command` too
greedily gobbles up potential flags from the command line. To fix the
issue, I introduced a `--` flag which acts similar to the bash idiomatic
[double dash][double-dash] flag. The flag signifies the end of the
command line flags. All subsequent command flags should not be parsed by
the command and instead be passed literally.

For example, recall the simple `echo.ml` file we were playing with.

```ocaml
(* echo.ml *)
open Printf

let () =
for i = 0 to Array.length Sys.argv - 1 do
printf "[%i] %s\n" i Sys.argv.(i)
done
```

Adding the double dash flag prevents `cs3110 run` from gobbling
arguments and instead passes them to `echo.ml`. Here are some examples
that demonstrate the problem is fixed.

```bash
$ cs3110 run echo.ml foo
[0] ./_build/echo.d.byte
[1] foo

$ cs3110 run echo.ml -foo
Runs a compiled executable.

cs3110 run TARGET [ARGS ...]

The run command runs a compiled executable.
Compile with the compile command, then run.

=== flags ===

[--] Signifies the end of command flags.
[-recompile] Compile target before running
(alias: -r)
[-verbose] Print debugging information.
(alias: -v)
[-help] print this help text and exit
(alias: -?)

unknown flag -foo

$ cs3110 run echo.ml -- -foo
[0] ./_build/echo.d.byte
[1] -foo

$ cs3110 run -v echo.ml bar -- -foo baz
[0] ./_build/echo.d.byte
[1] bar
[2] -foo
[3] baz
[run] Preparing to run target 'echo.ml' with args 'bar -foo baz'.
[run] Searching for executable './_build/echo.d.byte'.
```

This fixes #117.

[double-dash]: http://unix.stackexchange.com/questions/11376/what-does-double-dash-mean-also-known-as-bare-double-dash
[issue-117]: https://github.com/cs3110/tools/issues/117