Issue 19478 - getopt with config.stopOnFirstNonOption fails to recognize option
Summary: getopt with config.stopOnFirstNonOption fails to recognize option
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Mac OS X
: P3 minor
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-11 16:30 UTC by Timoses
Modified: 2024-12-01 16:34 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Timoses 2018-12-11 16:30:09 UTC
std.getopt seems to fail when reversing the order of the options passed as args when config.stopOnFirstNonOption is enabled.

    string dir1;
    string dir2;
    
    string[] args = ["./app",  "--dir1", "dir1","--dir2", "dir2"];
    auto result = getopt(args,
            config.stopOnFirstNonOption,
            "dir1", "first dir", &dir1,
            "dir2", "second dir", &dir2);

	assert(dir1 == "dir1" && dir2 == "dir2");
    
    args = ["./app",  "--dir2", "dir2","--dir1", "dir1"];
    // No problem without 'config.stopOnFirstNonOption'
    result = getopt(args,
            "dir1", "first dir", &dir1,
            "dir2", "second dir", &dir2);
  
    assert(dir1 == "dir1" && dir2 == "dir2");
    
    args = ["./app",  "--dir2", "dir2","--dir1", "dir1"];
    // Throws: "Unrecognized option --dir1"
    result = getopt(args,
            config.stopOnFirstNonOption,
            "dir1", "first dir", &dir1,
            "dir2", "second dir", &dir2);
Comment 1 dlangBugzillaToGithub 2024-12-01 16:34:37 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10362

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB