Skip to content

Commit

Permalink
规范run命令输出
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Feb 9, 2022
1 parent 2a98f82 commit 385f42c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ var langs = map[string]string{
"Root": "应用目录",
"Frontend": "前台地址",
"Dashboard": "管理后台",
"Not enough arguments": "参数错误: 缺少参数",
"Run: %s": "运行: %s",
"Arguments: %s": "参数错误: %s",
"%s Response": "%s 返回结果",
}

// L 多语言切换
Expand Down
15 changes: 8 additions & 7 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/yaoapp/kun/utils"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/engine"
"github.com/yaoapp/yao/share"
)

var runCmd = &cobra.Command{
Expand All @@ -21,16 +22,16 @@ var runCmd = &cobra.Command{
defer gou.KillPlugins()
Boot()
cfg := config.Conf
// cfg.Session.IsCLI = true
cfg.Session.IsCLI = true
engine.Load(cfg)
if len(args) < 1 {
fmt.Println(color.RedString("参数错误: 未指定处理名称"))
fmt.Println(color.WhiteString("xiang run <处理器名称> [参数表...]"))
fmt.Println(color.RedString(L("Not enough arguments")))
fmt.Println(color.WhiteString(share.BUILDNAME + " help"))
return
}

name := args[0]
fmt.Println(color.GreenString("运行处理器: %s", name))
fmt.Println(color.GreenString(L("Run: %s"), name))
pargs := []interface{}{}
for i, arg := range args {
if i == 0 {
Expand All @@ -43,7 +44,7 @@ var runCmd = &cobra.Command{
var v interface{}
err := jsoniter.Unmarshal([]byte(arg), &v)
if err != nil {
fmt.Println(color.RedString("参数错误: %s", err.Error()))
fmt.Println(color.RedString(L("Arguments: %s"), err.Error()))
return
}
pargs = append(pargs, v)
Expand All @@ -61,8 +62,8 @@ var runCmd = &cobra.Command{

process := gou.NewProcess(name, pargs...)
res := process.Run()
fmt.Println(color.WhiteString("\n--------------------------------------"))
fmt.Println(color.WhiteString("%s 返回结果", name))
fmt.Println(color.WhiteString("--------------------------------------"))
fmt.Println(color.WhiteString(L("%s Response"), name))
fmt.Println(color.WhiteString("--------------------------------------"))
utils.Dump(res)
},
Expand Down
10 changes: 1 addition & 9 deletions engine/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,9 @@ func init() {

// processCreate 运行模型 MustCreate
func processPing(process *gou.Process) interface{} {
var input interface{}
if process.NumOfArgs() > 0 {
input = process.Args[0]
}

res := map[string]interface{}{
"code": 200,
"server": "Yao App Engine",
"engine": share.BUILDNAME,
"version": share.VERSION,
// "allows": config.Conf.Service.Allow,
"args": input,
}
return res
}
Expand Down

0 comments on commit 385f42c

Please sign in to comment.