go-arg icon indicating copy to clipboard operation
go-arg copied to clipboard

flags are a flat namespace

Open mleku opened this issue 1 year ago • 2 comments

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

mleku avatar May 07 '24 20:05 mleku

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.

alexflint avatar May 09 '24 22:05 alexflint