ArgFlag

void main(string[] args) { bool help; bool detailhelp; int myInt = 2; // Default value == 2 bool myBool; // Default value == bool.init (ie, false) string myStr; // Default value == (string).init (ie, "")

auto cmd = new CmdLineParser(); mixin(defineArg!(cmd, help, "help", "Displays a help summary and exits" )); mixin(defineArg!(cmd, detailhelp, "detailhelp", "Displays a detailed help message and exits" )); mixin(defineArg!(cmd, myInt, "num", "An integer")); mixin(defineArg!(cmd, myBool, "flag", "A flag")); mixin(defineArg!(cmd, myStr, "str", "A string"));

if(!cmd.parse(args) || help) { Stdout.format("{}", cmd.getUsage()); return; } if(detailhelp) { Stdout.format("{}", cmd.getDetailedUsage()); return; }

Stdout.formatln("num: {}", myInt); Stdout.formatln("flag: {}", myBool); Stdout.formatln("str: {}", myStr); }

Sample Command Lines (All these are equivalent): > myApp.exe /num:5 /flag /str:blah > myApp.exe -flag:true -str:blah -num=5 > myApp.exe --num=5 /flag+ "-str:blah" num: 5 flag: true str: blah

> myApp.exe "/str:Hello World" num: 2 flag: false str: Hello World

> myApp.exe /foo Unknown switch: "/foo" Switches: (prefixes can be '/', '-' or '--') -help Displays a help summary and exits -detailhelp Displays a detailed help message and exits -num:<int> An integer (default: 2) -flag A flag -str:<string> A string

Values

ValueMeaning
Optional0b0000_0000
Required0b0000_0001
ToLower0b0000_1000
Advanced0b0001_0000

Meta