Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/01-usage.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,13 @@ default `man` is usually smart enough to look next to every directory in your
appropriate subdirectories and it should all Just Work™. Consult the `man`
documentation for more information.

Localization notes
------------------

In general, manual can be written in any language and all text should be given in target language.
To customize adopt output itself several one can pass localized strings to `make-inteface` in `:usage-string`, `:options-string` and `:examples-string`.
Given strings are used instead of default ones.

Implementation Specifics
------------------------

Expand Down
29 changes: 22 additions & 7 deletions src/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@
long-options
usage
help
manual)
manual
usage-string
options-string
examples-string)

(defmethod print-object ((i interface) stream)
(print-unreadable-object (i stream :type t)
Expand All @@ -387,7 +390,7 @@
(length (options i))
(length (groups i)))))

(defun make-interface (&key name summary usage help manual examples contents)
(defun make-interface (&key name summary usage help manual examples contents usage-string options-string examples-string)
"Create and return a command line interface.

This function takes a number of arguments that define how the interface is
Expand All @@ -400,6 +403,10 @@
* `manual` (optional): a string to use in place of `help` when rendering a man page.
* `examples` (optional): an alist of `(prose . command)` conses to render as a list of examples.
* `contents` (optional): a list of options and groups. Ungrouped options will be collected into a single top-level group.
* `usage-string` (optional): a string to use as a 'USAGE' line (may be used for localization)
* `options-string` (optional): a string to use as a 'Options' line (may be used for localization)
* `examples-string` (optional): a string to use as a 'Examples' line (may be used for localization)


See the full documentation for more information.

Expand All @@ -410,14 +417,20 @@
help string
manual (or null string)
examples list
contents list)
contents list
usage-string (or null string)
options-string (or null string)
examples-string (or null string))
(let* ((ungrouped-options (remove-if-not #'optionp contents))
(groups (cons (make-default-group ungrouped-options)
(remove-if-not #'groupp contents)))
(options (loop :for g :in groups :append (options g)))
(interface (make-instance 'interface
:name name
:usage usage
:usage-string (or usage-string "USAGE")
:options-string (or options-string "Options")
:examples-string (or examples-string "Examples")
:summary summary
:help help
:manual manual
Expand Down Expand Up @@ -709,12 +722,12 @@
"WIDTH (~D) must be at least 4 greater than OPTION-WIDTH (~D)"
width option-width)
(format stream "~A - ~A~2%" (name interface) (summary interface))
(format stream "USAGE: ~A ~A~2%" program-name (usage interface))
(format stream "~A: ~A ~A~2%" (usage-string interface) program-name (usage interface))
(format stream (bobbin:wrap (help interface) width))
(format stream "~%")
(dolist (group (groups interface))
(when (or (options group) (help group))
(format stream "~%~A:~%" (or (title group) (name group) "Options"))
(format stream "~%~A:~%" (or (title group) (name group) (options-string interface)))
(let* ((help (help group))
(help-column 2)
(help-width (- width help-column))
Expand All @@ -731,7 +744,7 @@
(example-column 2)
(example-width (- width example-column)))
(when (and examples include-examples)
(format stream "~%Examples:~%")
(format stream "~%~A:~%" (examples-string interface))
(loop :for (prose . command) :in examples :do
(format stream "~%~{ ~A~^~%~}~2% ~A~%"
(bobbin:wrap (list prose) example-width)
Expand Down Expand Up @@ -764,11 +777,13 @@
:include-examples include-examples)
(funcall exit-function exit-code))

(defparameter *error-string* "error")

(defun print-error-and-exit (error &key
(stream *error-output*)
(exit-function #'exit)
(exit-code 1)
(prefix "error: "))
(prefix (format nil "~A: " *error-string*)))
"Print `prefix` and `error` to `stream` and exit.

Example:
Expand Down
2 changes: 2 additions & 0 deletions src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@
:first
:last

:*error-string*

)
(:shadow :collect :reduce :first :last))