about summary refs log tree commit diff
path: root/tools/magrathea/mg.scm
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-12-17T22·42+0300
committertazjin <mail@tazj.in>2021-12-18T15·03+0000
commit46a4e25550456790999c3afe4a578dedb8fe5024 (patch)
tree88f82c418269550be526fe6664494acab594e7eb /tools/magrathea/mg.scm
parent589480a92552732399e8d3c318b5eb18c821677e (diff)
feat(tools/magrathea): add a path command r/3291
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>
Diffstat (limited to 'tools/magrathea/mg.scm')
-rw-r--r--tools/magrathea/mg.scm23
1 files changed, 19 insertions, 4 deletions
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))]))