ui: Add hint for command typo.
* guix/ui.scm (command-hint): New variable (run-guix-command): Use it. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
0df4d5aa04
commit
f0a1a55c66
1 changed files with 15 additions and 3 deletions
14
guix/ui.scm
14
guix/ui.scm
|
@ -2123,6 +2123,14 @@ Run COMMAND with ARGS.\n"))
|
||||||
(define (run-guix-command command . args)
|
(define (run-guix-command command . args)
|
||||||
"Run COMMAND with the given ARGS. Report an error when COMMAND is not
|
"Run COMMAND with the given ARGS. Report an error when COMMAND is not
|
||||||
found."
|
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
|
(define module
|
||||||
;; Check if there is a matching extension.
|
;; Check if there is a matching extension.
|
||||||
(match (search-path (extension-directories)
|
(match (search-path (extension-directories)
|
||||||
|
@ -2132,9 +2140,13 @@ found."
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(resolve-interface `(guix scripts ,command)))
|
(resolve-interface `(guix scripts ,command)))
|
||||||
(lambda _
|
(lambda _
|
||||||
|
(let ((hint (command-hint command (commands))))
|
||||||
(format (current-error-port)
|
(format (current-error-port)
|
||||||
(G_ "guix: ~a: command not found~%") command)
|
(G_ "guix: ~a: command not found~%") command)
|
||||||
(show-guix-usage))))
|
(when hint
|
||||||
|
(display-hint (format #f (G_ "Did you mean @code{~a}?")
|
||||||
|
hint)))
|
||||||
|
(show-guix-usage)))))
|
||||||
(file
|
(file
|
||||||
(load file)
|
(load file)
|
||||||
(resolve-interface `(guix extensions ,command)))))
|
(resolve-interface `(guix extensions ,command)))))
|
||||||
|
|
Reference in a new issue