mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-28 21:19:02 +08:00
test cobra
This commit is contained in:
parent
13132efc6c
commit
6eb13df2e2
@ -30,7 +30,7 @@ func main() {
|
|||||||
startCmd.Flags().IntP(constant.FlagPort, "p", 0, "Port to listen on")
|
startCmd.Flags().IntP(constant.FlagPort, "p", 0, "Port to listen on")
|
||||||
startCmd.Flags().StringP(constant.FlagConf, "c", "", "Path to config file folder")
|
startCmd.Flags().StringP(constant.FlagConf, "c", "", "Path to config file folder")
|
||||||
rootCmd := cmd.NewRootCmd()
|
rootCmd := cmd.NewRootCmd()
|
||||||
cobra.Command(rootCmd).AddCommand(startCmd)
|
rootCmd.Command.AddCommand(startCmd)
|
||||||
if err := startCmd.Execute(); err != nil {
|
if err := startCmd.Execute(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -6,7 +6,9 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RootCmd cobra.Command
|
type RootCmd struct {
|
||||||
|
Command cobra.Command
|
||||||
|
}
|
||||||
|
|
||||||
func NewRootCmd() RootCmd {
|
func NewRootCmd() RootCmd {
|
||||||
c := cobra.Command{
|
c := cobra.Command{
|
||||||
@ -18,11 +20,13 @@ func NewRootCmd() RootCmd {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
c.Flags()
|
c.Flags()
|
||||||
return RootCmd(c)
|
rootCmd := RootCmd{Command: c}
|
||||||
|
rootCmd.init()
|
||||||
|
return rootCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r RootCmd) Init() {
|
func (r RootCmd) init() {
|
||||||
cobra.Command(r).Flags().StringP(constant.FlagConf, "c", "", "Path to config file folder")
|
r.Command.Flags().StringP(constant.FlagConf, "c", "", "Path to config file folder")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfFromCmdAndInit(cmdLines *cobra.Command) error {
|
func getConfFromCmdAndInit(cmdLines *cobra.Command) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user