guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

04/05: ui: Add hint for command typo.


From: guix-commits
Subject: 04/05: ui: Add hint for command typo.
Date: Wed, 3 Feb 2021 06:42:12 -0500 (EST)

civodul pushed a commit to branch master
in repository guix.

commit f0a1a55c66c9ad0e5af504907d9558e9d91f30eb
Author: zimoun <zimon.toutoune@gmail.com>
AuthorDate: Tue Jan 19 22:28:10 2021 +0100

    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>
---
 guix/ui.scm | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index 45ae14f..9cea405 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
     ;; Check if there is a matching extension.
     (match (search-path (extension-directories)
@@ -2132,9 +2140,13 @@ found."
          (lambda ()
            (resolve-interface `(guix scripts ,command)))
          (lambda _
-           (format (current-error-port)
-                   (G_ "guix: ~a: command not found~%") command)
-           (show-guix-usage))))
+           (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)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]