about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2022-11-25T17·47-0800
committerwpcarro <wpcarro@gmail.com>2022-11-26T15·20+0000
commit1ea97c288e18397ee937bdd560c6a3223d1a801f (patch)
tree1e4e8676f574b691aed8933743fe1434114138fd /tools
parent9b7b0785ab816cf542a520b4a10cf39565581a3c (diff)
fix(tools/mg): Support applying args to mg run (empty-target) r/5329
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/magrathea/mg.scm6
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/magrathea/mg.scm b/tools/magrathea/mg.scm
index 4a2a5ca6ded9..f3a615f81890 100644
--- a/tools/magrathea/mg.scm
+++ b/tools/magrathea/mg.scm
@@ -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