d-opts 1.0.2

Argument parser


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

= CLI Arg Parser :source-highlighter: pygments :icons: font

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 [source, 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 [source, bash session]

$ ./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"]

Authors:
  • Elizabeth Harper
Dependencies:
none
Versions:
1.0.2 2018-Sep-19
1.0.1 2018-Sep-19
1.0.0 2018-Sep-18
~master 2018-Sep-19
~2.0-wip 2018-Sep-28
Show all 5 versions
Download Stats:
  • 2 downloads today

  • 8 downloads this week

  • 10 downloads this month

  • 17 downloads total

Score:
0.1
Short URL:
d-opts.dub.pm