github.com/abolfazlbeh/zhycan@v0.0.0-20230819144214-24cf38237387/cmd/cmd_main/commands/templates/root_command.gotmpl (about) 1 /* 2 Create By Zhycan Framework 3 4 Copyright © {{.Year}} 5 Project: {{.ProjectName}} 6 File: `root.go` --> {{ .Time.Format .TimeFormat }} by {{.CreatorUserName}} 7 ------------------------------ 8 */ 9 package commands 10 11 import ( 12 "github.com/spf13/cobra" 13 "github.com/abolfazlbeh/zhycan/pkg/command" 14 "os" 15 ) 16 17 // rootCmd represents the base command when called without any subcommands 18 var rootCmd = &cobra.Command{ 19 Use: "{{.ProjectName}}", 20 Short: "A brief description of your application", 21 Long: `A longer description that spans multiple lines and likely contains 22 examples and usage of using your application. For example: 23 24 Cobra is a CLI library for Go that empowers applications. 25 This application is a tool to generate the needed files 26 to quickly create a Cobra application.`, 27 } 28 29 // Execute adds all child commands to the root command and sets flags appropriately. 30 // This is called by main.main(). It only needs to happen once to the rootCmd. 31 func Execute() { 32 err := rootCmd.Execute() 33 if err != nil { 34 os.Exit(1) 35 } 36 } 37 38 func init() { 39 // Here you will define your flags and configuration settings. 40 // Cobra supports persistent flags, which, if defined here, 41 // will be global for your application. 42 43 // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.test-corba-cli.yaml)") 44 45 // Cobra also supports local flags, which will only run 46 // when this action is called directly. 47 48 //rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 49 50 // Attach Default Zhycan Cli Commands 51 command.AttachCommands(rootCmd) 52 53 // MARK:Commands --- And New Commands Below --- 54 // rootCmd.AddCommand(NewInitCmd()) 55 }