jasonwhite / darg Goto Github PK
View Code? Open in Web Editor NEWRobust command line argument parsing for D.
License: MIT License
Robust command line argument parsing for D.
License: MIT License
DMD v2.079.1 emits deprecation warning
.dub/packages/darg-0.0.4/darg/source/darg.d(616,12): Deprecation: module `std.traits` member Identity is not visible from module darg
Unable to pass CLI arguments with negative values.
import std.stdio;
import darg;
private struct Options {
@Option("help", "h")
@Help("Prints this help.")
OptionFlag help;
@Option("threshold", "t")
@Help("Threshold.")
int threshold;
}
// Generate the usage and help string at compile time.
private immutable usage = usageString!Options("darg-sample");
private immutable help = helpString!Options;
void main(string[] args) {
__gshared Options options;
try {
options = parseArgs!Options(args[1 .. $]);
}
catch (ArgParseError e) {
writeln(e.msg);
writeln(usage);
return;
}
catch (ArgParseHelp e) {
// Help was requested
writeln(usage);
write(help);
return;
}
writeln("Success");
}
21:42:51 ~/code/test $ ./darg-sample -t 1
Success
21:42:55 ~/code/test $ ./darg-sample -t -1
Expected argument for option '-t'
Usage: darg-sample [--help] [--threshold=<int>]
std.experimental.all
is a nice way to import all the symbols in a single statement. But doing so when darg is imported results in the below compiler error.
src\app.d(58,6): Error: darg.Option at ..\..\..\..\AppData\Local\dub\packages\darg-0.1.0\darg\source\darg.d(41,1) conflicts with std.getopt.Option at C:\DevEnv\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(500,1)
..\..\..\..\AppData\Local\dub\packages\darg-0.1.0\darg\source\darg.d(854,25): Error: template instance `app.Options.getUDAs!(help, Option)` error instantiating
src\app.d(220,27): instantiated from here: usageString!(Options)
Is it possible to accept an option multiple times? I tried a couple of approaches, but was unable to get it to work.
I was thinking about having named arguments or mandatory options. This need arises from the fact that I have up to 6 required arguments to my current project which can get quite confusing.
My idea is to implement an UDA NamedArgument
that is similar to Option
but will raise an error if it is missing in the arguments. I would create a mixin for the common code of the two to avoid code duplication.
I would love to get some feedback about this idea.
We are maintaining a basic module library for D programming, which is called HuntใWe like this project very much.
It's so sad to see it is no longer maintained. So, we want to integrate it into Hunt and continue improving it to satify the more future requirements. See here.
Any ideas can let us known. Thanks for your works.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.