--help or --version doesn't go into Action of cli.App
I am trying to exit the app when --help or --version flags are passed.
cli.go (ParseCLI function) :
app := &cli.App{
Name: test,
HelpName: test,
Usage: "test",
Version: "1.0.0",
Action: func(c *cli.Context) error {
fmt.Println("I am in cli.App")
return nil
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
}
return cliOpts, nil
main.go :
func main() {
_, err := cli.ParseCLI()
if err != nil {
// log here
os.Exit(1)
}
fmt.Println("test from main.go")
}
If I run go run .\main.go I get :
I am in cli.App
test from main.go
But if I run go run .\main.go --version I get :
test version 1.0.0
test from main.go
Same behaviour with --help.
It outputs help menu and prints test from main.go, but doesn't print I am in cli.App
My idea was that I could put os.exit(0) or something similar instead of printing I am in cli.App.
Where can I tell the cli to exit program if --help or --version is passed?
Similar issue to : https://github.com/urfave/cli/issues/771
Thank you!
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.
Closing this as it has become stale.
I think, if you use --help, it should exit after App.After method rather than run App.Action. But my problem is App.After doesn't run too. It may becase of App.After is added after checkHelp(). I will make a pr, hope it works, and forgive my plastic English.