feat(tools/magrathea): add a path command
this command prints the absolute directory for a given target. it can be combined with shell aliases to add quick navigation commands. unfortunately due to the nature of computers implementing something like `mg cd` directly is not possible. Change-Id: Icc88eb97384812c620c49fe2de8fa331f4d7153b Reviewed-on: https://cl.tvl.fyi/c/depot/+/4395 Tested-by: BuildkiteCI Reviewed-by: wpcarro <wpcarro@gmail.com>
This commit is contained in:
parent
589480a925
commit
46a4e25550
1 changed files with 19 additions and 4 deletions
|
@ -36,6 +36,7 @@ target:
|
||||||
commands:
|
commands:
|
||||||
build - build a target
|
build - build a target
|
||||||
shell - enter a shell with the target's build dependencies
|
shell - enter a shell with the target's build dependencies
|
||||||
|
path - print source folder for the target
|
||||||
|
|
||||||
file all feedback on b.tvl.fyi
|
file all feedback on b.tvl.fyi
|
||||||
USAGE
|
USAGE
|
||||||
|
@ -201,12 +202,13 @@ USAGE
|
||||||
"\" " acc ")"))])))
|
"\" " acc ")"))])))
|
||||||
|
|
||||||
;; exit and complain at the user if something went wrong
|
;; exit and complain at the user if something went wrong
|
||||||
|
(define (mg-error message)
|
||||||
|
(format (current-error-port) "[mg] error: ~A~%" message)
|
||||||
|
(exit 1))
|
||||||
|
|
||||||
(define (guarantee-success value)
|
(define (guarantee-success value)
|
||||||
(match value
|
(match value
|
||||||
[('error . message)
|
[('error . message) (mg-error message)]
|
||||||
(begin
|
|
||||||
(format (current-error-port) "[mg] error: ~A~%" message)
|
|
||||||
(exit 1))]
|
|
||||||
[_ value]))
|
[_ value]))
|
||||||
|
|
||||||
(define (execute-build t)
|
(define (execute-build t)
|
||||||
|
@ -240,11 +242,24 @@ USAGE
|
||||||
(guarantee-success (parse-target arg)))]
|
(guarantee-success (parse-target arg)))]
|
||||||
[other (print "not yet implemented")]))
|
[other (print "not yet implemented")]))
|
||||||
|
|
||||||
|
(define (path args)
|
||||||
|
(match args
|
||||||
|
[(arg)
|
||||||
|
(print (conc (repository-root)
|
||||||
|
"/"
|
||||||
|
(string-intersperse
|
||||||
|
(target-components
|
||||||
|
(normalise-target
|
||||||
|
(guarantee-success (parse-target arg)))) "/")))]
|
||||||
|
[() (mg-error "path command needs a target")]
|
||||||
|
[other (mg-error (format "unknown arguments: ~a" other))]))
|
||||||
|
|
||||||
(define (main args)
|
(define (main args)
|
||||||
(match args
|
(match args
|
||||||
[() (print usage)]
|
[() (print usage)]
|
||||||
[("build" . _) (build (cdr args))]
|
[("build" . _) (build (cdr args))]
|
||||||
[("shell" . _) (shell (cdr args))]
|
[("shell" . _) (shell (cdr args))]
|
||||||
|
[("path" . _) (path (cdr args))]
|
||||||
[other (begin (print "unknown command: mg " args)
|
[other (begin (print "unknown command: mg " args)
|
||||||
(print usage))]))
|
(print usage))]))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue