Skip to content

fix: parse explicit short flag values - #511

Open
Rayan-and-beyond wants to merge 3 commits into
spf13:masterfrom
Rayan-and-beyond:fix/short-noopt-explicit-value
Open

Rayan-and-beyond wants to merge 3 commits into
spf13:masterfrom
Rayan-and-beyond:fix/short-noopt-explicit-value

Conversation

@Rayan-and-beyond

Copy link
Copy Markdown

Fixes #207.

A shorthand with NoOptDefVal now accepts a following non-flag token as an explicit value, while preserving the existing shorthand-cluster and boolean behavior. So -v explicit can override the no-option default, but -vb still uses -v's default and continues with -b.

The README now spells out that cluster behavior and the two unambiguous ways to pass an explicit value.

Checked with:

  • focused shorthand/NoOptDefVal parser tests
  • go test .
  • gofmt
  • git diff --check

@CLAassistant

CLAassistant commented Sep 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Ekko82 Ekko82 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this head with Go 1.27.1 on Windows: the two added optional-value tests pass, while two of nine focused required-value cases fail. Those nine cases all pass at merge base 161f35a. I did not run the full suite.

Comment thread flag.go Resolved

@Ekko82 Ekko82 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested 2456e99 on Windows/amd64 with Go 1.27.1: all nine original required-value cases now pass, including -n -1 and -s -pattern. Your two new regression cases and the two optional-value tests also pass. I did not run the full suite.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Processing of short-form arguments when NoOptDefVal is set

3 participants