viper-app/cmd/root.go

46 lines
1015 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cmd
import (
"demo-server/cmd/inits"
"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() {
err := inits.InitFundamental()
if err != nil {
panic(err)
}
})
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./conf/application.yaml)")
}