Skip to content

feat: add typed flag names - #22

Merged
mfridman merged 2 commits into
mainfrom
feat/typed-flag-names
Aug 21, 2026
Merged

feat: add typed flag names#22
mfridman merged 2 commits into
mainfrom
feat/typed-flag-names

Conversation

@mfridman

Copy link
Copy Markdown
Collaborator

Fix #21.

This PR adds FlagName[T] so GetFlag can infer its return type:

const verbose cli.FlagName[bool] = "verbose"

f.Bool(string(verbose), false, "enable verbose output")

if s.GetFlag(verbose) { // bool inferred
      // ...
}

Existing string literals still work:

s.GetFlag[bool]("verbose")

Note, a string variable must first be converted to FlagName[T]. Supporting both directly would require two methods and I think the type-safety here and no additional method is worth the tradeoff. See the linked issue for more thoughts

@mfridman
mfridman merged commit 1a7381d into main Aug 21, 2026
2 checks passed
@mfridman
mfridman deleted the feat/typed-flag-names branch August 21, 2026 10:51
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.

Add typed flag names with inferred values

1 participant