From 446e1432bcf0b060ded28254c9a2065a9d9981b5 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 19 Jun 2022 12:47:25 +0200 Subject: [PATCH] fix(cli): show full synopsis for pseudo commands Before: $ doom help help Usage: COMMAND [ARGS...] TODO TODO After: Usage: doom help [-g|--no-global] [--manpage] [--commands] [--synopsis|--subcommands|--similar|--envvars|--postamble] [--] COMMAND [ARGS...] Show documentation for a Doom CLI command. OPTIONS: -g, --no-global Hide global options. --manpage Generate in manpage format. --commands List all known commands. --synopsis, --subcommands, --similar, --envvars, --postamble Show only the specified sections.. Amend: 6c0b7e1530a6 --- core/cli/help.el | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core/cli/help.el b/core/cli/help.el index adc204436..1af2a787c 100644 --- a/core/cli/help.el +++ b/core/cli/help.el @@ -138,13 +138,14 @@ OPTIONS: (defun doom-cli-help (cli) "Return an alist of documentation summarizing CLI (a `doom-cli')." - (let ((docs (doom-cli-docs cli))) + (let* ((rcli (doom-cli-get cli)) + (docs (doom-cli-docs rcli))) `((command . ,(doom-cli-command-string cli)) (summary . ,(or (cdr (assoc "SUMMARY" docs)) "TODO")) (description . ,(or (cdr (assoc "MAIN" docs)) "TODO")) (synopsis . ,(doom-cli-help--synopsis cli)) - (arguments . ,(doom-cli-help--arguments cli)) - (options . ,(doom-cli-help--options cli)) + (arguments . ,(doom-cli-help--arguments rcli)) + (options . ,(doom-cli-help--options rcli)) (commands . ,(doom-cli-subcommands cli 1)) (sections . ,(seq-filter #'cdr (cddr docs)))))) @@ -234,7 +235,8 @@ OPTIONS: ;;; Help: synopsis (defun doom-cli-help--synopsis (cli &optional all-options?) - (let* ((opts (doom-cli-help--options cli)) + (let* ((rcli (doom-cli-get cli)) + (opts (doom-cli-help--options rcli)) (opts (mapcar #'car (if all-options? (mapcan #'cdr opts) (alist-get 'local opts)))) (opts (cl-loop for opt in opts for args = (cdar opt) @@ -245,9 +247,8 @@ OPTIONS: (string-join switches "|") (string-join (remove "..." args) "|")) else collect (format "[%s]" (string-join switches "|")))) - (args (doom-cli-arguments cli)) - ;; (partial? (null (doom-cli-fn cli))) - (subcommands? (doom-cli-subcommands cli 1 :predicate? t))) + (args (doom-cli-arguments rcli)) + (subcommands? (doom-cli-subcommands rcli 1 :predicate? t))) `((command . ,(doom-cli-command cli)) (options ,@opts) (required ,@(mapcar (fn!! (upcase (format "`%s'" %))) (if subcommands? '(command) (alist-get '&required args)))) @@ -354,7 +355,7 @@ The alist's CAR are lists of formatted switches plus their arguments, e.g. local-options global-options seen) - (dolist (neighbor (nreverse (doom-cli-find (doom-cli-command cli)))) + (dolist (neighbor (nreverse (doom-cli-find cli))) (dolist (option (doom-cli-options neighbor)) (when-let* ((switches (cl-loop for sw in (doom-cli-option-switches option) if (and (doom-cli-option-flag-p option)