| 110 | } |
| 111 | |
| 112 | int cmd__parse_options(int argc, const char **argv) |
| 113 | { |
| 114 | const char *prefix = "prefix/"; |
| 115 | const char *usage[] = { |
| 116 | "test-tool parse-options <options>", |
| 117 | "", |
| 118 | "A helper function for the parse-options API.", |
| 119 | NULL |
| 120 | }; |
| 121 | struct string_list expect = STRING_LIST_INIT_NODUP; |
| 122 | struct string_list list = STRING_LIST_INIT_NODUP; |
| 123 | uint16_t u16 = 0; |
| 124 | int16_t i16 = 0; |
| 125 | |
| 126 | struct option options[] = { |
| 127 | OPT_BOOL(0, "yes", &boolean, "get a boolean"), |
| 128 | OPT_BOOL('D', "no-doubt", &boolean, "begins with 'no-'"), |
| 129 | { |
| 130 | .type = OPTION_SET_INT, |
| 131 | .short_name = 'B', |
| 132 | .long_name = "no-fear", |
| 133 | .value = &boolean, |
| 134 | .precision = sizeof(boolean), |
| 135 | .help = "be brave", |
| 136 | .flags = PARSE_OPT_NOARG | PARSE_OPT_NONEG, |
| 137 | .defval = 1, |
| 138 | }, |
| 139 | OPT_COUNTUP('b', "boolean", &boolean, "increment by one"), |
| 140 | OPT_BIT('4', "or4", &boolean, |
| 141 | "bitwise-or boolean with ...0100", 4), |
| 142 | OPT_NEGBIT(0, "neg-or4", &boolean, "same as --no-or4", 4), |
| 143 | OPT_GROUP(""), |
| 144 | OPT_INTEGER('i', "integer", &integer, "get a integer"), |
| 145 | OPT_INTEGER(0, "i16", &i16, "get a 16 bit integer"), |
| 146 | OPT_INTEGER('j', NULL, &integer, "get a integer, too"), |
| 147 | OPT_UNSIGNED('u', "unsigned", &unsigned_integer, "get an unsigned integer"), |
| 148 | OPT_UNSIGNED(0, "u16", &u16, "get a 16 bit unsigned integer"), |
| 149 | OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23), |
| 150 | OPT_CMDMODE(0, "mode1", &integer, "set integer to 1 (cmdmode option)", 1), |
| 151 | OPT_CMDMODE(0, "mode2", &integer, "set integer to 2 (cmdmode option)", 2), |
| 152 | { |
| 153 | .type = OPTION_CALLBACK, |
| 154 | .long_name = "mode34", |
| 155 | .value = &integer, |
| 156 | .precision = sizeof(integer), |
| 157 | .argh = "(3|4)", |
| 158 | .help = "set integer to 3 or 4 (cmdmode option)", |
| 159 | .flags = PARSE_OPT_CMDMODE, |
| 160 | .callback = mode34_callback, |
| 161 | }, |
| 162 | OPT_CALLBACK('L', "length", &integer, "str", |
| 163 | "get length of <str>", length_callback), |
| 164 | OPT_FILENAME('F', "file", &file, "set file to <file>"), |
| 165 | OPT_GROUP("String options"), |
| 166 | OPT_STRING('s', "string", &string, "string", "get a string"), |
| 167 | OPT_STRING(0, "string2", &string, "str", "get another string"), |
| 168 | OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"), |
| 169 | OPT_STRING('o', NULL, &string, "str", "get another string"), |
nothing calls this directly
no test coverage detected