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

Unable to pass arguments with negative value #11

@carun

Description

@carun

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>]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions