| 294 | } |
| 295 | |
| 296 | const char *param_subcommand(struct command *cmd, const char *buffer, |
| 297 | const jsmntok_t tokens[], |
| 298 | const char *name, ...) |
| 299 | { |
| 300 | va_list ap; |
| 301 | struct param *params = tal_arr(cmd, struct param, 0); |
| 302 | const char *arg, **names = tal_arr(tmpctx, const char *, 1); |
| 303 | const char *subcmd; |
| 304 | |
| 305 | param_add(¶ms, "subcommand", PARAM_REQUIRED, (void *)param_string, &subcmd); |
| 306 | names[0] = name; |
| 307 | va_start(ap, name); |
| 308 | while ((arg = va_arg(ap, const char *)) != NULL) |
| 309 | tal_arr_expand(&names, arg); |
| 310 | va_end(ap); |
| 311 | |
| 312 | if (command_usage_only(cmd)) { |
| 313 | char *usage = tal_strdup(cmd, "subcommand"); |
| 314 | for (size_t i = 0; i < tal_count(names); i++) |
| 315 | tal_append_fmt(&usage, "%c%s", |
| 316 | i == 0 ? '=' : '|', names[i]); |
| 317 | command_set_usage(cmd, usage); |
| 318 | return NULL; |
| 319 | } |
| 320 | |
| 321 | /* Check it's valid */ |
| 322 | if (param_arr(cmd, buffer, tokens, params, true) != NULL) { |
| 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | /* Check it's one of the known ones. */ |
| 327 | for (size_t i = 0; i < tal_count(names); i++) |
| 328 | if (streq(subcmd, names[i])) |
| 329 | return subcmd; |
| 330 | |
| 331 | /* We really do ignore this. */ |
| 332 | struct command_result *ignore; |
| 333 | ignore = command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 334 | "Unknown subcommand '%s'", subcmd); |
| 335 | assert(ignore); |
| 336 | return NULL; |
| 337 | } |
| 338 | |
| 339 | bool param(struct command *cmd, const char *buffer, |
| 340 | const jsmntok_t tokens[], ...) |
nothing calls this directly
no test coverage detected