command line flag parsing module for the slope programming language
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.
sloum 6e7e94dcf2
Updates flag module to work with namespaces better
9 months ago
README.md Updates flag module to work with namespaces better 9 months ago
main.slo Updates flag module to work with namespaces better 9 months ago
module.json Updates flag module to work with namespaces better 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
  • (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 with string->number as base 10)
  • (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

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.