Skip to content

Required global flags are breaking help and completion commands #2244

@louisroyer

Description

@louisroyer

My urfave/cli version is

v3.6.1

Checklist

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

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:

  1. go run . help
  2. go run . completion bash

Observed behavior

  1. 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.
  2. 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

  1. 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.
  2. 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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v3relates to / is being considered for v3kind/bugdescribes or fixes a bugstatus/triagemaintainers still need to look into this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions