mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
reckless: accept json array arguments as input
Changelog-Added: Reckless: accepts json array input for command targets
This commit is contained in:
parent
1ac6e25ffd
commit
4aef72648c
1 changed files with 19 additions and 1 deletions
|
@ -1588,6 +1588,18 @@ def report_version() -> str:
|
||||||
log.add_result(__VERSION__)
|
log.add_result(__VERSION__)
|
||||||
|
|
||||||
|
|
||||||
|
def unpack_json_arg(json_target: str) -> list:
|
||||||
|
"""validate json for any command line targets passes as a json array"""
|
||||||
|
try:
|
||||||
|
targets = json.loads(json_target)
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
return None
|
||||||
|
if isinstance(targets, list):
|
||||||
|
return targets
|
||||||
|
log.warning(f'input {target_list} is not a json array')
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class StoreIdempotent(argparse.Action):
|
class StoreIdempotent(argparse.Action):
|
||||||
"""Make the option idempotent. This adds a secondary argument that doesn't
|
"""Make the option idempotent. This adds a secondary argument that doesn't
|
||||||
get reinitialized. The downside is it"""
|
get reinitialized. The downside is it"""
|
||||||
|
@ -1762,7 +1774,13 @@ if __name__ == '__main__':
|
||||||
args.func(args.targets)
|
args.func(args.targets)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
for target in args.targets:
|
for target in args.targets:
|
||||||
log.add_result(args.func(target))
|
# Accept single item arguments, or a json array
|
||||||
|
target_list = unpack_json_arg(target)
|
||||||
|
if target_list:
|
||||||
|
for tar in target_list:
|
||||||
|
log.add_result(args.func(tar))
|
||||||
|
else:
|
||||||
|
log.add_result(args.func(target))
|
||||||
elif 'func' in args:
|
elif 'func' in args:
|
||||||
log.add_result(args.func())
|
log.add_result(args.func())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue