add the actual code
This commit is contained in:
parent
f47fea3751
commit
72fe8cb479
45
cli/helper.go
Normal file
45
cli/helper.go
Normal file
@ -0,0 +1,45 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
type PrintHelpErr struct {
|
||||
Err error
|
||||
Ctx *cli.Context
|
||||
}
|
||||
|
||||
func (e *PrintHelpErr) Error() string {
|
||||
return e.Err.Error()
|
||||
}
|
||||
|
||||
func (e *PrintHelpErr) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
func (e *PrintHelpErr) Is(o error) bool {
|
||||
_, ok := o.(*PrintHelpErr)
|
||||
return ok
|
||||
}
|
||||
|
||||
func ShowHelp(cctx *cli.Context, err error) error {
|
||||
return &PrintHelpErr{Err: err, Ctx: cctx}
|
||||
}
|
||||
|
||||
func RunApp(app *cli.App) {
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
if os.Getenv("LOTUS_DEV") != "" {
|
||||
log.Warnf("%+v", err)
|
||||
} else {
|
||||
fmt.Printf("ERROR: %s\n\n", err)
|
||||
}
|
||||
phe, ok := err.(*PrintHelpErr)
|
||||
if ok {
|
||||
cli.ShowCommandHelp(phe.Ctx, phe.Ctx.Command.Name)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user