alexflint / go-arg

Struct-based argument parsing in Go
https://pkg.go.dev/github.com/alexflint/go-arg
BSD 2-Clause "Simplified" License
2.04k stars 100 forks source link

flags are a flat namespace #247

Open mleku opened 6 months ago

mleku commented 6 months ago

i just tested and with a subcommand and a flag value with the same -a the one in the subcommand did not work or register an error

not sure if this is an error or just something that should be pointed out in the documentation for the subcommands, and it might be worth adding some kind of validation for duplicate items to warn when using the MustParse method

alexflint commented 6 months ago

If you have an option -a on both the top-level struct and also on a subcommand, then depending on where in the command line you put the -a, you will either be interacting with the top-level or subcommand version of that option:

./my-program -a mysubcommand  # goes to the top-level version of the -a option
./my-program mysubcommand -a  # goes to the subcommand version of the -a option

I agree this is a bit dicey, actually. I'm worried that it's unhelpful. And you're right that it's not documented! I'll fix that.

mleku commented 6 months ago

i don't mind it being flat just it should be documented and there should be a validation to ensure no collisions