62 Star 347 Fork 418

infraboard / go-course

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
root.go 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
Mr.Yu 提交于 2021-09-04 18:41 . update day14
package cmd
import (
"errors"
"fmt"
"os"
"github.com/spf13/cobra"
)
var (
// pusher service config option
confType string
confFile string
confETCD string
)
var vers bool
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "demo-api",
Short: "demo-api 管理系统",
Long: `demo-api ...`,
RunE: func(cmd *cobra.Command, args []string) error {
// if vers {
// fmt.Println(version.FullVersion())
// return nil
// }
return errors.New("no flags find")
},
}
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}
func init() {
RootCmd.PersistentFlags().StringVarP(&confType, "config-type", "t", "file", "the service config type [file/env/etcd]")
RootCmd.PersistentFlags().StringVarP(&confFile, "config-file", "f", "etc/demo.toml", "the service config from file")
RootCmd.PersistentFlags().StringVarP(&confETCD, "config-etcd", "e", "127.0.0.1:2379", "the service config from etcd")
RootCmd.PersistentFlags().BoolVarP(&vers, "version", "v", false, "the demo version")
}
Go
1
https://gitee.com/infraboard/go-course.git
git@gitee.com:infraboard/go-course.git
infraboard
go-course
go-course
19a3f401ff21

搜索帮助