From 16acc2ff78f2a2892bcd8b7c2eb3f098ac33d309 Mon Sep 17 00:00:00 2001 From: Paul Pogonyshev Date: Sat, 7 Oct 2023 22:31:43 +0200 Subject: [PATCH] Always display short options before long ones in help screens, even if specified otherwise when defining. --- eldev.el | 4 +++- test/help.el | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/eldev.el b/eldev.el index 1d5b98bb..0550e159 100644 --- a/eldev.el +++ b/eldev.el @@ -1921,7 +1921,9 @@ If COMMAND is nil, list global options instead." (eldev-output (or title "\nOptions:")) (dolist (group by-handler) (let* ((value-mode (eldev-get (car group) :option-value)) - (options (cdr group)) + ;; Sort short options before long ones (but usually they are already sorted). + (options (sort (copy-sequence (cdr group)) + (lambda (a b) (and (not (string-prefix-p "--" (symbol-name a))) (string-prefix-p "--" (symbol-name b)))))) (all-strings (mapconcat #'symbol-name options ", "))) (when (eldev-all-p (string-prefix-p "--" (symbol-name it)) options) (setf all-strings (concat " " all-strings))) diff --git a/test/help.el b/test/help.el index 14f35bca..9cfb35c4 100644 --- a/test/help.el +++ b/test/help.el @@ -35,4 +35,16 @@ (should (= exit-code 0)))) +(eldev-ert-defargtest eldev-help-sorts-option (short-first) + (nil t) + (eldev--test-run "empty-project" ("--setup" `(eldev-defoption eldev--test-custom-option () + "Only for testing" + :options ,(if short-first '(-X --custom-option) '(--custom-option -X)) + :for-command help) + "help" "help") + ;; Should sort short options first, even if (accidentally) specified otherwise when defining. + (should (string-match-p "-X, --custom-option" stdout)) + (should (= exit-code 0)))) + + (provide 'test/help)