Bug 10674 – getopt does not work for enum type

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-07-19T07:48:00Z
Last change time
2013-07-19T20:38:36Z
Assigned to
nobody
Creator
ttanjo

Comments

Comment #0 by ttanjo — 2013-07-19T07:48:17Z
In the document of std.getopt.getopt it recognizes enum types but the following code does not work in dmd v2.064-devel-de68798 on Linux 64bit. --- import std.getopt; void main() { auto args = ["--color=yes"]; // The following code is in the document of getopt enum Color { no, yes } Color color; // default initialized to Color.no getopt(args, "color", &color); assert(color == Color.yes); // failed! } ---
Comment #1 by hsteoh — 2013-07-19T08:01:30Z
The problem is that args[0] is expected to be the program name, so std.getopt does not try to parse it as an option. If you replace the declaration of args with this: auto args = ["program.exe", "--color=yes"]; then the code works as expected.
Comment #2 by ttanjo — 2013-07-19T20:38:36Z
Thank you for your comment. After fixing args, I confirmed it works as expected. BTW, > The problem is that args[0] is expected to be the program name, is it described in the document? I did not find it.