github.com/youminxue/odin@v0.0.0-20230216022911-c2c8b05d3a41/cmd/name.go (about) 1 package cmd 2 3 import ( 4 "github.com/spf13/cobra" 5 "github.com/youminxue/odin/cmd/internal/name" 6 ) 7 8 var file string 9 var strategy string 10 var omitempty bool 11 var form bool 12 13 // nameCmd updates json tag of struct fields 14 var nameCmd = &cobra.Command{ 15 Use: "name", 16 Short: "bulk add or update json tag of struct fields", 17 Long: ``, 18 Run: func(cmd *cobra.Command, args []string) { 19 n := name.Name{file, strategy, omitempty, form} 20 n.Exec() 21 }, 22 } 23 24 func init() { 25 rootCmd.AddCommand(nameCmd) 26 27 // Here you will define your flags and configuration settings. 28 29 // Cobra supports Persistent Flags which will work for this command 30 // and all subcommands, e.g.: 31 // nameCmd.PersistentFlags().String("foo", "", "A help for foo") 32 33 // Cobra supports local flags which will only run when this command 34 // is called directly, e.g.: 35 nameCmd.Flags().StringVarP(&file, "file", "f", "", "absolute path of dto file") 36 nameCmd.Flags().StringVarP(&strategy, "strategy", "s", "lowerCamel", `name of strategy, currently only support "lowerCamel" and "snake"`) 37 nameCmd.Flags().BoolVarP(&omitempty, "omitempty", "o", false, "whether omit empty value or not") 38 nameCmd.Flags().BoolVar(&form, "form", false, "whether need form tag for https://github.com/go-playground/form") 39 }