diff options
author | Paul A. Patience <paul@apatience.com> | 2022-02-08 11:39:44 +0000 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-02-08 08:09:17 -0800 |
commit | 061e8e5618ef445dcb133087cad74761de13070d (patch) | |
tree | c24e3e8f3bb4c7cfb27f388f8109c5fce722a011 | |
parent | 7783f13a2994ae144c05e2bafbe8a76eef39b028 (diff) | |
download | txr-061e8e5618ef445dcb133087cad74761de13070d.tar.gz txr-061e8e5618ef445dcb133087cad74761de13070d.tar.bz2 txr-061e8e5618ef445dcb133087cad74761de13070d.zip |
getopts: fix superfluous options header.
* stdlib/getopts.tl (opthelp): Print the options header only if
we have documented options.
-rw-r--r-- | stdlib/getopts.tl | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/stdlib/getopts.tl b/stdlib/getopts.tl index 18bec996..fcfa8ea8 100644 --- a/stdlib/getopts.tl +++ b/stdlib/getopts.tl @@ -274,32 +274,34 @@ opt-desc-list)) : (do if @1.long @1.long @1.short)]) (undocumented (keep-if (op null @1.helptext) opt-desc-list))) - (put-line "\nOptions:\n") - (each ((od sorted)) - (let* ((type (if (and (consp od.type) (eq (car od.type) 'cumul)) - (cadr od.type) - od.type)) - (tstr (cond - ((keywordp type) (upcase-str (symbol-name type))) - ((and (consp type) (eq (car type) 'list)) + (put-line) + (when sorted + (put-line "Options:\n") + (each ((od sorted)) + (let* ((type (if (and (consp od.type) (eq (car od.type) 'cumul)) + (cadr od.type) + od.type)) + (tstr (cond + ((keywordp type) (upcase-str (symbol-name type))) + ((and (consp type) (eq (car type) 'list)) (let ((ts (upcase-str (symbol-name (cadr type))))) `@ts[,@ts...]`)) - (t "ARG"))) - (long (if od.long - `--@{od.long}@(if od.arg-p `=@tstr`)`)) - (short (if od.short - `-@{od.short}@(if od.arg-p ` @tstr`)`)) - (ls (cond - ((and long short) `@{long 21} (@short)`) - (long long) - (short `@{"" 21} @short`))) - (lines (if od.helptext (sys:wdwrap od.helptext 43)))) - (if (>= (len ls) 34) - (put-line ` @ls`) - (put-line ` @{ls 34}@(pop lines)`)) - (while lines - (put-line ` @{"" 34}@(pop lines)`)))) - (put-line) + (t "ARG"))) + (long (if od.long + `--@{od.long}@(if od.arg-p `=@tstr`)`)) + (short (if od.short + `-@{od.short}@(if od.arg-p ` @tstr`)`)) + (ls (cond + ((and long short) `@{long 21} (@short)`) + (long long) + (short `@{"" 21} @short`))) + (lines (if od.helptext (sys:wdwrap od.helptext 43)))) + (if (>= (len ls) 34) + (put-line ` @ls`) + (put-line ` @{ls 34}@(pop lines)`)) + (while lines + (put-line ` @{"" 34}@(pop lines)`)))) + (put-line)) (when undocumented (put-line "Undocumented options:\n") (let* ((undoc-str `@{[mapcar sys:opt-dash |