Set HelpFlag=nil causes panic
wxiaoguang opened this issue · comments
My urfave/cli version is
2.25.7
Checklist
- Are you running the latest v2 release? The list of releases is here.
- Did you check the manual for your release? The v2 manual is here
- Did you perform a search about this problem? Here's the GitHub guide about searching.
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