Bug 11764 – [REG2.065a]std.getopt broken

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-18T07:16:00Z
Last change time
2013-12-18T14:17:19Z
Assigned to
nobody
Creator
zan77137
See also
https://d.puremagic.com/issues/show_bug.cgi?id=5762

Comments

Comment #0 by zan77137 — 2013-12-18T07:16:21Z
This code doesn't work (git HEAD): import std.getopt; import std.stdio; void main() { auto args = ["main", "-test"]; bool opt; args.getopt(config.passThrough, "opt", &opt); writeln(args); assert(args == ["main", "-test"]); } ---- $ dmd -run main ["main", "-t", "est"] core.exception.AssertError@main(10): Assertion failure
Comment #1 by monarchdodra — 2013-12-18T08:54:06Z
Comment #2 by andrej.mitrovich — 2013-12-18T09:38:18Z
I guess getopt should check whether the option exists before it tries to separate "-abc" to -a=bc?
Comment #3 by andrei — 2013-12-18T09:42:09Z
This is intentional because arguably the use was incorrectly accepted. The commonly used convention is to either use short (single-letter) options with single dash, or long options (multi-letter) with double dashes. The use '-test' is currently interpreted as "pass argument est to the single-letter option -t". That said, a regression is what it is so perhaps we need to continue supporting the old mistake. I'll look into it. Please advise.
Comment #4 by andrej.mitrovich — 2013-12-18T10:23:56Z
(In reply to comment #3) > This is intentional because arguably the use was incorrectly accepted. The > commonly used convention is to either use short (single-letter) options with > single dash, or long options (multi-letter) with double dashes. > > The use '-test' is currently interpreted as "pass argument est to the > single-letter option -t". I think the OPs point however is that the passThrough option should let *you* handle any unsupported syntax like single-dash long options *after* getopt is done, hence why it should not split up "-test" (if there's no -t option then it should arguably not try to split up -test).
Comment #5 by andrei — 2013-12-18T11:24:37Z
Oh I see. Nice!
Comment #6 by andrei — 2013-12-18T12:30:21Z
Comment #7 by github-bugzilla — 2013-12-18T13:46:13Z