My urfave/cli version is
v3.6.1
Checklist
Dependency Management
- My project is using go modules.
Describe the bug
When adding a global flag with Required: true, the help and the completion subcommands are no longer working if the flag is not set. I expect global required flags to be required only for user defined commands, not to default one's.
To reproduce
package main
import (
"context"
"log"
"os"
"github.com/urfave/cli/v3"
)
func main() {
cmd := &cli.Command{
EnableShellCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "lang",
Required: true,
Aliases: []string{"l"},
Value: "english",
Usage: "language for the greeting",
Sources: cli.EnvVars("APP_LANG"),
},
},
}
if err := cmd.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
}
Then run:
go run . help
go run . completion bash
Observed behavior
- The help message of the
help subcommand is displayed, a message Required flag "lang" not set is displayed, and the command exits with code 1.
- The help message of the
completion subcommand is displayed, a message Required flag "lang" not set is displayed, and the command exits with code 1.
Expected behavior
- Display global help, don't bother about the required flag (they should only be required for user defined subcommands, not default one's), exit with code 0.
- Output the bash completion script, don't bother about the required flag (they should only be required for user defined subcommands, not default one's), exit with code 0.
Run go version and paste its output here
go version go1.25.5 linux/amd64
Run go env and paste its output here
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/louis/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/louis/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2892386511=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/louis/Téléchargements/tcli/go.mod'
GOMODCACHE='/home/louis/.local/share/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/louis/.local/share/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/louis/.local/share/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.5.linux-amd64'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/louis/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/louis/.local/share/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.5.linux-amd64/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.5'
GOWORK=''
PKG_CONFIG='pkg-config'
My urfave/cli version is
v3.6.1
Checklist
Dependency Management
Describe the bug
When adding a global flag with
Required: true, thehelpand thecompletionsubcommands are no longer working if the flag is not set. I expect global required flags to be required only for user defined commands, not to default one's.To reproduce
Then run:
go run . helpgo run . completion bashObserved behavior
helpsubcommand is displayed, a messageRequired flag "lang" not setis displayed, and the command exits with code 1.completionsubcommand is displayed, a messageRequired flag "lang" not setis displayed, and the command exits with code 1.Expected behavior
Run
go versionand paste its output hereRun
go envand paste its output here