docs(cli): show correct command in error message

Before:
  $ doom ci hook commit-msg test
  Error: "doom ci" expected 0 arguments, but got 1

  Usage: doom ci COMMAND [ARGS...]

  See 'doom h[elp] ci' or 'doom ci {-?,--help}' for documentation.

After:
  $ doom ci hook commit-msg test
  Error: ":before doom ci" expected 0 arguments, but got 1

  Usage: doom ci hook commit-msg FILE

  See 'doom h[elp] ci hook commit-msg' or 'doom ci hook commit-msg {-?,--help}' for documentation.
This commit is contained in:
Henrik Lissner 2022-06-19 22:16:38 +02:00
parent 50a0c2ef46
commit ab7f7058f3
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -375,7 +375,7 @@ Return nil if CLI (a `doom-cli') has no explicit documentation."
(when (or (< argc min) (when (or (< argc min)
(> argc max)) (> argc max))
(signal 'doom-cli-wrong-number-of-arguments-error (signal 'doom-cli-wrong-number-of-arguments-error
(list (doom-cli--command context) nil args min max))) (list (doom-cli-key cli) nil args min max)))
(dolist (sym spec) (dolist (sym spec)
(setf (alist-get sym alist) (if args (pop args)))) (setf (alist-get sym alist) (if args (pop args))))
(dolist (type `((&args . ,args) (dolist (type `((&args . ,args)
@ -1667,14 +1667,17 @@ errors to `doom-cli-error-file')."
(doom-cli-wrong-number-of-arguments-error (doom-cli-wrong-number-of-arguments-error
(pcase-let ((`(,command ,flag ,args ,min ,max) (cdr e))) (pcase-let ((`(,command ,flag ,args ,min ,max) (cdr e)))
(print! (red "Error: %S expected %s argument%s, but got %d") (print! (red "Error: %S expected %s argument%s, but got %d")
(or flag (doom-cli-command-string (cdr command))) (or flag (doom-cli-command-string
(if (keywordp (car command))
command
(cdr command))))
(if (or (= min max) (if (or (= min max)
(= max most-positive-fixnum)) (= max most-positive-fixnum))
min min
(format "%d-%d" min max)) (format "%d-%d" min max))
(if (or (= min 0) (> min 1)) "s" "") (if (or (= min 0) (> min 1)) "s" "")
(length args)) (length args))
(doom-cli-call `(:help "--synopsis" "--postamble" ,@(cdr command)) context e)) (doom-cli-call `(:help "--synopsis" "--postamble" ,@(cdr (doom-cli--command context))) context e))
5) 5)
(doom-cli-unrecognized-option-error (doom-cli-unrecognized-option-error
(print! (red "Error: unknown option %s") (cadr e)) (print! (red "Error: unknown option %s") (cadr e))