mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 06:30:28 +03:00
Merge branch 'master' of github.com:andralex/phobos into current-pull-request
This commit is contained in:
commit
047bf768ec
3 changed files with 38 additions and 4 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
generated
|
||||
GNUmakefile
|
34
std/getopt.d
34
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;
|
||||
|
|
|
@ -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\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue