https://github.com/foxcapades/lib-d-opts
https://github.com/foxcapades/lib-d-opts
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/foxcapades/lib-d-opts
- Owner: Foxcapades
- Created: 2018-09-18T22:29:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-08T13:08:05.000Z (about 7 years ago)
- Last Synced: 2025-02-12T17:19:25.709Z (over 1 year ago)
- Language: D
- Size: 43 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: readme.adoc
Awesome Lists containing this project
README
= 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 `
** That can be specified multiple times `-f -f -fff`
* Long flags `--foo`
** With optional values `--foo[=value]`
** With mandatory values `--foo=`
** 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"]
----