Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
source
.gitignore
dub.json
readme.adoc

readme.adoc

CLI Arg Parser

A clumsy and inconvenient CLI argument parser written in D.

Features

  • Short flags -f

    • With optional values -f [value]

    • With mandatory values -f <value>

    • That can be specified multiple times -f -f -fff

  • Long flags --foo

    • With optional values --foo[=value]

    • With mandatory values --foo=<value>

    • That can be specified multiple times --foo --foo -ff --foo

  • Positional parameters

app.d
import std.stdio;

import eph.args;

void main(const string[] args)
{
  Argument  count = new Argument().shortFlag('c');
  Argument  flag  = new Argument().longFlag("flag").shortFlag('f').requireParam();
  Parameter param = new Parameter();
  ArgParser parse = new ArgParser().register(count, flag).register(param);

  parse.parse(args);

  writefln("count: %d", count.uses());
  writefln("flag: %s", flag.values());
  writefln("param: %s", param.value());
  writefln("extra (unknown values): %s", parse.remainder());
  writefln("passthrough: %s", parse.passthrough());
}
run
$ ./app -cffoo -ccc --flag=bar fizz buzz -- some passthrough values
count: 4
flag: ["foo", "bar"]
param: fizz
extra (unknown values): ["buzz"]
passthrough: ["some", "passthrough", "values"]
You can’t perform that action at this time.