[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#45893] [PATCH v3 3/3] ui: Add hint for command typo.
From: |
zimoun |
Subject: |
[bug#45893] [PATCH v3 3/3] ui: Add hint for command typo. |
Date: |
Tue, 19 Jan 2021 22:28:10 +0100 |
* guix/ui.scm (command-hint): New variable
* guix/ui.scm (run-guix-command): Use it.
---
guix/ui.scm | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/guix/ui.scm b/guix/ui.scm
index bd504c68da..895c3a721f 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -2123,6 +2123,14 @@ Run COMMAND with ARGS.\n"))
(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 ()
@@ -2139,9 +2147,12 @@ found."
(load file)
(resolve-interface `(guix extensions ,command)))))
(lambda _
- (format (current-error-port)
- (G_ "guix: ~a: command not found~%") command)
- (show-guix-usage))))))
+ (let ((hint (command-hint command (commands))))
+ (when hint
+ (display-hint (format #f (G_ "Do you mean @code{~a}?") hint)))
+ (format (current-error-port)
+ (G_ "guix: ~a: command not found~%") command)
+ (show-guix-usage)))))))
(let ((command-main (module-ref module
(symbol-append 'guix- command))))
--
2.29.2
- [bug#45893] [PATCH 0/2] DRAFT: Hint for options., (continued)
- [bug#45893] [PATCH 0/2] DRAFT: Hint for options., zimoun, 2021/01/26
- [bug#45893] Hint for package name: too slow!, zimoun, 2021/01/19
- [bug#45893] Hint for package name: full matrix iteration, zimoun, 2021/01/20
- [bug#45893] [PATCH 0/2] DRAFT: Hint for options., Ludovic Courtès, 2021/01/26
- [bug#45893] [PATCH 0/2] DRAFT: Hint for options., zimoun, 2021/01/26
- [bug#45893] [PATCH 0/2] DRAFT: Hint for options., Ludovic Courtès, 2021/01/27
- [bug#45893] [PATCH v2 2/3] guix: scripts: Add hint for option typo., zimoun, 2021/01/15
- [bug#45893] [PATCH 0/2] DRAFT: Hint for options., Ludovic Courtès, 2021/01/19
- [bug#45893] [PATCH v3 1/3] utils: Add string distance., zimoun, 2021/01/19