mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
lightning-cli: support --filter parameter.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: cli: new `--filter` parameter to reduce JSON output.
This commit is contained in:
@@ -620,7 +620,7 @@ int main(int argc, char *argv[])
|
|||||||
enum input input = DEFAULT_INPUT;
|
enum input input = DEFAULT_INPUT;
|
||||||
enum log_level notification_level = LOG_INFORM;
|
enum log_level notification_level = LOG_INFORM;
|
||||||
bool last_was_progress = false;
|
bool last_was_progress = false;
|
||||||
char *command = NULL;
|
char *command = NULL, *filter = NULL;
|
||||||
|
|
||||||
err_set_progname(argv[0]);
|
err_set_progname(argv[0]);
|
||||||
jsmn_init(&parser);
|
jsmn_init(&parser);
|
||||||
@@ -650,6 +650,9 @@ int main(int argc, char *argv[])
|
|||||||
opt_register_arg("-N|--notifications", opt_set_level,
|
opt_register_arg("-N|--notifications", opt_set_level,
|
||||||
opt_show_level, ¬ification_level,
|
opt_show_level, ¬ification_level,
|
||||||
"Set notification level, or none");
|
"Set notification level, or none");
|
||||||
|
opt_register_arg("-l|--filter", opt_set_charp,
|
||||||
|
opt_show_charp, &filter,
|
||||||
|
"Set JSON reply filter");
|
||||||
|
|
||||||
opt_register_version();
|
opt_register_version();
|
||||||
|
|
||||||
@@ -713,8 +716,11 @@ int main(int argc, char *argv[])
|
|||||||
enable_notifications(fd);
|
enable_notifications(fd);
|
||||||
|
|
||||||
cmd = tal_fmt(ctx,
|
cmd = tal_fmt(ctx,
|
||||||
"{ \"jsonrpc\" : \"2.0\", \"method\" : \"%s\", \"id\" : \"%s\", \"params\" :",
|
"{ \"jsonrpc\" : \"2.0\", \"method\" : \"%s\", \"id\" : \"%s\",",
|
||||||
json_escape(ctx, method)->s, idstr);
|
json_escape(ctx, method)->s, idstr);
|
||||||
|
if (filter)
|
||||||
|
tal_append_fmt(&cmd, "\"filter\": %s,", filter);
|
||||||
|
tal_append_fmt(&cmd, " \"params\" :");
|
||||||
|
|
||||||
if (input == DEFAULT_INPUT) {
|
if (input == DEFAULT_INPUT) {
|
||||||
/* Hacky autodetect; only matters if more than single arg */
|
/* Hacky autodetect; only matters if more than single arg */
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ print out notifications of *LEVEL* or above (one of `io`, `debug`,
|
|||||||
`info` (the default), `unusual` or `broken`: they are prefixed with `#
|
`info` (the default), `unusual` or `broken`: they are prefixed with `#
|
||||||
`.
|
`.
|
||||||
|
|
||||||
|
* **--filter**/**-l**=*JSON*
|
||||||
|
|
||||||
|
This hands lightningd *JSON* as a filter, which controls what will be output, e.g. `'--filter={"help":[{"command":true}]}'`. See lightningd-rpc(7) for more details on how to specify filters.
|
||||||
|
|
||||||
* **--help**/**-h**
|
* **--help**/**-h**
|
||||||
|
|
||||||
Pretty-print summary of options to standard output and exit. The format can
|
Pretty-print summary of options to standard output and exit. The format can
|
||||||
|
|||||||
@@ -927,6 +927,16 @@ def test_cli(node_factory):
|
|||||||
j, _ = json.JSONDecoder().raw_decode(out)
|
j, _ = json.JSONDecoder().raw_decode(out)
|
||||||
assert 'help [command]' in j['help'][0]['verbose']
|
assert 'help [command]' in j['help'][0]['verbose']
|
||||||
|
|
||||||
|
# Test filtering
|
||||||
|
out = subprocess.check_output(['cli/lightning-cli',
|
||||||
|
'--network={}'.format(TEST_NETWORK),
|
||||||
|
'--lightning-dir={}'
|
||||||
|
.format(l1.daemon.lightning_dir),
|
||||||
|
'-J', '--filter={"help":[{"command":true}]}',
|
||||||
|
'help', 'help']).decode('utf-8')
|
||||||
|
j, _ = json.JSONDecoder().raw_decode(out)
|
||||||
|
assert j == {'help': [{'command': 'help [command]'}]}
|
||||||
|
|
||||||
# Test missing parameters.
|
# Test missing parameters.
|
||||||
try:
|
try:
|
||||||
# This will error due to missing parameters.
|
# This will error due to missing parameters.
|
||||||
|
|||||||
Reference in New Issue
Block a user