Skip to content

Commit b1fe851

Browse files
cli: improve help output formatting.
Changelog-Changed: Updated the `lightning-cli help` output by replacing '\n' with '|' as a line separator, enhancing readability and consistency. Signed-off-by: Nishant Bansal <[email protected]>
1 parent d561c72 commit b1fe851

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cli/lightning-cli.c

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ static size_t human_readable(const char *buffer, const jsmntok_t *t, char term)
4949
i++;
5050
continue;
5151
}
52+
} else if (buffer[i] == '|') {
53+
fputc('\n', stdout);
54+
continue;
5255
}
5356
fputc(buffer[i], stdout);
5457
}
@@ -174,6 +177,13 @@ static int compare_help(const jsmntok_t *const *a,
174177
buffer);
175178
}
176179

180+
static void replace_char(char *buf, size_t len, char old, char new)
181+
{
182+
char *p = buf, *end = buf + len;
183+
while ((p = memchr(p, old, end - p)) != NULL)
184+
*p = new;
185+
}
186+
177187
static void human_help(char *buffer, const jsmntok_t *result)
178188
{
179189
unsigned int i;
@@ -197,6 +207,8 @@ static void human_help(char *buffer, const jsmntok_t *result)
197207
for (i = 0; i < tal_count(help); i++) {
198208
const jsmntok_t *command;
199209
command = json_get_member(buffer, help[i], "command");
210+
replace_char(buffer + command->start,
211+
command->end - command->start, '|', '\n');
200212
printf("%.*s\n\n",
201213
command->end - command->start, buffer + command->start);
202214
}

0 commit comments

Comments
 (0)