diff --git a/cli/lightning-cli.c b/cli/lightning-cli.c index c3a25afd14a0..68c13738fa74 100644 --- a/cli/lightning-cli.c +++ b/cli/lightning-cli.c @@ -49,6 +49,9 @@ static size_t human_readable(const char *buffer, const jsmntok_t *t, char term) i++; continue; } + } else if (buffer[i] == '|') { + fputc('\n', stdout); + continue; } fputc(buffer[i], stdout); } @@ -174,6 +177,13 @@ static int compare_help(const jsmntok_t *const *a, buffer); } +static void replace_char(char *buf, size_t len, char old, char new) +{ + char *p = buf, *end = buf + len; + while ((p = memchr(p, old, end - p)) != NULL) + *p = new; +} + static void human_help(char *buffer, const jsmntok_t *result) { unsigned int i; @@ -197,6 +207,8 @@ static void human_help(char *buffer, const jsmntok_t *result) for (i = 0; i < tal_count(help); i++) { const jsmntok_t *command; command = json_get_member(buffer, help[i], "command"); + replace_char(buffer + command->start, + command->end - command->start, '|', '\n'); printf("%.*s\n\n", command->end - command->start, buffer + command->start); } diff --git a/contrib/pyln-client/pyln/client/plugin.py b/contrib/pyln-client/pyln/client/plugin.py index 022a931852a0..ce2a136d57fc 100644 --- a/contrib/pyln-client/pyln/client/plugin.py +++ b/contrib/pyln-client/pyln/client/plugin.py @@ -84,7 +84,9 @@ def get_usage(self): args.append("[%s]" % arg) if self.description is not None: - args.append("\n%s" % self.description) + doc = inspect.getdoc(self.func) + doc = re.sub('\n+', ' | ', doc) + args.append(" | %s" % doc) return " ".join(args) @@ -938,16 +940,6 @@ def _getmanifest(self, **kwargs) -> JSONType: 'after': method.after}) continue - doc = inspect.getdoc(method.func) - if not doc: - self.log( - 'RPC method \'{}\' does not have a docstring.'.format( - method.name - ) - ) - doc = "Undocumented RPC method from a plugin." - doc = re.sub('\n+', ' ', doc) - # For compatibility with lightningd prior to 24.08, we must # provide a description. Ignored by 24.08 onwards, description = method.description