From 38e94e883f52701ca5ca7bc23bc72ff1b8fd9991 Mon Sep 17 00:00:00 2001 From: Mark Beckwith Date: Fri, 2 Mar 2018 08:00:45 -0800 Subject: [PATCH] Improved display of lightning-cli help for humans The display format is now: command1 description1 command2 description2 . . . --- cli/lightning-cli.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cli/lightning-cli.c b/cli/lightning-cli.c index 7d1f11fa3..996a93faa 100644 --- a/cli/lightning-cli.c +++ b/cli/lightning-cli.c @@ -93,6 +93,22 @@ static size_t human_readable(const char *buffer, const jsmntok_t *t, char term) abort(); } +static void human_help(const char *buffer, const jsmntok_t *result) { + int i; + const jsmntok_t * help_array = result + 2; + /* the first command object */ + const jsmntok_t * curr = help_array + 1; + /* iterate through all commands, printing the name and description */ + for (i = 0; isize; i++) { + curr += 2; + printf("%.*s\n", curr->end - curr->start, buffer + curr->start); + curr += 2; + printf(" %.*s\n\n", curr->end - curr->start, buffer + curr->start); + /* advance to next command */ + curr++; + } +} + enum format { JSON, HUMAN, @@ -315,7 +331,8 @@ int main(int argc, char *argv[]) if (!error || json_tok_is_null(resp, error)) { if (format == HUMAN) - human_readable(resp, result, '\n'); + if (streq(method, "help")) human_help(resp, result); + else human_readable(resp, result, '\n'); else printf("%.*s\n", json_tok_len(result),