Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyln-client+cli: Fix formatting issues for plugin description in lightning-cli help #8022

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cli/lightning-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
14 changes: 3 additions & 11 deletions contrib/pyln-client/pyln/client/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Comment on lines -87 to 92
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in the next commit?

Also, the Changelog line for the first commit is unnecessary: this isn't a user-visible change!

Expand Down Expand Up @@ -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
Expand Down