unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#50314] [PATCH 0/2] Add hint typo for importers and system actions
@ 2021-09-01  9:55 zimoun
  2021-09-01  9:57 ` [bug#50314] [PATCH 1/2] import: Add hint for importer typo zimoun
  2021-09-07 13:51 ` bug#50314: [PATCH 0/2] Add hint typo for importers and system actions Ludovic Courtès
  0 siblings, 2 replies; 4+ messages in thread
From: zimoun @ 2021-09-01  9:55 UTC (permalink / raw)
  To: 50314; +Cc: zimoun

Hi,

Instead of,

        $ guix import pypy foo
        guix import: error: pypy: invalid importer

it becomes

        $ ./pre-inst-env guix import pypy foo
        guix import: error: pypy: invalid importer
        hint: Did you mean `pypi'?

And thanks to Sarah, the --options are also hinted (when typo).

Note that it is not possible to guess which importer is between 'cpan' and
'cran' for the typo 'can'.  The first from the list 'importers' is returned,
i.e., 'cpan'.

Last, instead of

        $ guix system sarch cuirass
        guix system: error: sarch: unknown action

it becomes

        $ ./pre-inst-env guix system sarch cuirass
        guix system: error: sarch: unknown action
        hint: Did you mean `search'?


All the best,
simon


zimoun (2):
  import: Add hint for importer typo.
  system: Add hint for action typo.

 guix/scripts/import.scm |  8 +++++++-
 guix/scripts/system.scm | 31 ++++++++++++++++++++-----------
 2 files changed, 27 insertions(+), 12 deletions(-)


base-commit: 1a657497acdead9afbeb24db6102f645d7e28ac9
-- 
2.29.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [bug#50314] [PATCH 1/2] import: Add hint for importer typo.
  2021-09-01  9:55 [bug#50314] [PATCH 0/2] Add hint typo for importers and system actions zimoun
@ 2021-09-01  9:57 ` zimoun
  2021-09-01  9:57   ` [bug#50314] [PATCH 2/2] system: Add hint for action typo zimoun
  2021-09-07 13:51 ` bug#50314: [PATCH 0/2] Add hint typo for importers and system actions Ludovic Courtès
  1 sibling, 1 reply; 4+ messages in thread
From: zimoun @ 2021-09-01  9:57 UTC (permalink / raw)
  To: 50314; +Cc: zimoun

* guix/scripts/import.scm (define-command): Add hint.
---
 guix/scripts/import.scm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index b369a362d0..11e94769bb 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
 ;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
 ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -130,4 +131,9 @@ Run IMPORTER with ARGS.\n"))
                         expressions))
              (x
               (leave (G_ "'~a' import failed~%") importer))))
-         (leave (G_ "~a: invalid importer~%") importer)))))
+         (let ((hint (string-closest importer importers #:threshold 3)))
+           (report-error (G_ "~a: invalid importer~%") importer)
+           (when hint
+             (display-hint
+              (format #f (G_ "Did you mean @code{~a}?~%") hint)))
+           (exit 1))))))
-- 
2.29.2





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#50314] [PATCH 2/2] system: Add hint for action typo.
  2021-09-01  9:57 ` [bug#50314] [PATCH 1/2] import: Add hint for importer typo zimoun
@ 2021-09-01  9:57   ` zimoun
  0 siblings, 0 replies; 4+ messages in thread
From: zimoun @ 2021-09-01  9:57 UTC (permalink / raw)
  To: 50314; +Cc: zimoun

* guix/scripts/system.scm (actions): New variable.
(define-command): Add hint for action typo.
---
 guix/scripts/system.scm | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 83bbefd3dc..65eb98e4b2 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -9,6 +9,7 @@
 ;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
 ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1152,6 +1153,13 @@ Some ACTIONS support additional ARGS.\n"))
 ;;; Entry point.
 ;;;
 
+(define actions '("build" "container" "vm" "vm-image" "image" "disk-image"
+                  "reconfigure" "init"
+                  "extension-graph" "shepherd-graph"
+                  "list-generations" "describe"
+                  "delete-generations" "roll-back"
+                  "switch-generation" "search" "docker-image"))
+
 (define (process-action action args opts)
   "Process ACTION, a sub-command, with the arguments are listed in ARGS.
 ACTION must be one of the sub-commands that takes an operating system
@@ -1335,17 +1343,18 @@ argument list and OPTS is the option alist."
 
   (define (parse-sub-command arg result)
     ;; Parse sub-command ARG and augment RESULT accordingly.
-    (if (assoc-ref result 'action)
-        (alist-cons 'argument arg result)
-        (let ((action (string->symbol arg)))
-          (case action
-            ((build container vm vm-image image disk-image reconfigure init
-              extension-graph shepherd-graph
-              list-generations describe
-              delete-generations roll-back
-              switch-generation search docker-image)
-             (alist-cons 'action action result))
-            (else (leave (G_ "~a: unknown action~%") action))))))
+    (cond ((assoc-ref result 'action)
+           (alist-cons 'argument arg result))
+          ((member arg actions)
+           (let ((action (string->symbol arg)))
+             (alist-cons 'action action result)))
+          (else
+           (let ((hint (string-closest arg actions #:threshold 3)))
+             (report-error (G_ "~a: unknown action~%") arg)
+             (when hint
+               (display-hint
+                (format #f (G_ "Did you mean @code{~a}?~%") hint)))
+             (exit 1)))))
 
   (define (match-pair car)
     ;; Return a procedure that matches a pair with CAR.
-- 
2.29.2





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#50314: [PATCH 0/2] Add hint typo for importers and system actions
  2021-09-01  9:55 [bug#50314] [PATCH 0/2] Add hint typo for importers and system actions zimoun
  2021-09-01  9:57 ` [bug#50314] [PATCH 1/2] import: Add hint for importer typo zimoun
@ 2021-09-07 13:51 ` Ludovic Courtès
  1 sibling, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2021-09-07 13:51 UTC (permalink / raw)
  To: zimoun; +Cc: 50314-done

Hello!

zimoun <zimon.toutoune@gmail.com> skribis:

> Instead of,
>
>         $ guix import pypy foo
>         guix import: error: pypy: invalid importer
>
> it becomes
>
>         $ ./pre-inst-env guix import pypy foo
>         guix import: error: pypy: invalid importer
>         hint: Did you mean `pypi'?
>
> And thanks to Sarah, the --options are also hinted (when typo).

[...]

>         $ ./pre-inst-env guix system sarch cuirass
>         guix system: error: sarch: unknown action
>         hint: Did you mean `search'?

Nice!

>   import: Add hint for importer typo.
>   system: Add hint for action typo.

Applied, thanks!  :-)

Ludo’.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-07 14:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01  9:55 [bug#50314] [PATCH 0/2] Add hint typo for importers and system actions zimoun
2021-09-01  9:57 ` [bug#50314] [PATCH 1/2] import: Add hint for importer typo zimoun
2021-09-01  9:57   ` [bug#50314] [PATCH 2/2] system: Add hint for action typo zimoun
2021-09-07 13:51 ` bug#50314: [PATCH 0/2] Add hint typo for importers and system actions Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).