Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jasonwhite/darg
Robust command line argument parsing for D.
https://github.com/jasonwhite/darg
argument-parsing dlang
Last synced: about 1 hour ago
JSON representation
Robust command line argument parsing for D.
- Host: GitHub
- URL: https://github.com/jasonwhite/darg
- Owner: jasonwhite
- License: mit
- Archived: true
- Created: 2015-11-14T07:02:16.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-11-24T08:46:01.000Z (almost 3 years ago)
- Last Synced: 2024-08-04T01:04:16.569Z (4 months ago)
- Topics: argument-parsing, dlang
- Language: D
- Size: 40 KB
- Stars: 38
- Watchers: 7
- Forks: 8
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-d - darg - Robust command line argument parsing for D. (Command Line / XML)
README
[buildbadge]: https://travis-ci.org/jasonwhite/darg.svg?branch=master
[buildstatus]: https://travis-ci.org/jasonwhite/darg# D Argument Parser [![Build Status][buildbadge]][buildstatus]
Better command line argument parsing using D's powerful compile-time code
generation facilities.**Note**: This is a stable library, but it is no longer maintained. If you'd
like to help out with maintanence please make an issue letting me know!## Example
```d
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=] [file...]Positional arguments:
file Input filesOptional arguments:
--help, -h Prints this help.
--threads, -t
Number of threads to use.
$ ./example --foobar
Unknown option '--foobar'
Usage: program [--help] [--threads=] [file...]## License
[MIT License](/LICENSE.md)