system: Add hint for action typo.
* guix/scripts/system.scm (actions): New variable. (define-command): Add hint for action typo. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
1cf866c863
commit
b8b56badd3
@ -9,6 +9,7 @@
|
|||||||
;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
|
;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
|
||||||
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
|
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
|
||||||
;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
|
;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
|
||||||
|
;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
@ -1152,6 +1153,13 @@ Some ACTIONS support additional ARGS.\n"))
|
|||||||
;;; Entry point.
|
;;; 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)
|
(define (process-action action args opts)
|
||||||
"Process ACTION, a sub-command, with the arguments are listed in ARGS.
|
"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
|
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)
|
(define (parse-sub-command arg result)
|
||||||
;; Parse sub-command ARG and augment RESULT accordingly.
|
;; Parse sub-command ARG and augment RESULT accordingly.
|
||||||
(if (assoc-ref result 'action)
|
(cond ((assoc-ref result 'action)
|
||||||
(alist-cons 'argument arg result)
|
(alist-cons 'argument arg result))
|
||||||
(let ((action (string->symbol arg)))
|
((member arg actions)
|
||||||
(case action
|
(let ((action (string->symbol arg)))
|
||||||
((build container vm vm-image image disk-image reconfigure init
|
(alist-cons 'action action result)))
|
||||||
extension-graph shepherd-graph
|
(else
|
||||||
list-generations describe
|
(let ((hint (string-closest arg actions #:threshold 3)))
|
||||||
delete-generations roll-back
|
(report-error (G_ "~a: unknown action~%") arg)
|
||||||
switch-generation search docker-image)
|
(when hint
|
||||||
(alist-cons 'action action result))
|
(display-hint
|
||||||
(else (leave (G_ "~a: unknown action~%") action))))))
|
(format #f (G_ "Did you mean @code{~a}?~%") hint)))
|
||||||
|
(exit 1)))))
|
||||||
|
|
||||||
(define (match-pair car)
|
(define (match-pair car)
|
||||||
;; Return a procedure that matches a pair with CAR.
|
;; Return a procedure that matches a pair with CAR.
|
||||||
|
Loading…
Reference in New Issue
Block a user