Janet 1.38.0-73334f3 Documentation
(Other Versions:
1.37.1
1.36.0
1.35.0
1.34.0
1.31.0
1.29.1
1.28.0
1.27.0
1.26.0
1.25.1
1.24.0
1.23.0
1.22.0
1.21.0
1.20.0
1.19.0
1.18.1
1.17.1
1.16.1
1.15.0
1.13.1
1.12.2
1.11.1
1.10.1
1.9.1
1.8.1
1.7.0
1.6.0
1.5.1
1.5.0
1.4.0
1.3.1
)
Argument Parsing
Index
(argparse description &keys options)
Parse (dyn :args)
according to options. If the arguments are incorrect, will return nil and print usage
information.
Each option is a table or struct that specifies a flag or option for the script. The name of the option should
be a string, specified via (argparse/argparse "..." op1-name {...} op2-name {...} ...)
. A help option and
usage text is automatically generated for you.
The keys in each option table are as follows:
-
:kind
- What kind of option is this? One of:flag
,:multi
,:option
, or:accumulate
. A flag can either be on or off, a multi is a flag that can be provided multiple times, each time adding 1 to a returned integer, an option is a key that will be set in the returned table, and accumulate means an option can be specified 0 or more times, each time appending a value to an array. -
:short
- Single letter for shorthand access. -
:help
- Help text for the option, explaining what it is. -
:default
- Default value for the option. -
:required
- Whether or not an option is required. -
:short-circuit
- Whether or not to stop parsing if this option is hit. Result will also contain the rest of the arguments under the :rest key. -
:action
- A function that will be invoked when the option is parsed. -
:map
- A function that is applied to the value of the option to transform it
There is also a special option name :default
that will be invoked on arguments that do not start with a -- or
-. Use this option to collect unnamed arguments to your script. This is separate from the :default
key in
option specifiers.
After "--", every argument is treated as an unnamed argument.
Once parsed, values are accessible in the returned table by the name of the option. For example (result
"verbose")
will check if the verbose flag is enabled. You may also use a custom args array when specified via
the special option :args
.