-
Notifications
You must be signed in to change notification settings - Fork 913
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
base: master
Are you sure you want to change the base?
pyln-client+cli: Fix formatting issues for plugin description in lightning-cli help #8022
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea, I love it! Just need to make it specific to help output only, and fix commits a bit.
args.append("\n%s" % self.description) | ||
doc = inspect.getdoc(self.func) | ||
doc = re.sub('\n+', ' | ', doc) | ||
args.append(" | %s" % doc) | ||
|
||
return " ".join(args) | ||
|
There was a problem hiding this comment.
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!
printf("%.*s\n\n", | ||
command->end - command->start, buffer + command->start); | ||
human_readable(buffer, command, '\n'); | ||
printf("\n"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
human_readable() is used in other contexts, and this will break it. In particular, the summary plugin.
I think this replacement needs to occur inline:
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;
}
Then simply call replace_char(buffer + command->start, command->end - command_start, '|', '\n')
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done; however, this part:
else if (buffer[i] == '|') {
fputc('\n', stdout);
continue;
}
is necessary for formatting the help output in cases of commands like lightning-cli help funds
or lightning-cli help funds -H
for external plugins such as funds
.
90d9502
to
b1fe851
Compare
Hmm. In this case I think we have to use '\n' rather than abusing '|'. We now do this for plugin log messages, which makes it consistent. let me play... |
The `doc` variable was being initialised and processed but not used anywhere. Changelog-None Signed-off-by: Nishant Bansal <[email protected]>
Changelog-Changed: Interpret \n as the line separator in plugins to enhance the readability of lightning-cli help. Signed-off-by: Nishant Bansal <[email protected]> [ Modified to use \n not | --RR ]
So if they want a \n in usage, they can have it. Signed-off-by: Rusty Russell <[email protected]>
… us). Signed-off-by: Rusty Russell <[email protected]> Changelog-Changed: lightning-cli: `help` messages using new-lines is now printed properly, enhancing readability and consistency.
Signed-off-by: Rusty Russell <[email protected]>
b1fe851
to
69a4261
Compare
OK, how's that instead? More work, but closer to your original vision? |
I think this looks great. However, for output like the following, I’m not sure if we can do something about it: $ lightning-cli help funds -J
{
"help": [
{
"command": "funds [unit] \n Lists the total funds the lightning node owns off- and onchain in {unit}.\n {unit} can take the following values:\n s, satoshi, satoshis to depict satoshis\n b, bit, bits to depict bits\n m, milli, btc to depict milliBitcoin\n B, bitcoin, btc to depict Bitcoins\n When not using Satoshis (default) the comma values are rounded off."
}
],
"format-hint": "simple"
} $ lightning-cli help funds -R
{"help":[{"command":"funds [unit] \n Lists the total funds the lightning node owns off- and onchain in {unit}.\n {unit} can take the following values:\n s, satoshi, satoshis to depict satoshis\n b, bit, bits to depict bits\n m, milli, btc to depict milliBitcoin\n B, bitcoin, btc to depict Bitcoins\n When not using Satoshis (default) the comma values are rounded off."}],"format-hint":"simple"} $ lightning-cli help funds -F
help[0].command=funds [unit] \n Lists the total funds the lightning node owns off- and onchain in {unit}.\n {unit} can take the following values:\n s, satoshi, satoshis to depict satoshis\n b, bit, bits to depict bits\n m, milli, btc to depict milliBitcoin\n B, bitcoin, btc to depict Bitcoins\n When not using Satoshis (default) the comma values are rounded off.
format-hint=simple But for the most commonly used command, which is: $ lightning-cli help funds this output is great. |
Fixes: #8020
Improved formatting of plugin descriptions displayed in the
lightning-cli help
output: Previously, the descriptions contained unnecessary\n
characters when shown as a single line, which affected readability.Proposed Solution: Replace
\n
with|
as the line separator when output is displayed in a single line, for better clarity and consistency.Removed unused variables and related code from
pyln-client
: For example, thedoc
variable inpyln/client/plugin.py
was declared but never utilized, and related code was cleaned up to improve maintainability.Important
24.11 FREEZE NOVEMBER 7TH: Non-bugfix PRs not ready by this date will wait for 25.02.
Checklist
Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked: