2023-02-03 16:18:31 +08:00
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
2023-05-13 01:27:48 +08:00
|
|
|
|
"demo-server/cmd/inits"
|
2023-02-03 16:18:31 +08:00
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var cfgFile string
|
|
|
|
|
|
|
|
|
|
// rootCmd represents the base command when called without any subcommands
|
|
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
|
Use: "${cmd}",
|
|
|
|
|
Short: "${cmd} example",
|
|
|
|
|
Long: `${cmd} example
|
|
|
|
|
use --config use config file to init app.
|
|
|
|
|
`,
|
|
|
|
|
// Uncomment the following line if your bare application
|
|
|
|
|
// has an action associated with it:
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
println("app say: no default opt, see help. ")
|
|
|
|
|
_ = cmd.Help()
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
|
|
|
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
|
|
|
|
func Execute() {
|
|
|
|
|
err := rootCmd.Execute()
|
|
|
|
|
if err != nil {
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
cobra.OnInitialize(func() {
|
2023-05-13 01:27:48 +08:00
|
|
|
|
err := inits.InitFundamental()
|
2023-02-03 16:18:31 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./conf/application.yaml)")
|
|
|
|
|
}
|