cmd.go 5.4 KB

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