darg 0.0.5

D command line argument parser.


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:

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.1.0 2018-Aug-11
0.0.5 2018-Jul-31
0.0.4 2016-Apr-05
0.0.3 2016-Feb-19
0.0.2 2016-Feb-19
Show all 7 versions
Download Stats:
  • 0 downloads today

  • 14 downloads this week

  • 26 downloads this month

  • 2778 downloads total

Score:
2.6
Short URL:
darg.dub.pm