main.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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", bpo::value<std::string>(),
  18. "enable ssl for connection to server")("verbose", "enable debug output");
  19. bpo::variables_map vm;
  20. bool machine = false, usessl = false, batch = false, verbose = false;
  21. const char *file = NULL;
  22. const char *certfile = NULL;
  23. IoMan *ioman;
  24. try {
  25. store(parse_command_line(argc, argv, desc), vm);
  26. notify(vm);
  27. if (vm.count("help")) {
  28. show_help(argv[0]);
  29. std::cout << desc;
  30. return 1;
  31. }
  32. if (vm.count("machine")) {
  33. // enable machine/gui mode
  34. machine = true;
  35. }
  36. if (vm.count("batch")) {
  37. // handle batch file mode
  38. file = vm["batch"].as<std::string>().c_str();
  39. batch = true;
  40. }
  41. if (vm.count("usessl")) {
  42. certfile = vm["usessl"].as<std::string>().c_str();
  43. usessl = true;
  44. }
  45. if (vm.count("verbose")) {
  46. verbose = true;
  47. }
  48. } catch (const bpo::error &ex) {
  49. std::cerr << ex.what() << std::endl;
  50. return 1;
  51. }
  52. std::printf("machine mode is %d file is %s enablessl is %d verbose is %d\n", machine, file ? file : "", usessl, verbose);
  53. if (batch) {
  54. ioman = new BatchIoMan(usessl, certfile, verbose, file);
  55. } else if (machine) {
  56. ioman = new MachineIoMan(usessl, certfile, verbose);
  57. } else {
  58. ioman = new UserIoMan(usessl, certfile, verbose);
  59. }
  60. gIOMAN = ioman;
  61. if (ioman->init()) {
  62. ioman->run();
  63. }
  64. delete ioman;
  65. gIOMAN = NULL;
  66. std::printf("done\n");
  67. return 0;
  68. }