Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modified CLI parsing API.


Done.

    std.optusage(argv[0], &defs)

On Sat, 2 May 2015 18:49:53 -0500, Ryan Gonzalez <rymg19@xxxxxxxxx> wrote:

> I am very happy with this, considering that 99% of my hate for getopt stems
> from the general API (e.g. no auto help message, the need to do everything
> manually, those stupid option strings...).
> 
> Would it be possible to add an external std.show_usage function that shows
> the first line of the usage message? So I could do stuff like:
> 
> | ('x', arg):
>   if is_not_number(arg)
>     std.put("-x argument must be a number\n")
>     std.show_usage(opts)
>   ;;
> ;;
> 
> 
> On Sat, May 2, 2015 at 6:36 PM, Ori Bernstein <ori@xxxxxxxxxxxxxx> wrote:
> 
> > 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
> >
> >
> 
> 
> -- 
> Ryan
> [ERROR]: Your autotools build scripts are 200 lines longer than your
> program. Something’s wrong.
> http://kirbyfan64.github.io/


-- 
    Ori Bernstein

References:
Modified CLI parsing API.Ori Bernstein <ori@xxxxxxxxxxxxxx>
Re: Modified CLI parsing API.Ryan Gonzalez <rymg19@xxxxxxxxx>