8
* License: Public Domain
14
this(string longer,T* prop){
18
this(string shorter,string longer,T* prop){
19
_tmp(shorter,longer,prop);
21
//dmdのmixinのバグ避け。thisの扱いが変?
22
protected void _tmp(string shorter,string longer,T* prop){
40
class FlagOption:Option{
43
this(string longer,bool* prop){
46
this(string shorter,string longer,bool* prop){
47
_tmp(shorter,longer,prop);
49
this(string shorter,string longer,bool* prop,bool set){
50
_tmp(shorter,longer,prop);
57
class ArgsOption:Option{}
59
class StringOption:ArgsOption{
60
mixin TOption!(string);
63
class UintOption:ArgsOption{
69
private string[] args;
70
private FlagOption[] fopts;
71
private ArgsOption[] aopts;
73
public void setOption(Option opt){
74
if(ArgsOption t=cast(ArgsOption)opt){
76
}else if(FlagOption t=cast(FlagOption)opt){
86
///設定します。オプションを除いた残りを返します。
87
///Bugs: -faild -ok okval
92
foreach(uint index,string _arg;args){
97
if(arg[0]=='-'&&beforeCommand!="")
98
throw new Exception(beforeCommand~" is not supported.");
99
foreach(FlagOption opt;fopts){
100
if(arg=="-"~opt.shorter||arg=="--"~opt.longer){*opt.prop=opt.set;ok=true;break;}
103
if(arg[0]=='-')beforeCommand=arg;
104
else if(beforeCommand!=""){
106
foreach(ArgsOption opt;aopts){
107
if(beforeCommand=="-"~opt.shorter||beforeCommand=="--"~opt.longer){
108
if(StringOption t=cast(StringOption)opt)*t.prop=arg;
109
else if(UintOption t=cast(UintOption)opt)*t.prop=.toUint(arg);
115
throw new Exception(beforeCommand~" is not supported.");
117
}else isOptions=false;
119
if(!isOptions){if(arg[0]=='\\')arg=arg[1..$];result~=arg;}
121
if(beforeCommand!="")throw new Exception(beforeCommand~" is not supported or parameter is missing.");
134
static string[] sargs=["test","-t","test","-t2","12","--flag","-s","test","test"];
135
Args arg=new Args(sargs);
136
TestOptions* test=new TestOptions;
137
arg.setOption(new StringOption("t","test",&test.stringTest));
138
arg.setOption(new UintOption("t2","test2",&test.uintTest));
139
arg.setOption(new FlagOption("f","flag",&test.flagTest));
140
arg.setOption(new FlagOption("s","ssss",&test.flagTest2,false));
141
string[] items=arg.set();
142
assert(test.stringTest=="test");
143
assert(test.uintTest==12);
144
assert(test.flagTest==true);
145
assert(test.flagTest2==false);
146
static string[] tmp=["test","test"];