www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9260] New: getopt should allow setting booleans to false

reply d-bugmail puremagic.com writes:
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: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



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



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



-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 02 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9260


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
         AssignedTo|nobody puremagic.com        |andrej.mitrovich gmail.com



10:21:42 PST ---
https://github.com/D-Programming-Language/phobos/pull/1050

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 03 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9260


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx



Would it be too much to support --no-<flagname> as a synonym for --flag=false?
For example, --verbose means --verbose=true, --no-verbose means
--verbose=false.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 28 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9260




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/ba8ea757b984a860ef25fd23a63a698543311a3f
Fixes Issue 9260 - std.getopt: Implement boolean parsing with optional
argument.

https://github.com/D-Programming-Language/phobos/commit/2ad62682c4a7a9b269b566689a2ed5dd444f865c


Issue 9260 - std.getopt: Implement boolean parsing with optional argument

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 08 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9260


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alex lycus.org
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 08 2013