github.com/abolfazlbeh/zhycan@v0.0.0-20230819144214-24cf38237387/cmd/cmd_main/commands/templates/command.gotmpl (about) 1 /* 2 Create By Zhycan Framework 3 4 Copyright © {{.Year}} 5 Project: {{.ProjectName}} 6 File: `{{.CommandName}}_command.go` --> {{ .Time.Format .TimeFormat }} by {{.CreatorUserName}} 7 ------------------------------ 8 */ 9 package commands 10 11 import ( 12 "github.com/spf13/cobra" 13 "os" 14 ) 15 16 func New{{.CommandName}}Cmd() *cobra.Command { 17 {{.CommandName}}Cmd := &cobra.Command{ 18 Use: "{{.CommandName}}", 19 Short: `A brief description of this command`, 20 Long: `A longer description about this command`, 21 Run: func(cmd *cobra.Command, args []string) { 22 // --- you actions here --- 23 } 24 } 25 26 // Here you will define your flags and configuration settings. 27 // Cobra supports persistent flags, which, if defined here, 28 // will be global for your application. 29 30 // {{.CommandName}}Cmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.test-corba-cli.yaml)") 31 32 // Cobra also supports local flags, which will only run 33 // when this action is called directly. 34 35 //{{.CommandName}}Cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 36 37 // MARK:Commands --- And Sub Commands Below --- 38 // <place_your_command_here> -- change this with your command to add sub command 39 // {{.CommandName}}Cmd.AddCommand(<place_your_command_here>) 40 41 return {{.CommandName}}Cmd 42 }