58b85ffbf146

Merge.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 21 Dec 2018 21:26:47 -0500
parents 16b92b8ab5d9 (current diff) 45ccf0952128 (diff)
children 1dfdaf51ac28
branches/tags (none)
files src/main.lisp

Changes

--- 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