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
|
(define usage #<<USAGE
|
||||||
usage: mg <command> [<target>]
|
usage: mg <command> [<target>]
|
||||||
mg run [<target>] [-- <arguments>]
|
mg run [<target>] [-- <arguments>]
|
||||||
|
mg shell [<target>] [<command>]
|
||||||
|
|
||||||
target:
|
target:
|
||||||
a target specification with meaning inside of the repository. can
|
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)))
|
(execute-build parsed)))
|
||||||
|
|
||||||
(define (execute-shell t)
|
(define (execute-shell target #!optional command)
|
||||||
(let ((expr (nix-expr-for t))
|
(if command
|
||||||
(user-shell (or (get-environment-variable "SHELL") "bash")))
|
(fprintf (current-error-port) "[mg] executing ~A in shell for ~A~%"
|
||||||
(fprintf (current-error-port) "[mg] entering shell for ~A~%" t)
|
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"
|
(process-execute "nix-shell"
|
||||||
(list "-E" expr "--command" user-shell))))
|
(list "-E" expr "--command" command))))
|
||||||
|
|
||||||
(define (shell args)
|
(define (shell args)
|
||||||
(match args
|
(match args
|
||||||
[() (execute-shell (empty-target))]
|
[() (execute-shell (empty-target))]
|
||||||
[(arg) (execute-shell
|
[(target . args) (apply
|
||||||
(guarantee-success (parse-target arg)))]
|
execute-shell
|
||||||
[other (print "not yet implemented")]))
|
(guarantee-success (parse-target target))
|
||||||
|
args)]))
|
||||||
|
|
||||||
(define (repl args)
|
(define (repl args)
|
||||||
(process-execute "nix" (append (list "repl" "--show-trace" (repository-root)) args)))
|
(process-execute "nix" (append (list "repl" "--show-trace" (repository-root)) args)))
|
||||||
|
|
Loading…
Reference in a new issue