Document the command-line module.
This commit is contained in:
parent
b0dc7d478e
commit
cb237f0137
2 changed files with 35 additions and 4 deletions
31
README.md
31
README.md
|
@ -87,6 +87,37 @@ implemented anyway to not require any external dependencies.
|
||||||
|
|
||||||
### Command Line parsing
|
### 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
|
### Dictionary
|
||||||
|
|
||||||
Simple key/value dictionary with most operations implemented in linear
|
Simple key/value dictionary with most operations implemented in linear
|
||||||
|
|
|
@ -27,10 +27,12 @@
|
||||||
|
|
||||||
(module
|
(module
|
||||||
command-line
|
command-line
|
||||||
(command-line
|
(
|
||||||
|
command-line
|
||||||
command-line:parse-command-line
|
command-line:parse-command-line
|
||||||
command-line:print-options
|
command-line:print-options
|
||||||
command-line-tests!)
|
command-line-tests!
|
||||||
|
)
|
||||||
|
|
||||||
(import scheme
|
(import scheme
|
||||||
(chicken base)
|
(chicken base)
|
||||||
|
@ -119,8 +121,6 @@
|
||||||
;; Syntax for expanding various types of options.
|
;; Syntax for expanding various types of options.
|
||||||
(define-syntax make-option
|
(define-syntax make-option
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
((_ opt help proc)
|
|
||||||
(list (symbol->string 'opt) help proc))
|
|
||||||
((_ opt (args ...) help body ...)
|
((_ opt (args ...) help body ...)
|
||||||
(list (symbol->string 'opt)
|
(list (symbol->string 'opt)
|
||||||
help
|
help
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue