Document the command-line module.

This commit is contained in:
Dominik Pantůček 2023-03-20 22:07:06 +01:00
parent b0dc7d478e
commit cb237f0137
2 changed files with 35 additions and 4 deletions

View file

@ -87,6 +87,37 @@ implemented anyway to not require any external dependencies.
### Command Line parsing
Generic syntax-based implementation of command-line options parsing
with focus on generated help and ergonomic binding of option
arguments.
(command-line print-help (opt (args ...) help body ...) ...)
* ```print-help``` - identifier binding for the help printing procedure
* ```opt``` - command-line option name as identifier (unquoted symbol)
* ```args ...``` - optional arguments of given option
* ```help``` - help string for this option
* ```body ...``` - expressions to be evaluated upon option match
Parses command-line arguments based on the specification given. If
evaluated inside ```csi``` script, only options and arguments after
the ```--``` meta-option are parsed. If evaluated inside compiled
binary, all arguments are parsed as usual.
Each option is represented by the ```opt``` option identifier
(unquoted symbol), optional arguments ```args``` which become bound in
the option specification ```body ...``` expressions, help string and
the actual expressions to be evaluated when the option (and possibly
its arguments) match.
If an option is encountered on the command-line and not enough
arguments (according to the option specification) are provided for it,
an exception is raised.
Within any of the ```body ...``` expressions the ```print-help```
procedure can be used to print the options, their argument names and
help strings in a nice, human-readable format.
### Dictionary
Simple key/value dictionary with most operations implemented in linear

View file

@ -27,10 +27,12 @@
(module
command-line
(command-line
(
command-line
command-line:parse-command-line
command-line:print-options
command-line-tests!)
command-line-tests!
)
(import scheme
(chicken base)
@ -119,8 +121,6 @@
;; Syntax for expanding various types of options.
(define-syntax make-option
(syntax-rules ()
((_ opt help proc)
(list (symbol->string 'opt) help proc))
((_ opt (args ...) help body ...)
(list (symbol->string 'opt)
help