feat: use --debug flag for error more verbose output

This commit is contained in:
wpetit 2022-08-01 15:31:39 +02:00 committed by Bornholm
parent 08cd172502
commit ab4f498b7c
1 changed files with 18 additions and 4 deletions

View File

@ -77,18 +77,32 @@ func main() {
Value: "",
Hidden: true,
},
&cli.BoolFlag{
Name: "debug",
EnvVars: []string{"FORMIDABLE_DEBUG"},
Value: false,
},
},
}
app.ExitErrHandler = func(ctx *cli.Context, err error) {
fmt.Printf("%+v", err)
if err == nil {
return
}
debug := ctx.Bool("debug")
if !debug {
fmt.Printf("[ERROR] %v\n", err)
} else {
fmt.Printf("%+v", err)
}
}
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
err := app.RunContext(ctx, os.Args)
if err != nil {
panic(errors.WithStack(err))
if err := app.RunContext(ctx, os.Args); err != nil {
os.Exit(1)
}
}