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

Conversation

NishantBansal2003
Copy link

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, the doc variable in pyln/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:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes.
  • Documentation has been reviewed and updated as needed.
  • Related issues have been listed and linked, including any that this PR closes.

@rustyrussell rustyrussell added this to the v25.02 milestone Jan 22, 2025
Copy link
Contributor

@rustyrussell rustyrussell left a 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.

Comment on lines -87 to 92
args.append("\n%s" % self.description)
doc = inspect.getdoc(self.func)
doc = re.sub('\n+', ' | ', doc)
args.append(" | %s" % doc)

return " ".join(args)

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!

Comment on lines 200 to 214
printf("%.*s\n\n",
command->end - command->start, buffer + command->start);
human_readable(buffer, command, '\n');
printf("\n");
}
Copy link
Contributor

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.

Copy link
Author

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.

The `doc` variable was being initialised and processed but not used anywhere.
Changelog-None

Signed-off-by: Nishant Bansal <[email protected]>
Changelog-Changed: Replaced \n with | as the line separator
in the plugin to enhance the readability of lightning-cli help.

Signed-off-by: Nishant Bansal <[email protected]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatting Issue in description for external plugins in lightning-cli help
2 participants