fix(tools/mg): Support applying args to mg run (empty-target)

With this, we can disambiguate the following `mg run` invocations:

```shell
$ mg run :foo    # run the virtual target, foo, with no args
$ mg run -- :foo # run the empty target and pass the arg, :foo, to it
```

Change-Id: Id6395b36a4d8ef3f325937e322e1c27b8630b556
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7408
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
William Carroll 2022-11-25 09:47:01 -08:00 committed by wpcarro
parent 9b7b0785ab
commit 1ea97c288e

View file

@ -21,6 +21,7 @@
(define usage #<<USAGE
usage: mg <command> [<target>]
mg run [<target>] [-- <arguments>]
target:
a target specification with meaning inside of the repository. can
@ -333,9 +334,10 @@ if you meant to pass these arguments to nix, please separate them with
(define (run args)
(match args
[() (execute-run (empty-target))]
[("--" . rest) (execute-run (empty-target) rest)]
[(target . ("--" . rest)) (execute-run (guarantee-success (parse-target target)) rest)]
;; TODO(sterni): flag for selecting binary name
[other (execute-run (guarantee-success (parse-target (car args)))
(cdr args))]))
[_ (mg-error "usage: mg run [<target>] [-- <arguments>] (hint: use \"--\" to separate the `mg run [<target>]` invocation from the arguments you're passing to the built executable)")]))
(define (path args)
(match args