Firmeve
命令基于cobra
,在其基础之上提供了一系内置可用命令,以及灵活的命令扩展。命令是Firmeve
运行的最初入口,Firmeve
是通过多命令运行。
命令的创建必须实现contract.Command
接口
Command interface {
// 返回一个新的 cobra command
CobraCmd() *cobra.Command
// 业务主入口
Run(root BaseCommand, cmd *cobra.Command, args []string)
}
以下是一个基础示例:
import (
"fmt"
"github.com/firmeve/firmeve"
"github.com/firmeve/firmeve/kernel/contract"
"github.com/spf13/cobra"
)
type TestCommand struct {
}
func (t TestCommand) CobraCmd() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = "testing"
cmd.Short = "Testing a cmd"
return cmd
}
func (t TestCommand) Run(root contract.BaseCommand, cmd *cobra.Command, args []string) {
fmt.Println("run")
}
更多用法,请参见示例 example/command
所有的命令都是在main
初始化中注册,本质上来说,是所有的子命令会在main
中挂载到系统root command
中
func main() {
firmeve.RunDefault(firmeve.WithCommands(
[]contract.Command{
new(TestCommand),
},
))
}
Firmeve提供了一系列内置运行命令,如:http:serve
migrate
等,具体可执行go run main.go -c config.yaml
查看
关于更多命令开发方法请参考 cobra