v2 bug: Do Not Make -v A Global Flag Or At Least Prevent Automatic Inclusion In Subcommands Of The Version Flag #1073
Labels
area/v2
relates to / is being considered for v2
kind/bug
describes or fixes a bug
status/claimed
someone has claimed this issue
my urfave/cli version is
v2.1.1
Checklist
Dependency Management
Describe the bug
The
-v
flag is used as a shorthand for--version
. For example if I have a binary calledfoo
,foo -v
can be used to print the version. Now lets say I have a subcommandbar
with averbose
flag that has av
alias. Running this subcommand will cause a panic, with an error message indicating that thev
flag is redefined. Because theversion
flag is reimported for all commands and subcommands.To reproduce
Create a CLI binary that has a subcommand with any kind of flag that uses either
v
as the flag name, or as the flag alias. I would provide sample code but honestly im lazy and the project is closed-source lolObserved behavior
Program crashes with a panic
Expected behavior
Allow me to invoke my
-v
aliased subcommands.Additional context
Personally I don't think the
-v
aliased--version
flag should be imported to subcommands. Really it should only be available when the CLI binary is invoked without any commands.With a binary
foo
foo subcommand -v
should not be invoking the--version
flag. I can't think of anyone in the history of computers who would invoke-v
with a subcommand to see the version of the CLI binary. It is significantly more keystrokes to get the version byfoo subcommand -v
than it is to get the version byfoo -v
.Additionally it is extremely common for CLI binaries to use
-v
with subcommands to signifyverbose
output. That is actually how I discovered the bug because one of our subcommands is attempting to use-v
to signify verbose output.Currently the solution for this is to alias the
verbose
flag withvv
instead ofv
, but I would really like to be able to usev
because typically unix/linux CLI uses increasing counts ofv
(ievv
andvvv
) to signify increasingly verbose logs.Want to fix this yourself?
I would be willing to fix this myself but might need some guidance as to the part of the codebase to look at.
Run
go version
and paste its output hereRun
go env
and paste its output hereThe text was updated successfully, but these errors were encountered: