CLImate (the same pronunciation as climate) is a CLI generating library. Provising CLI definitions, then the library handles argument check, generates usage message.
Builds climate object. The syntax looks like this
(climate $name
($command "usage"
(group ($sub-command0 "usage of $sub-command0" $processor0
(arguments
((arg0 "arg0 description")
arg1) ;; description can be omit
;; keyword (short long) argument-required default-value usage
(:opt0 (#\o "option0") #t #f "opt0 descrition")
(:opt1 (#\O "option1") #f #f "opt1 descrition")))
($sub-command1 "usage of $sub-command1" $processor1
(options
(:opt0 (#\o "option0") #t #f "opt0 descrition")
(:opt1 (#\O "option1") #f #f "opt1 descrition"))))))This generates below CLI commands
$name $sub-command0 {arg0} {arg1} [-o {opt0}] [-O {opt1}]$name $sub-command1 [-o {opt0}] [-O {opt1}]
The $processor must be a procesure which accepts the arguments described
in the CLI specification. For example, for the $sub-command0, then it must
be like this
(define (processor0 arg0 arg1 :key opt0 opt1) ...)Returns #t if the given obj is climate object, otherwise #f.
Executes the given climate with the given args
The args must be a list of strings represents the command line argument
(define example-cli (climate ...))
;; using main
(define (main args)
(let ((result (execute-climate example-cli (cdr args))))
(display (result-value result)) (newline)
(exit (if (result-success? result) 0 1))))Returns #t if the given obj is climate result object, otherwise #f.
Returns #t if the execution is successful otherwise #f.
Retrieves the result value. When the execution failed due to an unexpected error, then usage message is returned.
The below APIs are also exported from (climate)
Input parsing utilties library.
The arg must be a string.
Converts the given arg into a binary input port. This procedure applies some conversion rules if arg is;
- A string
-, then(standard-input-port)is returned - A string starts with
@, then reading from a file. e.g. If arg is@input.txt, theninput.txtis read - A string doesn't apply the above, then
(open-bytevector-input-port (string->utf8 _arg_)is applied.
Converts given arg to string applying the rule of argument->input-port.
Applying given proc with the result of argument->input-port. If the
keyword argument transcoder is specified, then proc receives a
transcoded port.
Split the given arg with | and returns 2 values. If the arg doesn't
contain |, then arg and default are returned.
If arg is "foo|bar", then the return values are "foo" and "bar".
If arg is "foo", then the return values are "foo" and #f.
If arg is "foo" and default is "buz", then return values are
"foo" and "buz"