cmd.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package rpc
  2. import (
  3. "github.com/spf13/cobra"
  4. "github.com/zeromicro/go-zero/tools/goctl/rpc/cli"
  5. )
  6. var (
  7. // Cmd describes a rpc command.
  8. Cmd = &cobra.Command{
  9. Use: "rpc",
  10. Short: "Generate rpc code",
  11. RunE: func(cmd *cobra.Command, args []string) error {
  12. return cli.RPCTemplate(true)
  13. },
  14. }
  15. newCmd = &cobra.Command{
  16. Use: "new",
  17. Short: "Generate rpc demo service",
  18. Args: cobra.ExactValidArgs(1),
  19. RunE: cli.RPCNew,
  20. }
  21. templateCmd = &cobra.Command{
  22. Use: "template",
  23. Short: "Generate proto template",
  24. RunE: func(cmd *cobra.Command, args []string) error {
  25. return cli.RPCTemplate(false)
  26. },
  27. }
  28. protocCmd = &cobra.Command{
  29. Use: "protoc",
  30. Short: "Generate grpc code",
  31. Example: "goctl rpc protoc xx.proto --go_out=./pb --go-grpc_out=./pb --zrpc_out=.",
  32. Args: cobra.ExactValidArgs(1),
  33. RunE: cli.ZRPC,
  34. }
  35. )
  36. func init() {
  37. Cmd.Flags().StringVar(&cli.VarStringOutput, "o", "", "Output a sample proto file")
  38. Cmd.Flags().StringVar(&cli.VarStringHome, "home", "", "The goctl home path of "+
  39. "the template, --home and --remote cannot be set at the same time, if they are, --remote has"+
  40. " higher priority")
  41. Cmd.Flags().StringVar(&cli.VarStringRemote, "remote", "", "The remote git repo"+
  42. " of the template, --home and --remote cannot be set at the same time, if they are, --remote"+
  43. " has higher priority\n\tThe git repo directory must be consistent with the "+
  44. "https://github.com/zeromicro/go-zero-template directory structure")
  45. Cmd.Flags().StringVar(&cli.VarStringBranch, "branch", "", "The branch of the "+
  46. "remote repo, it does work with --remote")
  47. newCmd.Flags().StringSliceVar(&cli.VarStringSliceGoOpt, "go_opt", nil, "")
  48. newCmd.Flags().StringSliceVar(&cli.VarStringSliceGoGRPCOpt, "go-grpc_opt", nil, "")
  49. newCmd.Flags().StringVar(&cli.VarStringStyle, "style", "gozero", "The file "+
  50. "naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]")
  51. newCmd.Flags().BoolVar(&cli.VarBoolIdea, "idea", false, "Whether the command "+
  52. "execution environment is from idea plugin.")
  53. newCmd.Flags().StringVar(&cli.VarStringHome, "home", "", "The goctl home path "+
  54. "of the template, --home and --remote cannot be set at the same time, if they are, --remote "+
  55. "has higher priority")
  56. newCmd.Flags().StringVar(&cli.VarStringRemote, "remote", "", "The remote git "+
  57. "repo of the template, --home and --remote cannot be set at the same time, if they are, "+
  58. "--remote has higher priority\n\tThe git repo directory must be consistent with the "+
  59. "https://github.com/zeromicro/go-zero-template directory structure")
  60. newCmd.Flags().StringVar(&cli.VarStringBranch, "branch", "",
  61. "The branch of the remote repo, it does work with --remote")
  62. newCmd.Flags().BoolVarP(&cli.VarBoolVerbose, "verbose", "v", false, "Enable log output")
  63. newCmd.Flags().MarkHidden("go_opt")
  64. newCmd.Flags().MarkHidden("go-grpc_opt")
  65. protocCmd.Flags().BoolVarP(&cli.VarBoolMultiple, "multiple", "m", false,
  66. "Generated in multiple rpc service mode")
  67. protocCmd.Flags().StringSliceVar(&cli.VarStringSliceGoOut, "go_out", nil, "")
  68. protocCmd.Flags().StringSliceVar(&cli.VarStringSliceGoGRPCOut, "go-grpc_out", nil, "")
  69. protocCmd.Flags().StringSliceVar(&cli.VarStringSliceGoOpt, "go_opt", nil, "")
  70. protocCmd.Flags().StringSliceVar(&cli.VarStringSliceGoGRPCOpt, "go-grpc_opt", nil, "")
  71. protocCmd.Flags().StringSliceVar(&cli.VarStringSlicePlugin, "plugin", nil, "")
  72. protocCmd.Flags().StringSliceVarP(&cli.VarStringSliceProtoPath, "proto_path", "I", nil, "")
  73. protocCmd.Flags().StringVar(&cli.VarStringZRPCOut, "zrpc_out", "", "The zrpc output directory")
  74. protocCmd.Flags().StringVar(&cli.VarStringStyle, "style", "gozero", "The file "+
  75. "naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]")
  76. protocCmd.Flags().StringVar(&cli.VarStringHome, "home", "", "The goctl home "+
  77. "path of the template, --home and --remote cannot be set at the same time, if they are, "+
  78. "--remote has higher priority")
  79. protocCmd.Flags().StringVar(&cli.VarStringRemote, "remote", "", "The remote "+
  80. "git repo of the template, --home and --remote cannot be set at the same time, if they are, "+
  81. "--remote has higher priority\n\tThe git repo directory must be consistent with the "+
  82. "https://github.com/zeromicro/go-zero-template directory structure")
  83. protocCmd.Flags().StringVar(&cli.VarStringBranch, "branch", "",
  84. "The branch of the remote repo, it does work with --remote")
  85. protocCmd.Flags().BoolVarP(&cli.VarBoolVerbose, "verbose", "v", false, "Enable log output")
  86. protocCmd.Flags().MarkHidden("go_out")
  87. protocCmd.Flags().MarkHidden("go-grpc_out")
  88. protocCmd.Flags().MarkHidden("go_opt")
  89. protocCmd.Flags().MarkHidden("go-grpc_opt")
  90. protocCmd.Flags().MarkHidden("plugin")
  91. protocCmd.Flags().MarkHidden("proto_path")
  92. templateCmd.Flags().StringVar(&cli.VarStringOutput, "o", "", "Output a sample proto file")
  93. templateCmd.Flags().StringVar(&cli.VarStringHome, "home", "", "The goctl home"+
  94. " path of the template, --home and --remote cannot be set at the same time, if they are, "+
  95. "--remote has higher priority")
  96. templateCmd.Flags().StringVar(&cli.VarStringRemote, "remote", "", "The remote "+
  97. "git repo of the template, --home and --remote cannot be set at the same time, if they are, "+
  98. "--remote has higher priority\n\tThe git repo directory must be consistent with the "+
  99. "https://github.com/zeromicro/go-zero-template directory structure")
  100. templateCmd.Flags().StringVar(&cli.VarStringBranch, "branch", "", "The branch"+
  101. " of the remote repo, it does work with --remote")
  102. Cmd.AddCommand(newCmd)
  103. Cmd.AddCommand(protocCmd)
  104. Cmd.AddCommand(templateCmd)
  105. }