GNU bug report logs -
#45893
[PATCH 0/2] DRAFT: Hint for options.
Previous Next
Reported by: zimoun <zimon.toutoune <at> gmail.com>
Date: Fri, 15 Jan 2021 16:38:01 UTC
Severity: normal
Tags: patch
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
Message #44 received at 45893 <at> debbugs.gnu.org (full text, mbox):
* guix/scripts.scm (option-hint): New procedure.
(parse-command-line): Add 'option-hint'.
---
guix/scripts.scm | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/guix/scripts.scm b/guix/scripts.scm
index 34cba35401..e997edbb6d 100644
--- a/guix/scripts.scm
+++ b/guix/scripts.scm
@@ -4,6 +4,7 @@
;;; Copyright © 2015, 2016 Alex Kost <alezost <at> gmail.com>
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke <at> gnu.org>
;;; Copyright © 2021 Ricardo Wurmus <rekado <at> elephly.net>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -112,6 +113,13 @@ procedure, but both the category and synopsis are meant to be read (parsed) by
doc
body ...)))))
+(define (option-hint guess options)
+ "Return the closest long-name OPTIONS from GUESS,
+according to'string-distance'."
+ (define (options->long-names options)
+ (filter string? (append-map option-names options)))
+ (string-closest guess (options->long-names options) #:threshold 3))
+
(define (args-fold* args options unrecognized-option-proc operand-proc . seeds)
"A wrapper on top of `args-fold' that does proper user-facing error
reporting."
@@ -149,7 +157,11 @@ parameter of 'args-fold'."
;; Actual parsing takes place here.
(apply args-fold* args options
(lambda (opt name arg . rest)
- (leave (G_ "~A: unrecognized option~%") name))
+ (let ((hint (option-hint name options)))
+ (when hint
+ (display-hint
+ (format #f (G_ "Do you mean @code{~a}?~%") hint)))
+ (leave (G_ "~A: unrecognized option~%") name)))
argument-handler
seeds))
--
2.29.2
This bug report was last modified 4 years and 106 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.