cli icon indicating copy to clipboard operation
cli copied to clipboard

--verbose flag gets interpreted as "print version and exit"

Open tcard opened this issue 1 month ago • 3 comments

My urfave/cli version is

3.6.1

Checklist

  • [x] Are you running the latest v3 release? The list of releases is here.
  • [x] Did you check the manual for your release? The v3 manual is here
  • [x] Did you perform a search about this problem? Here's the GitHub guide about searching.

Dependency Management

  • My project is using go modules.
  • My project is using vendoring.
  • My project is automatically downloading the latest version.

Describe the bug

After the upgrade from v2 to v3, our command starting always printing the version and exiting when passed --verbose.

We narrowed it down to the way --verbose is defined:

&cli.BoolFlag{
	Name:    "verbose",
	Aliases: []string{"v"},
},

It looks like the v alias conflicts with the default version flag.

To reproduce

  • Define a boolean flag that has v as alias.
  • Call the command, setting the flag to true.

See in Go playground.

Observed behavior

Command prints version and exits.

Expected behavior

One of:

  • The clash on alias v is detected and the library returns an error or panics.
  • The custom flag definition completely replaces default version flag.

Additional context

Want to fix this yourself?

I'm open to it!

Run go version and paste its output here

go version go1.25.4 darwin/arm64

Run go env and paste its output here

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/tcard/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/tcard/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/l3/h28qjr993sl4y2cgmkl06v980000gn/T/go-build751984059=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/tcard/go/pkg/mod'
GOOS='darwin'
GOPATH='/Users/tcard/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/tcard/go/pkg/mod/golang.org/[email protected]'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/tcard/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/tcard/go/pkg/mod/golang.org/[email protected]/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.25.4'
GOWORK=''
PKG_CONFIG='pkg-config'

tcard avatar Nov 24 '25 10:11 tcard

@tcard Which version of v2 were you upgrading from ? I dont think this behaviour has changed from v2 to v3. Alias "v" for "version" flag has been around since beginning of v2. A quick fix for you would be to set

cli.VersionFlag.(*cli.BoolFlag).Aliases=[]

dearchap avatar Nov 25 '25 08:11 dearchap

Hey @dearchap, we already worked around this issue and it isn't really affecting us anymore.

We upgraded from version v2.27.7.

Regardless of this is a regression or not, it seems to me this behavior should change.

tcard avatar Nov 25 '25 12:11 tcard

I've added a link to a repro in the Go playground.

tcard avatar Nov 25 '25 12:11 tcard