mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-27 04:59:27 -05:00
guix: scripts: Add hint for option typo.
* guix/scripts.scm (option-hint): New procedure. (parse-command-line): Add 'option-hint'. Co-authored-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
9505b54a4f
commit
0df4d5aa04
1 changed files with 14 additions and 1 deletions
|
@ -4,6 +4,7 @@
|
||||||
;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com>
|
;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com>
|
||||||
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
;;; Copyright © 2021 Ricardo Wurmus <rekado@elephly.net>
|
;;; Copyright © 2021 Ricardo Wurmus <rekado@elephly.net>
|
||||||
|
;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -112,6 +113,13 @@ (define (name . args)
|
||||||
doc
|
doc
|
||||||
body ...)))))
|
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)
|
(define (args-fold* args options unrecognized-option-proc operand-proc . seeds)
|
||||||
"A wrapper on top of `args-fold' that does proper user-facing error
|
"A wrapper on top of `args-fold' that does proper user-facing error
|
||||||
reporting."
|
reporting."
|
||||||
|
@ -149,7 +157,12 @@ (define (parse-options-from args seeds)
|
||||||
;; Actual parsing takes place here.
|
;; Actual parsing takes place here.
|
||||||
(apply args-fold* args options
|
(apply args-fold* args options
|
||||||
(lambda (opt name arg . rest)
|
(lambda (opt name arg . rest)
|
||||||
(leave (G_ "~A: unrecognized option~%") name))
|
(let ((hint (option-hint name options)))
|
||||||
|
(report-error (G_ "~A: unrecognized option~%") name)
|
||||||
|
(when hint
|
||||||
|
(display-hint
|
||||||
|
(format #f (G_ "Did you mean @code{~a}?~%") hint)))
|
||||||
|
(exit 1)))
|
||||||
argument-handler
|
argument-handler
|
||||||
seeds))
|
seeds))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue