Modified CLI parsing API.
[Thread Prev] | [Thread Next]
[Date Prev] | [Date Next]
- Subject: Modified CLI parsing API.
- From: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Date: Sat, 2 May 2015 16:36:44 -0700
- To: myrddin-dev@xxxxxxxxxxxxxx
I'm moving away from getopt-like strings, and towards something that specifies
arguments so that help messages can be automatically generated. For an example
of usage, take a look at the mbld source:
http://git.eigenstate.org/ori/mc.git/tree/mbld/main.myr
To see the data structures and implementation:
http://git.eigenstate.org/ori/mc.git/tree/libstd/optparse.myr
Eventually, when I fix environment capture, I may move to closures for parsed
options, rather than argument lists.
Relevant summary:
opts = [
/* only used for the description: usage: progname [arg summary] argdesc */
.argdesc = "inputlist description",
/* if we get less than minargs [discounting options], we error */
.minargs = 1
/*
the description of the option list.
-h and -? are handled automatically, but you can
override if you want.
*/
.opts = [
/* an option that takes a mandatory argument */
[.opt='x', .arg="xample", .desc="description"],
/* an option that takes an optional argument: -*/
[.opt='o', .arg="optional", .desc="description", .optional=true],
/* an option that takes no argument. */
[.opt='y', .arg="", .desc="description"],
/* equivalently, .arg= can be dropped */
[.opt='z', .desc="description"],
][:]
]
parsed = std.optparse(args, &opts)
for o in parsed.opts
match o
| ('x', arg): /* arg is a string */
| ('y', arg): /* arg is an empty string for no args. */
| ('y', ""): /* again, empty string; since 'z' takes no
args, we always get an empty value */
| ('z', ""): /* see above */
| _:
/* due to exhaustiveness checking, we have to have
a default case. */
std.die("impossible");
;;
;;
for a in parsed.args:
std.put("arg: %s\n", arg)
;;
--
Ori Bernstein
| Re: Modified CLI parsing API. | Ryan Gonzalez <rymg19@xxxxxxxxx> |
- Next by Date: Re: Modified CLI parsing API.
- Next by thread: Re: Modified CLI parsing API.
- Index(es):