main.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "../include/batchioman.h"
  2. #include "../include/machineioman.h"
  3. #include "../include/userioman.h"
  4. #include <boost/program_options.hpp>
  5. #include <iostream>
  6. #include <string>
  7. namespace bpo = boost::program_options;
  8. /* this is provided for the readline callback in IoMan */
  9. IoMan *gIOMAN = NULL;
  10. void show_help(char *exec) {
  11. std::printf("ccats command line interface\n");
  12. std::printf("usage: %s [Options]\n", exec);
  13. }
  14. int main(int argc, char **argv) {
  15. bpo::options_description desc("Options");
  16. desc.add_options()("help", "show this help")("machine", "switch to machine mode for I/O (not designed for user interaction)")(
  17. "batch", bpo::value<std::string>(), "run operations from arg as batch file")("usessl", "enable ssl for connection to server")("verbose",
  18. "enable debug output");
  19. bpo::variables_map vm;
  20. bool machine = false, usessl = false, batch = false, verbose = false;
  21. const char *file = NULL;
  22. IoMan *ioman;
  23. try {
  24. store(parse_command_line(argc, argv, desc), vm);
  25. notify(vm);
  26. if (vm.count("help")) {
  27. show_help(argv[0]);
  28. std::cout << desc;
  29. return 1;
  30. }
  31. if (vm.count("machine")) {
  32. // enable machine/gui mode
  33. machine = true;
  34. }
  35. if (vm.count("batch")) {
  36. // handle batch file mode
  37. file = vm["batch"].as<std::string>().c_str();
  38. batch = true;
  39. }
  40. if (vm.count("usessl")) {
  41. usessl = true;
  42. }
  43. if (vm.count("verbose")) {
  44. verbose = true;
  45. }
  46. } catch (const bpo::error &ex) {
  47. std::fprintf(stderr, "%s\n", ex.what());
  48. }
  49. std::printf("machine mode is %d file is %s enablessl is %d verbose is %d\n", machine, file ? file : "", usessl, verbose);
  50. if (batch) {
  51. ioman = new BatchIoMan(usessl, verbose, file);
  52. } else if (machine) {
  53. ioman = new MachineIoMan(usessl, verbose);
  54. } else {
  55. ioman = new UserIoMan(usessl, verbose);
  56. }
  57. gIOMAN = ioman;
  58. if (ioman->init()) {
  59. ioman->run();
  60. }
  61. delete ioman;
  62. gIOMAN = NULL;
  63. std::printf("done\n");
  64. }