diff --git a/README.md b/README.md index 9c42ba8..cbdd35b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/command-line.scm b/command-line.scm index 31969a6..825ce65 100644 --- a/command-line.scm +++ b/command-line.scm @@ -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