keen/parse-command

Source
parsed-command record
nameless string[]
named string[][symbol]
after string[]

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"

== bool(a parsed-command, b parsed-command)
to json(a parsed-command)
parse-command-error record
show string
parse-command parsed-command(args string[])
See comment on parsed-command for syntax. Parse errors aren't possible with this syntax.
parse-named-args string[] option[] option(args string[], arg-names symbol[])

This is stricter than parse-command. It expects only named arguments, 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(strings string[] option, option-name string)

If a is a single element, returns that; else throws a parse-command-error.

Useful for arguments that should have a single string as their value.