integrii / flaggy

Idiomatic Go input parsing with subcommands, positional values, and flags at any position. No required project or package layout and no external dependencies.
The Unlicense
858 stars 30 forks source link

Global positional value arguments don't work after subcommands #61

Closed topjor closed 4 years ago

topjor commented 4 years ago

I am trying to have some global positional values after subcommands as these are the same for each command but when parsing flags and entering a value at the positional place I always get an Unexpected argument: <value> exception

It works fine when using them under a subcommand but not globally

Global positional values also dont show up under the help of a subcommand

gist with code and output (mostly copied from example and blank lines removed): https://gist.github.com/topjor/51e52e88e2c7aedb4d5b34c21497d1a1

integrii commented 4 years ago

Oh, a positional actually cant be a global. The positional is in relativity to some subcommand (or the root program) like this:

./myProgram someSubcommand [positional value goes here]

This above positional would only be available after someSubcommand. If it were available from the root, we wouldn't be able to tell if that were a subcommand of some kind or a positional value.

You have to add positional values on every subcommand that has them.

I'm going to close this one - if I am not understanding or if you think something is busted, feel free to leave a reply.