MCPcopy Create free account
hub / github.com/ElementsProject/lightning / param_subcommand

Function param_subcommand

common/json_param.c:293–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

json_plugin_controlFunction · 0.85
json_devFunction · 0.85

Calls 7

param_addFunction · 0.85
tal_append_fmtFunction · 0.85
check_paramsFunction · 0.85
param_arrFunction · 0.85
command_usage_onlyFunction · 0.50
command_set_usageFunction · 0.50
command_failFunction · 0.50

Tested by

no test coverage detected