Skip to content

Feat:(issue_2392) Single-value arguments can be marked as required#2393

Open
idelchi wants to merge 2 commits into
urfave:mainfrom
idelchi:required-single-arg
Open

Feat:(issue_2392) Single-value arguments can be marked as required#2393
idelchi wants to merge 2 commits into
urfave:mainfrom
idelchi:required-single-arg

Conversation

@idelchi

@idelchi idelchi commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • feature

What this PR does / why we need it:

  • args.go: adds a Required field to ArgumentBase, same as flags have. A missing required argument returns required argument "name" not set. Usage() now renders optional single args as [name], matching what {Type}Args already does.
  • args_test.go: adds TestSingleRequiredArg and TestChainedRequiredArgs. The TestArgUsage expectation for an optional arg changes from ia to [ia].
  • docs/v3/examples/arguments/advanced.md: short section on required arguments.
  • godoc-current.txt / testdata/godoc-v3.x.txt: regenerated.

A default Value does not satisfy Required, same as with flags.

Which issue(s) this PR fixes:

Fixes #2392

Special notes for your reviewer:

The help output change (optional single args rendering as [name]) is a separate commit and can be dropped if unwanted.

Testing

  • go test ./...
  • make gfmrun for the docs example
  • make generate + make v3approve for the godoc diff check

Release Notes

Single-value arguments can be marked as `Required`. Optional single-value arguments now render as `[name]` in help output.

@idelchi
idelchi requested a review from a team as a code owner July 20, 2026 20:07
@idelchi
idelchi force-pushed the required-single-arg branch from 7c2cf0a to 526922f Compare July 20, 2026 20:37
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.

No way to mark a single-value argument as required

1 participant