|
@@ -1,6 +1,9 @@
|
|
|
#include <boost/program_options.hpp>
|
|
|
#include <cctype>
|
|
|
#include <iostream>
|
|
|
+#include <string>
|
|
|
+
|
|
|
+#include <readline/readline.h>
|
|
|
|
|
|
#define COMMANDLEN 10
|
|
|
#define sizeofarr(a) (sizeof(a) / sizeof(a[0]))
|
|
@@ -62,61 +65,53 @@ COMMANDTYPES getCommand(char *str, unsigned int isshort) {
|
|
|
|
|
|
void show_help(char *exec) {
|
|
|
std::printf("ccats command line interface\n");
|
|
|
- std::printf("usage: %s COMMAND IP [Options]\n", exec);
|
|
|
- std::printf("available COMMANDs are:\n");
|
|
|
- for (int i = 0; i < sizeofarr(commands); i++) {
|
|
|
- std::printf("%10s - %s\n", commands[i].name, commands[i].desc);
|
|
|
- }
|
|
|
+ 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()("cooloption", "Cooloption to use with command FOON");
|
|
|
+ desc.add_options()("help", "show this help")
|
|
|
+ ("machine", "switch to machine mode for I/O (not designed for user interaction)")
|
|
|
+ ("batch", bpo::value<std::string>(), "run operations from arg as batch file");
|
|
|
+
|
|
|
bpo::variables_map vm;
|
|
|
-
|
|
|
- if (argc < 2) {
|
|
|
- show_help(argv[0]);
|
|
|
- exit(1);
|
|
|
- }
|
|
|
- COMMANDTYPES cmd = getCommand(argv[1], (strlen(argv[1]) == 1));
|
|
|
- switch (cmd) {
|
|
|
- case CMD_UNKNOWN:
|
|
|
- std::printf("unknown command\n");
|
|
|
- case CMD_HELP:
|
|
|
- show_help(argv[0]);
|
|
|
- std::cout << desc;
|
|
|
- exit(1);
|
|
|
+ unsigned int machine = 0;
|
|
|
+ const char *file = NULL;
|
|
|
+
|
|
|
+ if(argc < 2) {
|
|
|
+ show_help(argv[0]);
|
|
|
+ std::cout << desc;
|
|
|
+ return 1;
|
|
|
}
|
|
|
- if (argc < 3) {
|
|
|
- std::printf("not enough arguments\n");
|
|
|
- show_help(argv[0]);
|
|
|
- exit(1);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- switch (cmd) {
|
|
|
- case CMD_CONNECT:
|
|
|
- std::printf("connecting to %s\n", argv[2]);
|
|
|
- break;
|
|
|
- case CMD_DISCONNECT:
|
|
|
- std::printf("disconnecting from %s\n", argv[2]);
|
|
|
- break;
|
|
|
- default:
|
|
|
- std::printf("command %s not implemented\n", argv[1]);
|
|
|
- break;
|
|
|
+
|
|
|
+ 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 - 2, argv + 2, desc), vm);
|
|
|
+ store(parse_command_line(argc - 1, argv + 1, desc), vm);
|
|
|
notify(vm);
|
|
|
|
|
|
if (vm.count("help")) {
|
|
|
+ show_help(argv[0]);
|
|
|
std::cout << desc;
|
|
|
- } else {
|
|
|
- std::printf("no additional options\n");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ if (vm.count("machine")) {
|
|
|
+
|
|
|
+ machine = 1;
|
|
|
+ }
|
|
|
+ if (vm.count("batch")) {
|
|
|
+
|
|
|
+ file = vm["batch"].as<std::string>().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:"");
|
|
|
+ std::printf("read line %s\n", readline("fancprompt "));
|
|
|
}
|