mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
improve command not found error for package gcmd
This commit is contained in:
@ -12,6 +12,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gcfg"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
@ -45,14 +47,13 @@ func (c *Command) RunWithValue(ctx context.Context) (value interface{}, err erro
|
||||
}
|
||||
|
||||
// Print error and help command if no command found.
|
||||
fmt.Printf(
|
||||
"ERROR: command \"%s\" not found for arguments \"%s\"\n",
|
||||
err = gerror.NewCodef(
|
||||
gcode.CodeNotFound,
|
||||
`command "%s" not found for arguments "%s"`,
|
||||
gstr.Join(args, " "),
|
||||
gstr.Join(os.Args, " "),
|
||||
)
|
||||
c.Print()
|
||||
|
||||
return nil, nil
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Command) doRun(ctx context.Context, parser *Parser) (value interface{}, err error) {
|
||||
|
||||
@ -13,6 +13,8 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
@ -127,7 +129,9 @@ gf get golang.org/x/sys
|
||||
}
|
||||
|
||||
if err = commandRoot.Run(ctx); err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
if gerror.Code(err) == gcode.CodeNotFound {
|
||||
commandRoot.Print()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user