about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorAspen Smith <grfn@gws.fyi>2023-12-10T20·46-0500
committerclbot <clbot@tvl.fyi>2023-12-12T11·44+0000
commit02c66218138f6cf8eeb1437687c5cfddbe27fdd9 (patch)
treee8241b533de889b1efcf437f5eb7930e244d0053 /tools
parent8018313b6880d9fae71ba189a476502b68a26d25 (diff)
feat(tools/magrathea): Allow running commands in a shell r/7162
Add support for running a command inside a `mg shell`, specified as an
extra argument after the target to the shell command

Change-Id: Icbbd9cf4e1f099fcd7e6b13655b8447775a236d2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10247
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tools')
-rw-r--r--tools/magrathea/mg.scm24
1 files changed, 16 insertions, 8 deletions
diff --git a/tools/magrathea/mg.scm b/tools/magrathea/mg.scm
index 0caf7843ef62..0418a94f0fc8 100644
--- a/tools/magrathea/mg.scm
+++ b/tools/magrathea/mg.scm
@@ -22,6 +22,7 @@
 (define usage #<<USAGE
 usage: mg <command> [<target>]
        mg run [<target>] [-- <arguments>]
+       mg shell [<target>] [<command>]
 
 target:
   a target specification with meaning inside of the repository. can
@@ -276,19 +277,26 @@ if you meant to pass these arguments to nix, please separate them with
 
     (execute-build parsed)))
 
-(define (execute-shell t)
-  (let ((expr (nix-expr-for t))
-        (user-shell (or (get-environment-variable "SHELL") "bash")))
-    (fprintf (current-error-port) "[mg] entering shell for ~A~%" t)
+(define (execute-shell target #!optional command)
+  (if command
+      (fprintf (current-error-port) "[mg] executing ~A in shell for ~A~%"
+               command
+               target)
+      (fprintf (current-error-port) "[mg] entering shell for ~A~%" target))
+  (let ((expr (nix-expr-for target))
+        (command (or command
+                     (get-environment-variable "SHELL")
+                     "bash")))
     (process-execute "nix-shell"
-                     (list "-E" expr "--command" user-shell))))
+                     (list "-E" expr "--command" command))))
 
 (define (shell args)
   (match args
          [() (execute-shell (empty-target))]
-         [(arg) (execute-shell
-                 (guarantee-success (parse-target arg)))]
-         [other (print "not yet implemented")]))
+         [(target . args) (apply
+                           execute-shell
+                           (guarantee-success (parse-target target))
+                           args)]))
 
 (define (repl args)
   (process-execute "nix" (append (list "repl" "--show-trace" (repository-root)) args)))