From 02c66218138f6cf8eeb1437687c5cfddbe27fdd9 Mon Sep 17 00:00:00 2001 From: Aspen Smith Date: Sun, 10 Dec 2023 15:46:56 -0500 Subject: feat(tools/magrathea): Allow running commands in a shell 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 Tested-by: BuildkiteCI Reviewed-by: tazjin --- tools/magrathea/mg.scm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'tools/magrathea') 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 #< [] mg run [] [-- ] + mg shell [] [] 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))) -- cgit 1.4.1