Skip to content

feat: add StringMapArgs accessor for the StringMap argument type - #2535

Open
PerryLink wants to merge 1 commit into
urfave:mainfrom
PerryLink:fix/stringmapargs-accessor
Open

PerryLink wants to merge 1 commit into
urfave:mainfrom
PerryLink:fix/stringmapargs-accessor

Conversation

@PerryLink

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • feature

What this PR does / why we need it:

StringMapArgs is the only exported named-argument type in args.go without a matching Command.{Type}Arg accessor. args.go declares:

StringMapArgs = ArgumentBase[map[string]string, StringConfig, StringMap]

while every other argument type can be read back through cmd.FloatArg, cmd.IntArg, cmd.StringArg, ... There is no cmd.StringMapArgs.

Command.Value only looks at flags, and the doc comment on Command.Args() says values consumed by named arguments "should be retrieved via the command.{Type}Arg(name) functions instead". Without this accessor the parsed value of a StringMapArgs argument can only be reached by iterating cmd.Arguments and type-asserting Get(), or through Destination — the documented retrieval path does not exist for this one type.

This adds the accessor the same way StringArg/StringArgs are built (arg[map[string]string](name, c)), returning nil for an unknown name. Parsing behaviour is unchanged.

Which issue(s) this PR fixes:

No issue; reported from source read. This is an API-completion fix for the accessor promised by the Args() doc comment, not a bug fix for a reported failure.

Special notes for your reviewer:

  • The accessor name mirrors the existing type alias StringMapArgs. The alias is singular (ArgumentBase) but carries the Args suffix, so the accessor follows the type name for discoverability; happy to rename to StringMapArg if you prefer.
  • godoc-current.txt and testdata/godoc-v3.x.txt were regenerated with make generate + make v3approve; make v3diff exits 0.

Testing:

  • go test ./... and go vet ./... pass, including the new TestArgsStringMapType. It runs a command with &cli.StringMapArgs{Name: "ma", Destination: &mval} over "a=1,b=2" and checks the Destination, cmd.StringMapArgs("ma"), and the nil result for an unknown name.
  • Removing only the args.go hunk makes the test fail at compile time with cmd.StringMapArgs undefined (type *Command has no field or method StringMapArgs), which is the gap this PR fills.

Release Notes

Add `Command.StringMapArgs` so the value of a `StringMapArgs` argument can be read through the documented `command.{Type}Arg(name)` accessor.

StringMapArgs is the only exported named-argument type without a
Command.{Type}Arg accessor, while Args() documents that named arguments
are read through those accessors. Add Command.StringMapArgs, a test, and
the regenerated godoc snapshots.
@PerryLink
PerryLink requested a review from a team as a code owner November 9, 2026 14:26

This branch has not been deployed

No deployments
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.

1 participant