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 <grfn@gws.fyi> Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
8018313b68
commit
02c6621813
1 changed files with 16 additions and 8 deletions
|
@ -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)))
|
||||
|
|
Loading…
Reference in a new issue