Skip to content

getopt callback with index into argument array - #11077

Merged
thewilsonator merged 1 commit into
dlang:masterfrom
burner:issue10902_getopt_order
Aug 6, 2026
Merged

getopt callback with index into argument array#11077
thewilsonator merged 1 commit into
dlang:masterfrom
burner:issue10902_getopt_order

Conversation

@burner

@burner burner commented Aug 4, 2026

Copy link
Copy Markdown
Member

Rationale

getopt normally handles options in a way that make impossible to do positional argument handling.
This adds the minimal change I can think of to allow positional argument handling.

Feature request or issue tracking

Closes #10902.

Pre-review checklist

  • I have performed a self-review of my code.
  • If my PR fixes a bug or introduces a new feature, I have added thorough tests.
  • If my changes are non-trivial and do not concern a reported issue, I have added a changelog entry.

LLM/AI disclosure

@rikkimax

rikkimax commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

This is not pushback.
What I'm wondering is if we are missing the guarantee that handlers are called left to right.
Wouldn't that also solve this problem?

0xEAB

This comment was marked as resolved.

@burner

burner commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

This is not pushback. What I'm wondering is if we are missing the guarantee that handlers are called left to right. Wouldn't that also solve this problem?

Not quite. The issue is that the impl basically does.

foreach(o; option) {
  foreach(idx, a; args) {
    if(o == a) {
       o.out = a;
       args.remove(idx);
    }
  }
}

and then you left with an args that contains the unhandled arguments.
This means, you can't have multiple >1 values assigned to an option.

@burner
burner force-pushed the issue10902_getopt_order branch from d37c097 to bca3515 Compare August 4, 2026 20:39
@burner
burner force-pushed the issue10902_getopt_order branch from bca3515 to f0e8fe3 Compare August 5, 2026 07:15
@atilaneves

Copy link
Copy Markdown
Contributor

I don't think I understand the use case.

@burner

burner commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

I don't think I understand the use case.

have a look at @CyberShadow issue #10902

@thewilsonator
thewilsonator merged commit 5aa554f into dlang:master Aug 6, 2026
10 checks passed
@burner

burner commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

thank you all

@0xEAB

0xEAB commented Aug 7, 2026

Copy link
Copy Markdown
Member

@burner
Thank you for tackling this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

std.getopt does not support order-sensitive options

5 participants