Skip to content
Merged
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
4 changes: 2 additions & 2 deletions cli/lightning-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,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");
printf("%.*s\n\n",
command->end - command->start, buffer + command->start);
human_readable(buffer, command, '\n');
printf("\n");
}
Comment on lines -200 to 202
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
Contributor 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.

tal_free(help);

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', '\n ', doc)
args.append(" \n %s" % doc)

return " ".join(args)

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
16 changes: 14 additions & 2 deletions lightningd/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1393,10 +1393,22 @@ static void setup_command_usage(struct lightningd *ld,
bool jsonrpc_command_add(struct jsonrpc *rpc, struct json_command *command,
const char *usage TAKES)
{
struct json_escape *esc;
const char *unescaped;

if (!command_add(rpc, command))
return false;
usage = tal_strdup(command, usage);
strmap_add(&rpc->usagemap, command->name, usage);

esc = json_escape_string_(tmpctx, usage, strlen(usage));
unescaped = json_escape_unescape(command, esc);
if (!unescaped)
unescaped = tal_strdup(command, usage);
else {
if (taken(usage))
tal_free(usage);
}

strmap_add(&rpc->usagemap, command->name, unescaped);
tal_add_destructor2(command, destroy_json_command, rpc);
return true;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/plugins/multiline-help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
from pyln.client import Plugin, Millisatoshi


plugin = Plugin()


@plugin.method("helpme")
def helpme(plugin, msat: Millisatoshi):
"""This is a message which consumes multiple lines and thus should
be well-formatted by lightning-cli help

"""
return {'help': msat}


plugin.run()
22 changes: 22 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,28 @@ def test_cli(node_factory):
assert [l for l in lines if not re.search(r'^help\[[0-9]*\].', l)] == ['format-hint=simple']


def test_cli_multiline_help(node_factory):
l1 = node_factory.get_node(options={'plugin': os.path.join(os.getcwd(), 'tests/plugins/multiline-help.py')})

out = subprocess.check_output(['cli/lightning-cli',
'--network={}'.format(TEST_NETWORK),
'--lightning-dir={}'
.format(l1.daemon.lightning_dir),
'help']).decode('utf-8')
assert ("helpme msat \n"
" This is a message which consumes multiple lines and thus should\n"
" be well-formatted by lightning-cli help\n" in out)

out = subprocess.check_output(['cli/lightning-cli',
'--network={}'.format(TEST_NETWORK),
'--lightning-dir={}'
.format(l1.daemon.lightning_dir),
'help', 'helpme']).decode('utf-8')
assert out == ("helpme msat \n"
" This is a message which consumes multiple lines and thus should\n"
" be well-formatted by lightning-cli help\n")


def test_cli_commando(node_factory):
l1, l2 = node_factory.line_graph(2, fundchannel=False,
opts={'log-level': 'io', 'allow-deprecated-apis': True})
Expand Down
Loading