From 9076dfe7f8a9da76c30053fb35dbeee49b6aeb4a Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 23 Oct 2021 10:29:36 +0800 Subject: [PATCH] v0.8.16 + run command --- cmd/root.go | 1 + cmd/run.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ share/const.go | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 cmd/run.go diff --git a/cmd/root.go b/cmd/root.go index faa382d7..a17290b4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -35,6 +35,7 @@ func init() { inspectCmd, startCmd, importCmd, + runCmd, ) rootCmd.SetHelpCommand(helpCmd) rootCmd.PersistentFlags().StringVarP(&appPath, "app", "a", "", "指定应用目录") diff --git a/cmd/run.go b/cmd/run.go new file mode 100644 index 00000000..960014d5 --- /dev/null +++ b/cmd/run.go @@ -0,0 +1,45 @@ +package cmd + +import ( + "fmt" + + "github.com/fatih/color" + "github.com/spf13/cobra" + "github.com/yaoapp/gou" + "github.com/yaoapp/kun/utils" + "github.com/yaoapp/xiang/config" + "github.com/yaoapp/xiang/engine" +) + +var runCmd = &cobra.Command{ + Use: "run", + Short: "运行处理器", + Long: `运行处理器`, + Run: func(cmd *cobra.Command, args []string) { + Boot() + engine.Load(config.Conf) + if len(args) < 1 { + fmt.Println(color.RedString("参数错误: 未指定处理名称")) + fmt.Println(color.WhiteString("xiang run <处理器名称> [参数表...]")) + return + } + + name := args[0] + fmt.Println(color.GreenString("运行处理器: %s", name)) + pargs := []interface{}{} + for i, arg := range args { + if i == 0 { + continue + } + pargs = append(pargs, arg) + fmt.Println(color.WhiteString("args[%d]: %s", i-1, arg)) + } + + process := gou.NewProcess(name, pargs...) + res := process.Run() + fmt.Println(color.WhiteString("\n--------------------------------------")) + fmt.Println(color.WhiteString("%s 返回结果", name)) + fmt.Println(color.WhiteString("--------------------------------------")) + utils.Dump(res) + }, +} diff --git a/share/const.go b/share/const.go index 10f80f96..880ecacf 100644 --- a/share/const.go +++ b/share/const.go @@ -5,7 +5,7 @@ import ( ) // VERSION 版本号 -const VERSION = "0.8.15" +const VERSION = "0.8.16" // DOMAIN 许可域 const DOMAIN = "*.iqka.com"