From 46a4e25550456790999c3afe4a578dedb8fe5024 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 18 Dec 2021 01:42:05 +0300 Subject: 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 --- tools/magrathea/mg.scm | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/magrathea/mg.scm b/tools/magrathea/mg.scm index 2b822b6631dd..38447e930324 100644 --- a/tools/magrathea/mg.scm +++ b/tools/magrathea/mg.scm @@ -36,6 +36,7 @@ target: commands: build - build a target shell - enter a shell with the target's build dependencies + path - print source folder for the target file all feedback on b.tvl.fyi USAGE @@ -201,12 +202,13 @@ USAGE "\" " acc ")"))]))) ;; 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) (match value - [('error . message) - (begin - (format (current-error-port) "[mg] error: ~A~%" message) - (exit 1))] + [('error . message) (mg-error message)] [_ value])) (define (execute-build t) @@ -240,11 +242,24 @@ USAGE (guarantee-success (parse-target arg)))] [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) (match args [() (print usage)] [("build" . _) (build (cdr args))] [("shell" . _) (shell (cdr args))] + [("path" . _) (path (cdr args))] [other (begin (print "unknown command: mg " args) (print usage))])) -- cgit 1.4.1