jsonrpc: add verbose help for individual commands.

And beg for contributions!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-01-29 11:00:15 +10:30
committed by Christian Decker
parent 7f03e15e03
commit 27678dfe6a
2 changed files with 31 additions and 0 deletions

View File

@@ -289,8 +289,36 @@ static void json_help(struct command *cmd,
unsigned int i;
struct json_result *response = new_json_result(cmd);
struct json_command **cmdlist = get_cmdlist();
jsmntok_t *cmdtok;
if (!json_get_params(buffer, params, "?command", &cmdtok, NULL)) {
command_fail(cmd, "Invalid arguments");
return;
}
json_object_start(response, NULL);
if (cmdtok) {
for (i = 0; i < num_cmdlist; i++) {
if (json_tok_streq(buffer, cmdtok, cmdlist[i]->name)) {
if (!cmdlist[i]->verbose)
json_add_string(response,
"verbose",
"HELP! Please contribute"
" a description for this"
" command!");
else
json_add_string_escape(response,
"verbose",
cmdlist[i]->verbose);
goto done;
}
}
command_fail(cmd, "Unknown command '%.*s'",
cmdtok->end - cmdtok->start,
buffer + cmdtok->start);
return;
}
json_array_start(response, "help");
for (i = 0; i < num_cmdlist; i++) {
json_add_object(response,
@@ -301,6 +329,8 @@ static void json_help(struct command *cmd,
NULL);
}
json_array_end(response);
done:
json_object_end(response);
command_success(cmd, response);
}

View File

@@ -53,6 +53,7 @@ struct json_command {
const char *buffer, const jsmntok_t *params);
const char *description;
bool deprecated;
const char *verbose;
};
struct json_result *null_response(const tal_t *ctx);