You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
9 months ago | |
---|---|---|
README.md | 9 months ago | |
main.slo | 9 months ago | |
module.json | 9 months ago |
README.md
flag
flag is a command line flag parsing library for the slope programming language. It will parse flags into strings, bools, or numbers.
api
The following procedures are available:
(flag::bool [flag])
=>bool
- Will check for simple, non-key/value, flags
- Good for checking the presence of something like
-h
or-v
- Returns
#t
if found,#f
if not
(flag::string [flag])
=>string
|#f
- Will check for
--flag=value
or--flag value
style flags and returns the value as a string - Returns
#f
if the flag could not be found
- Will check for
(flag::number [flag])
=>number
|#f
- Will check for
--flag=value
or--flag value
style flags and will try to parse and return the value as a number - Returns
#f
if the flag could not be found or could not be parsed as a number (in accordance withstring->number
as base 10)
- Will check for
(flag::is-set? [flag])
=>bool
- Checks for the presence of a flag, similar to
flag-bool
, but will also check for key/value style flags (--key=value
) - Returns
#t
if found,#f
if not
- Checks for the presence of a flag, similar to
Example
If we have a script, my-script
:
(load-mod flag)
(define print-help? (flag::bool "-h"))
((lambda ()
(if print-help?
(begin (display "Help message [...]\n") (exit 0)))))
(define output-name (flag::string "-o"))
(define compression-level (flag::number "--level"))
and run the following:
my-script -o "test" --level=9
print-help?
would be #f
, and the help message would not print. output-name
would be "test"
. compression-level
would be set as 9
.