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
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
- Registered by Jason White
- 0.0.5 released 6 years ago
- jasonwhite/darg
- MIT
- Copyright © 2015-2016, Jason White
- Authors:
- 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 - Download Stats:
-
-
1 downloads today
-
3 downloads this week
-
10 downloads this month
-
2751 downloads total
-
- Score:
- 2.2
- Short URL:
- darg.dub.pm