#include "../include/machineioman.h" #include "../include/userioman.h" #include #include #include namespace bpo = boost::program_options; void show_help(char *exec) { std::printf("ccats command line interface\n"); std::printf("usage: %s IP [Options]\n", exec); std::printf("IP should be in the format \"xxx.xxx.xxx.xxx\"\n"); } int main(int argc, char **argv) { bpo::options_description desc{"Options"}; desc.add_options()("help", "show this help")( "machine", "switch to machine mode for I/O (not designed for user interaction)")( "batch", bpo::value(), "run operations from arg as batch file"); bpo::variables_map vm; unsigned int machine = 0; const char *file = NULL; IoMan *ioman; if (argc < 2 || !std::strncmp(argv[1], "--help", 6)) { show_help(argv[0]); std::cout << desc; return 1; } if (!isdigit(argv[1][0])) { std::printf("invalid ip\n"); show_help(argv[0]); std::cout << desc; return 1; } try { store(parse_command_line(argc - 1, argv + 1, desc), vm); notify(vm); if (vm.count("help")) { show_help(argv[0]); std::cout << desc; return 1; } if (vm.count("machine")) { // enable machine/gui mode machine = 1; } if (vm.count("batch")) { // handle batch file mode file = vm["batch"].as().c_str(); } } catch (const bpo::error &ex) { std::fprintf(stderr, "%s\n", ex.what()); } std::printf("ip %s machine mode is %d file is %s\n", argv[1], machine, file ? file : ""); if (machine) { ioman = new MachineIoMan(argv[1]); } else { ioman = new UserIoMan(argv[1]); } if (ioman->init()) { ioman->run(); } delete ioman; std::printf("done\n"); }