cmd.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority")
  35. Cmd.Flags().StringVar(&cli.VarStringRemote, "remote", "", "The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure")
  36. Cmd.Flags().StringVar(&cli.VarStringBranch, "branch", "", "The branch of the remote repo, it does work with --remote")
  37. newCmd.Flags().StringSliceVar(&cli.VarStringSliceGoOpt, "go_opt", nil, "")
  38. newCmd.Flags().StringSliceVar(&cli.VarStringSliceGoGRPCOpt, "go-grpc_opt", nil, "")
  39. newCmd.Flags().StringVar(&cli.VarStringStyle, "style", "gozero", "The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]")
  40. newCmd.Flags().BoolVar(&cli.VarBoolIdea, "idea", false, "Whether the command execution environment is from idea plugin.")
  41. newCmd.Flags().StringVar(&cli.VarStringHome, "home", "", "The goctl home path of the template, "+
  42. "--home and --remote cannot be set at the same time, if they are, --remote has higher priority")
  43. newCmd.Flags().StringVar(&cli.VarStringRemote, "remote", "", "The remote git repo of the template, "+
  44. "--home and --remote cannot be set at the same time, if they are, --remote has higher priority\n\tThe git repo "+
  45. "directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure")
  46. newCmd.Flags().StringVar(&cli.VarStringBranch, "branch", "", "The branch of the remote repo, it "+
  47. "does work with --remote")
  48. newCmd.Flags().BoolVarP(&cli.VarBoolVerbose, "verbose", "v", false, "Enable log output")
  49. newCmd.Flags().MarkHidden("go_opt")
  50. newCmd.Flags().MarkHidden("go-grpc_opt")
  51. protocCmd.Flags().StringSliceVar(&cli.VarStringSliceGoOut, "go_out", nil, "")
  52. protocCmd.Flags().StringSliceVar(&cli.VarStringSliceGoGRPCOut, "go-grpc_out", nil, "")
  53. protocCmd.Flags().StringSliceVar(&cli.VarStringSliceGoOpt, "go_opt", nil, "")
  54. protocCmd.Flags().StringSliceVar(&cli.VarStringSliceGoGRPCOpt, "go-grpc_opt", nil, "")
  55. protocCmd.Flags().StringSliceVar(&cli.VarStringSlicePlugin, "plugin", nil, "")
  56. protocCmd.Flags().StringSliceVarP(&cli.VarStringSliceProtoPath, "proto_path", "I", nil, "")
  57. protocCmd.Flags().StringVar(&cli.VarStringZRPCOut, "zrpc_out", "", "The zrpc output directory")
  58. protocCmd.Flags().StringVar(&cli.VarStringStyle, "style", "gozero", "The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]")
  59. protocCmd.Flags().StringVar(&cli.VarStringHome, "home", "", "The goctl home path of the template, "+
  60. "--home and --remote cannot be set at the same time, if they are, --remote has higher priority")
  61. protocCmd.Flags().StringVar(&cli.VarStringRemote, "remote", "", "The remote git repo of the template, "+
  62. "--home and --remote cannot be set at the same time, if they are, --remote has higher priority\n\tThe git repo "+
  63. "directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure")
  64. protocCmd.Flags().StringVar(&cli.VarStringBranch, "branch", "", "The branch of the remote repo, it "+
  65. "does work with --remote")
  66. protocCmd.Flags().BoolVarP(&cli.VarBoolVerbose, "verbose", "v", false, "Enable log output")
  67. protocCmd.Flags().MarkHidden("go_out")
  68. protocCmd.Flags().MarkHidden("go-grpc_out")
  69. protocCmd.Flags().MarkHidden("go_opt")
  70. protocCmd.Flags().MarkHidden("go-grpc_opt")
  71. protocCmd.Flags().MarkHidden("plugin")
  72. protocCmd.Flags().MarkHidden("proto_path")
  73. templateCmd.Flags().StringVar(&cli.VarStringOutput, "o", "", "Output a sample proto file")
  74. templateCmd.Flags().StringVar(&cli.VarStringHome, "home", "", "The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority")
  75. templateCmd.Flags().StringVar(&cli.VarStringRemote, "remote", "", "The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure")
  76. templateCmd.Flags().StringVar(&cli.VarStringBranch, "branch", "", "The branch of the remote repo, it does work with --remote")
  77. Cmd.AddCommand(newCmd)
  78. Cmd.AddCommand(protocCmd)
  79. Cmd.AddCommand(templateCmd)
  80. }