crow/parse-command.crow (source)
In this syntax:
* Each name starting with -- is an argument name, and words after that are its argumets.
* Everything before the first named argument will be left unparsed and put in nameless.
* Everything after -- will be left unparsed and put in after.
For example, if the command is: foo bar --a 1 --b 2 3 -- x y z:nameless will be: "foo", "bar"named will be: ("a", (1,)), ("b", (2, 3))after will be: "x", "y", "z"
parsed-command record
== bool(a parsed-command, b parsed-command)
parse-command-error record exception variant-member
exception variant-membershowstring
parse-command parsed-command(args string array)
See comment on parsed-command for syntax.
Parse errors aren't possible with this syntax.
parse-named-args string array? array?(args string array, arg-names symbol array)
This is stricter than parse-command.
It expects only named arguments with no before or after,
and only the names in arg-names are allowed.
Returns an array with an entry for each name in arg-names.
Values in the array will be a list of the argument values,
or an empty option if the corresponding argument name did not appear.
For example, if the command line is "--a --c d" and arg-names are ("a", "b", "c"),
This will return ((),) (), (("d",),).
If the argument syntax is invalid, returns an empty option.
single-string-or-throw string(a string array?, option-name string)
If a as a single element, returns that; else throws an exception.
Useful for arguments that should have a single string as their value.