Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Unable to pass arguments with negative value #11

Open
carun opened this issue Feb 13, 2019 · 0 comments
Open

Unable to pass arguments with negative value #11

carun opened this issue Feb 13, 2019 · 0 comments

Comments

@carun
Copy link

carun commented Feb 13, 2019

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>]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant