http://d.puremagic.com/issues/show_bug.cgi?id=9260
Summary: getopt should allow setting booleans to false
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Andrej Mitrovic <[email protected]> 2013-01-02
19:12:04 PST ---
import std.getopt;
void main(string[] args)
{
bool b;
getopt(args, "b", &b);
}
If you pass:
$ rdmd test.d --b=true
The '=true' is skipped, as getopt only cares whether '--b' is present. The
problem is that this leads to a user thinking that the opposite works:
$ rdmd test.d --b=false
However 'b' is still true in this case, the '=false' part is discarded.
The documentation *does* mention that booleans can only be set to on, however
it only uses the syntax '--b' and never mentions '--b=true' (it might be an
oversight allowing it). To avoid confusion and avoid code breakage, we should
either:
1) Throw when syntax '--b=false' is used, because it has no effect
2) Implement --b=false
I think #2 would be the best choice here.
The current alternative is to use enums, ala:
enum B { no, yes }
import std.getopt;
void main(string[] args)
{
B b;
getopt(args, "b", &b);
}
$ rdmd test.d --b=no
But there should be no problem implementing #2.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------