Bug 21057 – getopt, function setter for a long option receive the key, not the value
Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-07-19T15:48:09Z
Last change time
2020-07-19T16:06:26Z
Assigned to
No Owner
Creator
Basile-z
Comments
Comment #0 by b2.temp — 2020-07-19T15:48:09Z
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 by b2.temp — 2020-07-19T15:51:58Z
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 by elpenguino+D — 2020-07-19T15:53:29Z
this behavior matches the documentation. you need to use two arguments to get the value.