[Issue 19478] New: getopt with config.stopOnFirstNonOption fails to recognize option
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Dec 11 16:30:09 UTC 2018
    
    
  
https://issues.dlang.org/show_bug.cgi?id=19478
          Issue ID: 19478
           Summary: getopt with config.stopOnFirstNonOption fails to
                    recognize option
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: timosesu at gmail.com
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);
--
    
    
More information about the Digitalmars-d-bugs
mailing list