void parse_cmd_line(int argc, char **argv, CmdLine &clp) { int opt = 0; const char* opt_string = "a:p:r:o:d:g:it:f:s:e:n:l:m:u:c:h"; struct option longopts[] = { {"serv_addr", 1, NULL, 'a'}, {"serv_port", 1, NULL, 'p'}, {"root_addr", 1, NULL, 'r'}, {"root_port", 1, NULL, 'o'}, {"merge_addr", 1, NULL, 'd'}, {"merge_port", 1, NULL, 'g'}, {"using_id", 0, NULL, 'i'}, {"table_start_version", 1, NULL, 't'}, {"schema_file", 1, NULL, 'f'}, {"prefix_start", 1, NULL, 's'}, {"prefix_end", 1, NULL, 'e'}, {"mutator_num", 1, NULL, 'n'}, {"suffix_length", 1, NULL, 'l'}, {"max_row", 1, NULL, 'm'}, {"max_suffix", 1, NULL, 'u'}, {"max_cell", 1, NULL, 'c'}, {"help", 0, NULL, 'h'}, {0, 0, 0, 0} }; while ((opt = getopt_long(argc, argv, opt_string, longopts, NULL)) != -1) { switch (opt) { case 'a': clp.serv_addr = optarg; break; case 'p': clp.serv_port = atoi(optarg); break; case 'r': clp.root_addr = optarg; break; case 'o': clp.root_port = atoi(optarg); break; case 'd': clp.merge_addr = optarg; break; case 'g': clp.merge_port = atoi(optarg); break; case 'i': clp.using_id = true; break; case 't': clp.table_start_version = atoi(optarg); break; case 'f': clp.schema_file = optarg; break; case 's': clp.prefix_start = atoi(optarg); break; case 'e': if (0 == strcmp("MAX", optarg)) { clp.prefix_end = INT32_MAX; } else { clp.prefix_end = atoi(optarg); } break; case 'n': if (0 == strcmp("MAX", optarg)) { clp.mutator_num = INT32_MAX; } else { clp.mutator_num = atoi(optarg); } break; case 'l': clp.suffix_length = atoi(optarg); break; case 'm': clp.max_row = atoi(optarg); break; case 'u': clp.max_suffix = atoi(optarg); break; case 'c': clp.max_cell = atoi(optarg); break; case 'h': default: print_usage(); exit(1); } } if (!clp.is_valid()) { print_usage(); exit(-1); } }
void parse_cmd_line(int argc, char **argv, CmdLine &clp) { int opt = 0; const char* opt_string = "a:p:r:o:it:f:s:l:c:kh"; struct option longopts[] = { {"serv_addr", 1, NULL, 'a'}, {"serv_port", 1, NULL, 'p'}, {"root_addr", 1, NULL, 'r'}, {"root_port", 1, NULL, 'o'}, {"using_id", 0, NULL, 'i'}, {"table_start_version", 1, NULL, 't'}, {"schema_file", 1, NULL, 'f'}, {"prefix_start", 1, NULL, 's'}, {"suffix_length", 1, NULL, 'l'}, {"max_cell", 1, NULL, 'c'}, {"check", 1, NULL, 'k'}, {"help", 0, NULL, 'h'}, {0, 0, 0, 0} }; while ((opt = getopt_long(argc, argv, opt_string, longopts, NULL)) != -1) { switch (opt) { case 'a': clp.serv_addr = optarg; break; case 'p': clp.serv_port = atoi(optarg); break; case 'r': clp.root_addr = optarg; break; case 'o': clp.root_port = atoi(optarg); break; case 'i': clp.using_id = true; break; case 't': clp.table_start_version = atol(optarg); break; case 'f': clp.schema_file = optarg; break; case 's': clp.prefix_start = atoi(optarg); break; case 'l': clp.suffix_length = atoi(optarg); break; case 'c': clp.max_cell = atoi(optarg); break; case 'k': clp.check = true; break; case 'h': default: print_usage(); exit(1); } } if (!clp.is_valid()) { print_usage(); exit(-1); } }