diff options
author | Leo Famulari <leo@famulari.name> | 2021-02-09 15:09:43 -0500 |
---|---|---|
committer | Leo Famulari <leo@famulari.name> | 2021-02-09 15:09:43 -0500 |
commit | 388bd35dd0df2d231bc2cce3746d7d5fd15df23a (patch) | |
tree | 82e7cc45b8279f83439214c7c79dc7161ffda94d /guix/ui.scm | |
parent | f1c7c2f697877fcb68b53ea062ff8a88f274a2fe (diff) | |
parent | d00380b0077b0df2a0b790bb115d07c1533b8863 (diff) | |
download | guix-patches-388bd35dd0df2d231bc2cce3746d7d5fd15df23a.tar guix-patches-388bd35dd0df2d231bc2cce3746d7d5fd15df23a.tar.gz |
Merge branch 'master' into staging-next
Diffstat (limited to 'guix/ui.scm')
-rw-r--r-- | guix/ui.scm | 85 |
1 files changed, 60 insertions, 25 deletions
diff --git a/guix/ui.scm b/guix/ui.scm index fce2878354..9cea405456 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> +;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2013, 2018 Mark H Weaver <mhw@netris.org> ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org> ;;; Copyright © 2014 Cyril Roelandt <tipecaml@gmail.com> @@ -13,7 +13,7 @@ ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net> ;;; Copyright © 2019 Chris Marusich <cmmarusich@gmail.com> ;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr> -;;; Copyright © 2019 Simon Tournier <zimon.toutoune@gmail.com> +;;; Copyright © 2019, 2021 Simon Tournier <zimon.toutoune@gmail.com> ;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net> ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> ;;; @@ -528,7 +528,7 @@ See the \"Application Setup\" section in the manual, for more info.\n")) "Display version information for COMMAND and `(exit 0)'." (simple-format #t "~a (~a) ~a~%" command %guix-package-name %guix-version) - (format #t "Copyright ~a 2020 ~a" + (format #t "Copyright ~a 2021 ~a" ;; TRANSLATORS: Translate "(C)" to the copyright symbol ;; (C-in-a-circle), if this symbol is available in the user's ;; locale. Otherwise, do not translate "(C)"; leave it as-is. */ @@ -2021,10 +2021,11 @@ optionally contain a version number and an output name, as in these examples: on the 'define-command' top-level form found therein, or #f if FILE does not contain a 'define-command' form." (define command-name - (match (string-split file #\/) - ((_ ... "guix" "scripts" name) + (match (filter (negate string-null?) + (string-split file #\/)) + ((_ ... "guix" (or "scripts" "extensions") name) (list (file-sans-extension name))) - ((_ ... "guix" "scripts" first second) + ((_ ... "guix" (or "scripts" "extensions") first second) (list first (file-sans-extension second))))) ;; The strategy here is to parse FILE. This is much cheaper than a @@ -2046,24 +2047,34 @@ contain a 'define-command' form." (_ (loop))))))) -(define (command-files) +(define* (command-files #:optional directory) "Return the list of source files that define Guix sub-commands." - (define directory - (and=> (search-path %load-path "guix.scm") - (compose (cut string-append <> "/guix/scripts") - dirname))) + (define directory* + (or directory + (and=> (search-path %load-path "guix.scm") + (compose (cut string-append <> "/guix/scripts") + dirname)))) (define dot-scm? (cut string-suffix? ".scm" <>)) - (if directory - (map (cut string-append directory "/" <>) - (scandir directory dot-scm?)) + (if directory* + (map (cut string-append directory* "/" <>) + (scandir directory* dot-scm?)) '())) +(define (extension-directories) + "Return the list of directories containing Guix extensions." + (filter file-exists? + (parse-path + (getenv "GUIX_EXTENSIONS_PATH")))) + (define (commands) "Return the list of commands, alphabetically sorted." - (filter-map source-file-command (command-files))) + (filter-map source-file-command + (append (command-files) + (append-map command-files + (extension-directories))))) (define (show-guix-help) (define (internal? command) @@ -2098,23 +2109,47 @@ Run COMMAND with ARGS.\n")) (('internal . _) #t) ;hide internal commands ((category . synopsis) - (format #t "~% ~a~%" (G_ synopsis)) - (display-commands (filter (category-predicate category) - commands)))) + (let ((relevant-commands (filter (category-predicate category) + commands))) + ;; Only print categories that contain commands. + (match relevant-commands + ((one . more) + (format #t "~% ~a~%" (G_ synopsis)) + (display-commands relevant-commands)) + (_ #f))))) categories)) (show-bug-report-information)) (define (run-guix-command command . args) "Run COMMAND with the given ARGS. Report an error when COMMAND is not found." + (define (command-hint guess commands) + (define command-names + (map (lambda (command) + (match (command-name command) + ((head tail ...) head))) + commands)) + (string-closest (symbol->string guess) command-names #:threshold 3)) + (define module - (catch 'misc-error - (lambda () - (resolve-interface `(guix scripts ,command))) - (lambda - - (format (current-error-port) - (G_ "guix: ~a: command not found~%") command) - (show-guix-usage)))) + ;; Check if there is a matching extension. + (match (search-path (extension-directories) + (format #f "~a.scm" command)) + (#f + (catch 'misc-error + (lambda () + (resolve-interface `(guix scripts ,command))) + (lambda _ + (let ((hint (command-hint command (commands)))) + (format (current-error-port) + (G_ "guix: ~a: command not found~%") command) + (when hint + (display-hint (format #f (G_ "Did you mean @code{~a}?") + hint))) + (show-guix-usage))))) + (file + (load file) + (resolve-interface `(guix extensions ,command))))) (let ((command-main (module-ref module (symbol-append 'guix- command)))) |