darg 0.0.4

D command line argument parser.


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

D Argument Parser Build Status

Better command line argument parsing using D's powerful compile-time code generation facilities.

Example

import std.stdio;
import darg;

struct Options
{
    @Option("help", "h")
    @Help("Prints this help.")
    OptionFlag help;

    @Option("threads", "t")
    @Help("Number of threads to use.")
    size_t threads;

    @Argument("file", Multiplicity.zeroOrMore)
    @Help("Input files")
    string[] files;
}

// Generate the usage and help string at compile time.
immutable usage = usageString!Options("example");
immutable help = helpString!Options;

int main(string[] args)
{
    Options options;

    try
    {
        options = parseArgs!Options(args[1 .. $]);
    }
    catch (ArgParseError e)
    {
        writeln(e.msg);
        writeln(usage);
        return 1;
    }
    catch (ArgParseHelp e)
    {
        // Help was requested
        writeln(usage);
        write(help);
        return 0;
    }

    foreach (f; options.files)
    {
        // Use files
    }

    return 0;
}
$ ./example --help
Usage: example [--help] [--threads=<ulong>] [file...]

Positional arguments:
 file            Input files

Optional arguments:
 --help, -h      Prints this help.
 --threads, -t <ulong>
                 Number of threads to use.

$ ./example --foobar
Unknown option '--foobar'
Usage: program [--help] [--threads=<ulong>] [file...]


License

MIT License

Authors:
Jason White
Dependencies:
none
Versions:
0.0.4 2016-Apr-05
0.0.3 2016-Feb-19
0.0.2 2016-Feb-19
0.0.1 2016-Jan-10
~master 2017-Mar-21
Show all 5 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 42 downloads this month

  • 834 downloads total