The current (desired) behavior when a Command specifies a flag that
has the same name as a persistent/inherited flag, is that the local
definition takes precedence. This change updates the various
Flag subset functions to respect that behavior:
* LocalFlags: now returns only the set of flags and persistent flags
attached to the Command itself.
* InheritedFlags: now returns only the set of persistent flags inherited
from the Command's parent(s), excluding any that are overwritten by a
local flag.
* NonInheritedFlags: changed to an alias of LocalFlags.
* AllPersistentFlags: removed as not very useful; it returned the set
of all persistent flags attached to the Command and its parent(s).
Default UsageTemplate updated to use LocalFlags and InheritedFlags
For a single root command with a Run method, the help output still
contains 'help [command]' as a subcommand (because Help is always
added). Since the only subcommand would be 'help', the help is better
off omitted.
This change allows a command to be used both as a subcommand
or a root command without having to define a custom help that elides
the help command when no subcommands are added. Instead, the default
help command is only added when subcommands are present.
If, for some reason, you have an application with some name "foo", and your
app has a subcommand "foo", cobra should behave properly when you call
"foo foo", and it should also behave if you call "foo f".
These changes verify both of these cases and ensure cobra responds properly.
This fixes some issues that appear when testing prefix invocations. Since the
root command lists weren't being cleared, the list would persist between
tests, so there would be multiple instances of each command. Then, if you
tried to match a prefix of one of those commands, you'd get two matches (one
for each instance) and the command would fail.
Resetting the root command lists prevents them from persisting between tests,
resolving this issue.