feat: add yaml config support
This commit is contained in:
@ -10,8 +10,15 @@ import (
|
||||
"ultone/internal/unix"
|
||||
)
|
||||
|
||||
var (
|
||||
cliCommand = &cobra.Command{
|
||||
var ()
|
||||
|
||||
func initCli() *cobra.Command {
|
||||
var (
|
||||
svc string
|
||||
cliClient *rpc.Client
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "cli",
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
log.Debug(cmd.Context(), "[cmd.cli] svc address: %s", svc)
|
||||
@ -34,13 +41,8 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
svc string
|
||||
cliClient *rpc.Client
|
||||
)
|
||||
|
||||
func initCli() {
|
||||
cliCommand.PersistentFlags().StringVar(&svc, "svc", opt.RpcAddress, "server unix listen address")
|
||||
cliCommand.AddCommand(&cobra.Command{
|
||||
cmd.PersistentFlags().StringVar(&svc, "svc", opt.RpcAddress, "server unix listen address")
|
||||
cmd.AddCommand(&cobra.Command{
|
||||
Use: "set",
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
log.Debug(cmd.Context(), "[cli.set] all args: %v", args)
|
||||
@ -73,4 +75,6 @@ func initCli() {
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@ -7,6 +7,5 @@ import (
|
||||
func init() {
|
||||
time.Local = time.FixedZone("CST", 8*3600)
|
||||
|
||||
initRoot()
|
||||
initCli()
|
||||
initRoot(initCli())
|
||||
}
|
||||
|
@ -6,17 +6,17 @@ import (
|
||||
"ultone/internal/opt"
|
||||
)
|
||||
|
||||
func initRoot() {
|
||||
rootCommand.PersistentFlags().BoolVar(&opt.Debug, "debug", false, "debug mode")
|
||||
func initRoot(cmds ...*cobra.Command) {
|
||||
rootCommand.PersistentFlags().BoolVar(&opt.Cfg.Debug, "debug", false, "debug mode")
|
||||
rootCommand.PersistentFlags().StringVarP(&filename, "config", "c", "etc/config.json", "config json file path")
|
||||
rootCommand.PersistentPreRun = func(cmd *cobra.Command, args []string) {
|
||||
if opt.Debug {
|
||||
if opt.Cfg.Debug {
|
||||
log.SetLogLevel(log.LogLevelDebug)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
rootCommand.AddCommand(cliCommand)
|
||||
rootCommand.AddCommand(cmds...)
|
||||
}
|
||||
|
||||
var (
|
||||
|
Reference in New Issue
Block a user