# HG changeset patch # User Steve Losh # Date 1545445607 18000 # Node ID 58b85ffbf146d877f143afeb216b4019cdef338a # Parent 16b92b8ab5d979bdd8c25503654e85707a7112ac# Parent 45ccf095212805da937b432900d03540c4581232 Merge. diff -r 16b92b8ab5d9 -r 58b85ffbf146 src/main.lisp --- a/src/main.lisp Fri Dec 21 18:52:35 2018 -0500 +++ b/src/main.lisp Fri Dec 21 21:26:47 2018 -0500 @@ -408,7 +408,8 @@ (stream *standard-output*) (program-name (first (argv))) (width 80) - (option-width 20)) + (option-width 20) + (include-examples t)) "Print a pretty usage document for `interface` to `stream`. `width` should be the total width (in characters) for line-wrapping purposes. @@ -426,6 +427,7 @@ (print-usage *program-interface* :width 60 :option-width 15) ; => ; foo - do some things and meow + ; ; USAGE: /bin/foo [options] FILES ; ; Foo is a program to frobulate some files, meowing as it @@ -454,9 +456,18 @@ (let* ((option-column 2) (option-padding 2) (doc-column (+ option-column option-width option-padding)) - (doc-width (- width doc-column))) + (doc-width (- width doc-column)) + (examples (examples interface)) + (example-column 2) + (example-width (- width example-column))) (dolist (option (options interface)) - (print-option-usage stream option option-column doc-column doc-width)))) + (print-option-usage stream option option-column doc-column doc-width)) + (when (and examples include-examples) + (format stream "~%Examples:~%") + (loop :for (prose . command) :in examples :do + (format stream "~%~{ ~A~^~%~}~2% ~A~%" + (bobbin:wrap (list prose) example-width) + command))))) (defun print-usage-and-exit (interface &key @@ -464,6 +475,7 @@ (program-name (first (argv))) (width 80) (option-width 20) + (include-examples t) (exit-code 0)) "Print a pretty usage document for `interface` to `stream` and exit. @@ -478,7 +490,8 @@ :stream stream :program-name program-name :width width - :option-width option-width) + :option-width option-width + :include-examples include-examples) (exit exit-code)) (defun print-error-and-exit (error &key