1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package cmd
- import (
- "gadmin/config"
- "github.com/spf13/cobra"
- )
- var cfgFile string
- // rootCmd represents the base command when called without any subcommands
- var rootCmd = &cobra.Command{
- Use: "serve",
- Short: "A brief description of your application",
- Long: `A longer description that spans multiple lines and likely contains
- examples and usage of using your application. For example:
- Cobra is a CLI library for Go that empowers applications.
- This application is a tool to generate the needed files
- to quickly create a Cobra application.`,
- // Uncomment the following line if your bare application
- // has an action associated with it:
- // Run: func(cmd *cobra.Command, args []string) {},
- PersistentPreRun: func(cmd *cobra.Command, args []string) {
- if config.SysType == "windows" {
- // envFilename = "local.env"
- // go run main.go -c local67.env
- if cfgFile == "" {
- cfgFile = "local.env"
- }
- } else {
- cfgFile = ".env"
- }
- config.Init(cfgFile)
- },
- }
- // 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() {
- cobra.CheckErr(rootCmd.Execute())
- }
- func init() {
- // cobra.OnInitialize(initConfig)
- // Cobra also supports local flags, which will only run
- // when this action is called directly.
- rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
- rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.cobra.yaml)")
- }
- // initConfig reads in config file and ENV variables if set.
- func initConfig() {
- }
|