Thread overview
[Issue 16684] [REG 2.067.0] std.getopt, problem with the automatic handling of "h"
[Issue 16684] std.getopt, problem with the automatic handling of "h"
Jan 05, 2017
b2.temp@gmx.com
Jan 05, 2017
b2.temp@gmx.com
Jan 08, 2017
b2.temp@gmx.com
Jul 21, 2017
Vladimir Panteleev
Jul 21, 2017
Vladimir Panteleev
Jul 21, 2017
Vladimir Panteleev
December 15, 2016
https://issues.dlang.org/show_bug.cgi?id=16684

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@erdani.com
           Assignee|nobody@puremagic.com        |alexandru.razvan.c@gmail.co
                   |                            |m

--
December 22, 2016
https://issues.dlang.org/show_bug.cgi?id=16684

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |trivial

--
January 04, 2017
https://issues.dlang.org/show_bug.cgi?id=16684

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--
January 05, 2017
https://issues.dlang.org/show_bug.cgi?id=16684

--- Comment #1 from b2.temp@gmx.com ---
@Alexandru, I think that the best fix is to

1/ add a static assert() that prevents to specify "-h" or "--help"  (for
example there's already "optionValidator
January 05, 2017
https://issues.dlang.org/show_bug.cgi?id=16684

--- Comment #2 from b2.temp@gmx.com ---
(In reply to b2.temp from comment #1)
> @Alexandru, I think that the best fix is to
> 
> 1/ add a static assert() that prevents to specify "-h" or "--help"  (for
> example there's already "optionValidator" that does a few static checks)
> 
> 2/ also update the documentation, saying that this switch is handled automatically
> 
> The real problem I had before reporting was 1 hour lost trying to get why a function pointer was never called. With a static check this will never happen anymore to anyone.

Forgot to say that the only way to handle "h" should be the getopt results, e.g

void main(string[] args)
{
    import std.getopt;
    auto h = getopt(args, config.passThrough);
    if (h.helpWanted) {}
}

That's why it can be rejected at compile time.

--
January 08, 2017
https://issues.dlang.org/show_bug.cgi?id=16684

b2.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW
           Assignee|alexandru.razvan.c@gmail.co |nobody@puremagic.com
                   |m                           |

--- Comment #3 from b2.temp@gmx.com ---
Sorry, I allow myself to remove the assignee because of https://github.com/dlang/phobos/pull/5024 and also to prevent any double PR.

--
July 21, 2017
https://issues.dlang.org/show_bug.cgi?id=16684

Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |regression

--- Comment #4 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
This is a regression.

Simplified test case:

/////////////// test.d ///////////////
void main()
{
    import std.getopt;

    string[] args = ["program", "-h"];
    getopt(args, config.passThrough);
    assert(args == ["program", "-h"]);
}
//////////////////////////////////////

Introduced in https://github.com/dlang/phobos/pull/2072

(In reply to b2.temp from comment #1)
> @Alexandru, I think that the best fix is to
> 
> 1/ add a static assert() that prevents to specify "-h" or "--help"  (for
> example there's already "optionValidator" that does a few static checks)

What if I want to generate my own help screen? E.g. if I'm using a library around std.getopt that generates its own enhanced help screen (e.g. ae.utils.funopt).

--
July 21, 2017
https://issues.dlang.org/show_bug.cgi?id=16684

--- Comment #5 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
(In reply to b2.temp from comment #2)
> Forgot to say that the only way to handle "h" should be the getopt results, e.g

I guess "helpWanted" is a way to do that, but this was still a breaking change.

Also, I don't think the check can be done at compile-time, since the argument list to getopt consists of regular runtime arguments, so I don't think you can get the switch string literals at compile-time (from within getopt) here.

--
July 21, 2017
https://issues.dlang.org/show_bug.cgi?id=16684

Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|std.getopt, problem with    |[REG 2.067.0] std.getopt,
                   |the automatic handling of   |problem with the automatic
                   |"h"                         |handling of "h"

--