[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#45893] [PATCH v2 3/3] ui: Add command hint.
From: |
zimoun |
Subject: |
[bug#45893] [PATCH v2 3/3] ui: Add command hint. |
Date: |
Sat, 16 Jan 2021 01:26:34 +0100 |
* guix/ui.scm (run-guix-command): Add command hint.
---
guix/ui.scm | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/guix/ui.scm b/guix/ui.scm
index bd504c68da..43c2007594 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -2123,6 +2123,20 @@ 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))
+
+ (fold (lambda (name res)
+ (if (string-null? res)
+ (string-append "@code{" name "}")
+ (string-append "@code{" name "}, " res)))
+ ""
+ (string-closest (symbol->string guess) command-names)))
+
(define module
(catch 'misc-error
(lambda ()
@@ -2139,6 +2153,8 @@ found."
(load file)
(resolve-interface `(guix extensions ,command)))))
(lambda _
+ (display-hint (format #f (G_ "Do you mean ~a?")
+ (command-hint command (commands))))
(format (current-error-port)
(G_ "guix: ~a: command not found~%") command)
(show-guix-usage))))))
--
2.29.2
- [bug#45893] [PATCH 0/2] DRAFT: Hint for options., zimoun, 2021/01/15
- [bug#45893] [PATCH 1/2] scripts: search, show: Replace 'args-fold*' by 'parse-command-line'., zimoun, 2021/01/15
- [bug#45893] [PATCH v2 0/3] DRAFT: Hint command line typo, zimoun, 2021/01/15
- [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