Skip to content

Commit 8075bbe

Browse files
reckless: add listconfig command
Requested by @ShahanaFarooqui while accessing reckless via rpc in order to find out where the plugins are installed and enabled.
1 parent 2a527f2 commit 8075bbe

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

tools/reckless

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,13 @@ class Logger:
9999

100100
def reply_json(self):
101101
"""json output to stdout with accumulated result."""
102-
if len(log.json_output["result"]) == 1 and \
103-
isinstance(log.json_output["result"][0], list):
104-
# unpack sources output
105-
log.json_output["result"] = log.json_output["result"][0]
102+
if len(log.json_output["result"]) == 1:
103+
if isinstance(log.json_output["result"][0], list):
104+
# unpack sources output
105+
log.json_output["result"] = log.json_output["result"][0]
106+
elif isinstance(log.json_output['result'][0], dict):
107+
# If result is only a single dict, unpack it from the result list
108+
log.json_output['result'] = log.json_output['result'][0]
106109
output = json.dumps(log.json_output, indent=3) + '\n'
107110
ratelimit_output(output)
108111

@@ -846,6 +849,8 @@ class RecklessConfig(Config):
846849
)
847850
Config.__init__(self, path=str(path), default_text=default_text)
848851
self.reckless_dir = Path(path).parent
852+
# Which lightning config needs to inherit the reckless config?
853+
self.lightning_conf = None
849854

850855

851856
class LightningBitcoinConfig(Config):
@@ -1817,6 +1822,7 @@ def load_config(reckless_dir: Union[str, None] = None,
18171822
reckless_abort('Error: could not load or create the network specific lightningd'
18181823
' config (default .lightning/bitcoin)')
18191824
net_conf.editConfigFile(f'include {reckless_conf.conf_fp}', None)
1825+
reckless_conf.lightning_conf = network_path
18201826
return reckless_conf
18211827

18221828

@@ -2118,6 +2124,31 @@ def available_plugins() -> list:
21182124
return candidates
21192125

21202126

2127+
def listconfig() -> dict:
2128+
"""Useful for checking options passed through the reckless-rpc."""
2129+
config = {}
2130+
2131+
log.info(f'requested lightning config: {LIGHTNING_CONFIG}')
2132+
config.update({'requested_lightning_conf': LIGHTNING_CONFIG})
2133+
2134+
log.info(f'lightning config in use: {RECKLESS_CONFIG.lightning_conf}')
2135+
config.update({'lightning_conf': str(RECKLESS_CONFIG.lightning_conf)})
2136+
2137+
log.info(f'lightning directory: {LIGHTNING_DIR}')
2138+
config.update({'lightning_dir': str(LIGHTNING_DIR)})
2139+
2140+
log.info(f'reckless directory: {RECKLESS_CONFIG.reckless_dir}')
2141+
config.update({'reckless_dir': str(RECKLESS_CONFIG.reckless_dir)})
2142+
2143+
log.info(f'network: {NETWORK}')
2144+
config.update({'network': NETWORK})
2145+
2146+
log.info(f'reckless version: {__VERSION__}')
2147+
config.update({'version': __VERSION__})
2148+
2149+
return config
2150+
2151+
21212152
def report_version() -> str:
21222153
"""return reckless version"""
21232154
log.info(__VERSION__)
@@ -2132,7 +2163,7 @@ def unpack_json_arg(json_target: str) -> list:
21322163
return None
21332164
if isinstance(targets, list):
21342165
return targets
2135-
log.warning(f'input {target_list} is not a json array')
2166+
log.warning(f'input {json_target} is not a json array')
21362167
return None
21372168

21382169

@@ -2231,10 +2262,12 @@ if __name__ == '__main__':
22312262
parser.add_argument('-V', '--version',
22322263
action=StoreTrueIdempotent, const=None,
22332264
help='print version and exit')
2265+
listconfig_cmd = cmd1.add_parser('listconfig', help='list options passed to reckless')
2266+
listconfig_cmd.set_defaults(func=listconfig)
22342267

22352268
all_parsers = [parser, install_cmd, uninstall_cmd, search_cmd, enable_cmd,
22362269
disable_cmd, list_parse, source_add, source_rem, help_cmd,
2237-
update, list_cmd, available_cmd]
2270+
update, list_cmd, available_cmd, listconfig_cmd]
22382271
for p in all_parsers:
22392272
# This default depends on the .lightning directory
22402273
p.add_argument('-d', '--reckless-dir', action=StoreIdempotent,

0 commit comments

Comments
 (0)