Skip to content

Commit

Permalink
reckless: accept json array arguments as input
Browse files Browse the repository at this point in the history
Changelog-Added: Reckless: accepts json array input for command targets
  • Loading branch information
endothermicdev committed Jul 30, 2024
1 parent b2e4876 commit be3f0fe
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tools/reckless
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,18 @@ def report_version() -> str:
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):
"""Make the option idempotent. This adds a secondary argument that doesn't
get reinitialized. The downside is it"""
Expand Down Expand Up @@ -1755,7 +1767,13 @@ if __name__ == '__main__':
args.func(args.targets)
sys.exit(0)
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:
log.add_result(args.func())

Expand Down

0 comments on commit be3f0fe

Please sign in to comment.