urfave / cli

A simple, fast, and fun package for building command line apps in Go
https://cli.urfave.org
MIT License
21.91k stars 1.69k forks source link

Set HelpFlag=nil causes panic #1794

Closed wxiaoguang closed 11 months ago

wxiaoguang commented 11 months ago

My urfave/cli version is

2.25.7

Checklist

Describe the bug

The comment says:

// HelpFlag prints the help for all commands and subcommands.
// Set to nil to disable the flag.  The subcommand
// will still be added unless HideHelp or HideHelpCommand is set to true.
var HelpFlag Flag = &BoolFlag{

But the code:

func checkHelp(cCtx *Context) bool {
    found := false
    for _, name := range HelpFlag.Names() {  // !!!!!!!!!  PANIC here
        if cCtx.Bool(name) {

To reproduce

package main

import (
    "github.com/urfave/cli/v2"
    "os"
)

func main() {
    cli.HelpFlag = nil
    app := cli.NewApp()
    _ = app.Run(os.Args)
}

Then panic:

/go/pkg/mod/github.com/urfave/cli/v2@v2.25.7/help.go:419