diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..3d321d897 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +generated +GNUmakefile diff --git a/std/getopt.d b/std/getopt.d index 295c459ed..789fdc6fa 100644 --- a/std/getopt.d +++ b/std/getopt.d @@ -49,6 +49,8 @@ import std.getopt; string data = "file.dat"; int length = 24; bool verbose; +enum Color { no, yes }; +Color color; void main(string[] args) { @@ -56,7 +58,8 @@ void main(string[] args) args, "length", &length, // numeric "file", &data, // string - "verbose", &verbose); // flag + "verbose", &verbose, // flag + "color", &color); // enum ... } --------- @@ -117,6 +120,19 @@ To set $(D timeout) to $(D 5), invoke the program with either $(D instead, $(D paranoid) is set to 2 and "42" is not considered as part of the normal program arguments.)) + $(LI $(I Enum options.) If an option is bound to an enum, an enum symbol as a + string is expected as the next option, or right within the option separated + with an "=" sign: + +--------- + enum Color { no, yes }; + Color color; // default initialized to Color.no + getopt(args, "color", &color); +--------- + +To set $(D color) to $(D Color.yes), invoke the program with either $(D +--color=yes) or $(D --color yes). + $(LI $(I String options.) If an option is bound to a string, a string is expected as the next option, or right within the option separated with an "=" sign: @@ -459,6 +475,11 @@ void handleOption(R)(string option, R receiver, ref string[] args, if (incremental) ++*receiver; else *receiver = to!(typeof(*receiver))(val); } + else static if (is(typeof(*receiver) == enum)) + { + // enum receiver + *receiver = parse!(typeof(*receiver))(val); + } else static if (is(typeof(*receiver) == string)) { // string receiver @@ -614,6 +635,17 @@ unittest getopt(args, "paranoid+", ¶noid); assert(paranoid == 5, to!(string)(paranoid)); + enum Color { no, yes }; + Color color; + args = (["program.name", "--color=yes",]).dup; + getopt(args, "color", &color); + assert(color, to!(string)(color)); + + color = Color.no; + args = (["program.name", "--color", "yes",]).dup; + getopt(args, "color", &color); + assert(color, to!(string)(color)); + string data = "file.dat"; int length = 24; bool verbose = false; diff --git a/win32.mak b/win32.mak index 13fd10768..58c88406e 100644 --- a/win32.mak +++ b/win32.mak @@ -247,7 +247,7 @@ DOCS= $(DOC)\object.html \ $(DOC)\std_net_isemail.html \ $(DOC)\phobos.html -SRC= unittest.d crc32.d phobos.d +SRC= unittest.d crc32.d index.d SRC_STD= std\zlib.d std\zip.d std\stdint.d std\container.d std\conv.d std\utf.d std\uri.d \ std\math.d std\string.d std\path.d std\date.d std\datetime.d \ @@ -614,8 +614,8 @@ windows.obj : std\c\windows\windows.d $(DOC)\object.html : $(STDDOC) $(DRUNTIME)\src\object_.d $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\object.html $(STDDOC) $(DRUNTIME)\src\object_.d -I$(DRUNTIME)\src\ -$(DOC)\phobos.html : $(STDDOC) phobos.d - $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\phobos.html $(STDDOC) phobos.d +$(DOC)\phobos.html : $(STDDOC) index.d + $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\phobos.html $(STDDOC) index.d $(DOC)\core_atomic.html : $(STDDOC) $(DRUNTIME)\src\core\atomic.d $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\core_atomic.html $(STDDOC) $(DRUNTIME)\src\core\atomic.d -I$(DRUNTIME)\src\