From 87238476c9746a1a0d19d6771c05152f4fc9bd6e Mon Sep 17 00:00:00 2001 From: Raymond Toy Date: Fri, 4 Nov 2022 12:06:51 -0700 Subject: [PATCH] Print list of options neatly, wrapping if needed. When printing help, some options have various equivalent names and sometimes the list of options is long. Wrap the list of options at column 80 if needed. This makes the help neater. --- src/command-line.lisp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/command-line.lisp b/src/command-line.lisp index 915bc1224..3cf9962ad 100644 --- a/src/command-line.lisp +++ b/src/command-line.lisp @@ -76,9 +76,28 @@ (let ((help-string (cl-option-help-string opt)) (names (cl-option-names opt)) (arg (cl-option-argument opt))) - (format t " ~a" (cl-option-description (first names) arg)) - (dolist (name (rest names)) - (format t ", ~a" (cl-option-description name arg))) + #-gcl + (let ((*print-right-margin* 80)) + ;; Print out the options neatly, wrapping if needed. + ;; + ;; This format string is a pprint-logical-block ("~@<...~:>"). + ;; The per-line prefix "~@< ~;" print some space before each line. + ;; + ;; The body, "~{~A~^, ~:_~}", takes a list and prints out each + ;; element followed by ", ", except the last which leaves off + ;; the ", ". If necessary, a newline is inserted ("~:_"). + ;; + ;; There is no suffix ("~;~:>"). + (format t "~@< ~;~{~A~^, ~:_~}~;~:>" + (mapcar #'(lambda (name) + (cl-option-description name arg)) + names))) + #+gcl + (format t " ~{~A~^, ~}" + (mapcar #'(lambda (name) + (cl-option-description name arg)) + names)) + (terpri) (when help-string (print-help-string help-string)) -- 2.11.4.GIT