Spaces:
Runtime error
Runtime error
File size: 633 Bytes
69a6cef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import json
from typing import Mapping, Optional, List
def _yaml_recursive(data, segments: Optional[list] = None):
segments = list(segments or [])
if isinstance(data, Mapping):
for key, value in data.items():
yield from _yaml_recursive(value, [*segments, key])
elif isinstance(data, (list, tuple)):
for i, item in enumerate(data):
yield from _yaml_recursive(item, [*segments, i])
else:
key = '.'.join(map(str, segments))
value = json.dumps(data)
yield f'{key}={value}'
def data_to_cli_args(data) -> List[str]:
return list(_yaml_recursive(data))
|