srpc_ctl.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. Copyright (c) 2022 Sogou, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #include <stdio.h>
  14. #include "srpc_controller.h"
  15. static void usage(const char *name)
  16. {
  17. printf(COLOR_PINK"Description:\n"
  18. COLOR_PURPLE" Simple generator for building Workflow and SRPC projects.\n\n"
  19. COLOR_PINK"Usage:\n"
  20. COLOR_INFO" %s" COLOR_COMMAND " <COMMAND>"
  21. COLOR_INFO" <PROJECT_NAME>" COLOR_FLAG " [FLAGS]\n\n"
  22. COLOR_PINK"Available Commands:\n"
  23. COLOR_COMMAND" http"
  24. COLOR_WHITE" - create project with both client and server\n"
  25. COLOR_COMMAND" redis"
  26. COLOR_WHITE" - create project with both client and server\n"
  27. COLOR_COMMAND" rpc"
  28. COLOR_WHITE" - create project with both client and server\n"
  29. COLOR_COMMAND" api"
  30. COLOR_WHITE" - create protobuf or thrift IDL api\n"
  31. COLOR_COMMAND" proxy"
  32. COLOR_WHITE" - create proxy for some client and server protocol\n"
  33. COLOR_COMMAND" file"
  34. COLOR_WHITE" - create project with asynchronous file service\n"
  35. COLOR_COMMAND" compute"
  36. COLOR_WHITE" - create project with asynchronous computing service\n"
  37. COLOR_OFF, name);
  38. }
  39. int main(int argc, const char *argv[])
  40. {
  41. if (argc < 2)
  42. {
  43. usage(argv[0]);
  44. return 0;
  45. }
  46. CommandController *ctl;
  47. if (strcasecmp(argv[1], "http") == 0)
  48. {
  49. ctl = new HttpController;
  50. }
  51. else if (strcasecmp(argv[1], "redis") == 0)
  52. {
  53. ctl = new RedisController;
  54. }
  55. else if (strcasecmp(argv[1], "rpc") == 0)
  56. {
  57. ctl = new RPCController;
  58. }
  59. else if (strcasecmp(argv[1], "api") == 0)
  60. {
  61. ctl = new APIController;
  62. }
  63. else if (strcasecmp(argv[1], "proxy") == 0)
  64. {
  65. ctl = new ProxyController;
  66. }
  67. else if (strcasecmp(argv[1], "file") == 0)
  68. {
  69. ctl = new FileServiceController;
  70. }
  71. else if (strcasecmp(argv[1], "compute") == 0)
  72. {
  73. ctl = new ComputeController;
  74. }
  75. else
  76. {
  77. usage(argv[0]);
  78. return 0;
  79. }
  80. if (ctl->parse_args(argc, argv) == true)
  81. {
  82. if (ctl->dependencies_and_dir() == true)
  83. {
  84. if (ctl->copy_files() == true)
  85. ctl->print_success_info();
  86. }
  87. }
  88. else
  89. ctl->print_usage(argv[0]);
  90. delete ctl;
  91. return 0;
  92. }