mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
Improved display of lightning-cli help for humans
The display format is now:
command1
description1
command2
description2
.
.
.
This commit is contained in:
committed by
Christian Decker
parent
30faa6485a
commit
38e94e883f
@@ -93,6 +93,22 @@ 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) {
|
||||||
|
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; i<help_array->size; 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 {
|
enum format {
|
||||||
JSON,
|
JSON,
|
||||||
HUMAN,
|
HUMAN,
|
||||||
@@ -315,7 +331,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (!error || json_tok_is_null(resp, error)) {
|
if (!error || json_tok_is_null(resp, error)) {
|
||||||
if (format == HUMAN)
|
if (format == HUMAN)
|
||||||
human_readable(resp, result, '\n');
|
if (streq(method, "help")) human_help(resp, result);
|
||||||
|
else human_readable(resp, result, '\n');
|
||||||
else
|
else
|
||||||
printf("%.*s\n",
|
printf("%.*s\n",
|
||||||
json_tok_len(result),
|
json_tok_len(result),
|
||||||
|
|||||||
Reference in New Issue
Block a user