D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21057 - getopt, function setter for a long option receive the key, not the value
Summary: getopt, function setter for a long option receive the key, not the value
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-19 15:48 UTC by basile-z
Modified: 2020-07-19 16:06 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description basile-z 2020-07-19 15:48:09 UTC
Not sure if it is a major one, considering that nobody has reported it yet but this the setter for a long option is called with the wrong part of the option, e.g for "--key=value" the setter is called with "key":

---
void setValue(string value)
{
    assert(value == value.stringof, value);
}

void main(string[] args)
{
    args ~= "--key=value";
    import std.getopt;
    getopt(args, "key", &setValue);
}
---

unless i handle the fix by myself, open a PR in for the stable branch please.
Comment 1 basile-z 2020-07-19 15:51:58 UTC
This is blocking some work of me as using a setter is the only* way to translate a string to a enum member that is a D keyword + underscore ;)
Comment 2 elpenguino+D 2020-07-19 15:53:29 UTC
this behavior matches the documentation. you need to use two arguments to get the value.
Comment 3 basile-z 2020-07-19 16:06:26 UTC
Ok.