cli: fix human help output for the new jsonrpc help response
Now that we're returning all the help data, we need to update the human_help formatter to handle the extra data. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
d23a0e8adc
commit
8f405ca9a7
|
@ -89,22 +89,24 @@ static size_t human_readable(const char *buffer, const jsmntok_t *t, char term)
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void human_help(const char *buffer, const jsmntok_t *result) {
|
static void human_help(const char *buffer, const jsmntok_t *result, bool has_command) {
|
||||||
int i;
|
int i;
|
||||||
const jsmntok_t * help_array = result + 2;
|
const jsmntok_t * help_array = result + 2;
|
||||||
/* the first command object */
|
/* the first command object */
|
||||||
const jsmntok_t * curr = help_array + 1;
|
const jsmntok_t * curr = help_array + 1;
|
||||||
/* iterate through all commands, printing the name and description */
|
/* iterate through all commands, printing the name and description */
|
||||||
for (i = 0; i<help_array->size; i++) {
|
for (i = 0; i < help_array->size; i++) {
|
||||||
curr += 2;
|
curr += 2;
|
||||||
printf("%.*s\n", curr->end - curr->start, buffer + curr->start);
|
printf("%.*s\n", curr->end - curr->start, buffer + curr->start);
|
||||||
curr += 2;
|
curr += 2;
|
||||||
printf(" %.*s\n\n", curr->end - curr->start, buffer + curr->start);
|
printf(" %.*s\n\n", curr->end - curr->start, buffer + curr->start);
|
||||||
|
curr += 2;
|
||||||
/* advance to next command */
|
/* advance to next command */
|
||||||
curr++;
|
curr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("---\nrun `lightning-cli help <command>` for more information on a specific command\n");
|
if (!has_command)
|
||||||
|
printf("---\nrun `lightning-cli help <command>` for more information on a specific command\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
enum format {
|
enum format {
|
||||||
|
@ -363,9 +365,12 @@ int main(int argc, char *argv[])
|
||||||
json_tok_len(id), json_tok_contents(resp, id));
|
json_tok_len(id), json_tok_contents(resp, id));
|
||||||
|
|
||||||
if (!error || json_tok_is_null(resp, error)) {
|
if (!error || json_tok_is_null(resp, error)) {
|
||||||
|
// if we have specific help command
|
||||||
if (format == HUMAN)
|
if (format == HUMAN)
|
||||||
if (streq(method, "help")) human_help(resp, result);
|
if (streq(method, "help") && command == NULL)
|
||||||
else human_readable(resp, result, '\n');
|
human_help(resp, result, false);
|
||||||
|
else
|
||||||
|
human_readable(resp, result, '\n');
|
||||||
else
|
else
|
||||||
printf("%.*s\n",
|
printf("%.*s\n",
|
||||||
json_tok_len(result),
|
json_tok_len(result),
|
||||||
|
|
Loading…
Reference in New Issue