getopt2 0.0.1

Alternative library for getopt with modeling


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

getopt2

This library is an experimental wrapper for dlang's getopt function.

usage

To use, simply declare an option structure and then pass it to getopt2, along with the parameters. Configuration options can be attached via UDA that affect each parameter (such as caseSensitive). Other udas exist, I will document them eventually.

what it does

It's basically a wrapper to getopt, but uses a struct model to define the options instead of requiring the user to specify everything on the call to getopt. The idea is, you have to define places/functions to be called by getopt anyway, why not use the existing names and structure directly?

Udas replace interspersed config options.

Some config options are for the whole call and are specified on the getopt2 call (such as passThrough).

Very much a WIP.

example

The example from the getopt docs:

import std.getopt;

string data = "file.dat";
int length = 24;
bool verbose;
enum Color { no, yes };
Color color;

void main(string[] args)
{
  auto helpInformation = getopt(
    args,
    "length",  &length,    // numeric
    "file",    &data,      // string
    "verbose", &verbose,   // flag
    "color", "Information about this color", &color);    // enum
  ...

  if (helpInformation.helpWanted)
  {
    defaultGetoptPrinter("Some information about the program.",
      helpInformation.options);
  }
}

And the equivalent with getopt2:

import schlib.getopt2;

enum Color { no, yes }

struct Opts {
    string data = "file.dat";
    int length = 24;
    bool verbose;
    @description("Information about this color") Color color;
}

Opts opts;

void main(string[] args)
{
  auto helpInformation = args.getopt2(opts);
  ...

  if (helpInformation.helpWanted)
  {
    defaultGetoptPrinter("Some information about the program.",
      helpInformation.options);
  }
}
Authors:
  • Steven Schveighoffer
Dependencies:
none
Versions:
0.0.1 2022-Dec-09
~master 2022-Dec-09
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 12 downloads total

Score:
0.4
Short URL:
getopt2.dub.pm