cmd.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package tpl
  2. import (
  3. "github.com/spf13/cobra"
  4. )
  5. var (
  6. varStringHome string
  7. varStringCategory string
  8. varStringName string
  9. // Cmd describes a template command.
  10. Cmd = &cobra.Command{
  11. Use: "template",
  12. Short: "Template operation",
  13. }
  14. initCmd = &cobra.Command{
  15. Use: "init",
  16. Short: "Initialize the all templates(force update)",
  17. RunE: genTemplates,
  18. }
  19. cleanCmd = &cobra.Command{
  20. Use: "clean",
  21. Short: "Clean the all cache templates",
  22. RunE: cleanTemplates,
  23. }
  24. updateCmd = &cobra.Command{
  25. Use: "update",
  26. Short: "Update template of the target category to the latest",
  27. RunE: updateTemplates,
  28. }
  29. revertCmd = &cobra.Command{
  30. Use: "revert",
  31. Short: "Revert the target template to the latest",
  32. RunE: revertTemplates,
  33. }
  34. )
  35. func init() {
  36. initCmd.Flags().StringVar(&varStringHome, "home", "", "The goctl home path of the template")
  37. cleanCmd.Flags().StringVar(&varStringHome, "home", "", "The goctl home path of the template")
  38. updateCmd.Flags().StringVar(&varStringHome, "home", "", "The goctl home path of the template")
  39. updateCmd.Flags().StringVarP(&varStringCategory, "category", "c", "", "The category of template, enum [api,rpc,model,docker,kube]")
  40. revertCmd.Flags().StringVar(&varStringHome, "home", "", "The goctl home path of the template")
  41. revertCmd.Flags().StringVarP(&varStringCategory, "category", "c", "", "The category of template, enum [api,rpc,model,docker,kube]")
  42. revertCmd.Flags().StringVarP(&varStringName, "name", "n", "", "The target file name of template")
  43. Cmd.AddCommand(cleanCmd)
  44. Cmd.AddCommand(initCmd)
  45. Cmd.AddCommand(revertCmd)
  46. Cmd.AddCommand(updateCmd)
  47. }