fix: resolve CI linting and type checking issues
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
26
app/cmdparse/formatters.py
Normal file
26
app/cmdparse/formatters.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
"""Output formatting utilities."""
|
||||||
|
|
||||||
|
from typing import Any, Dict, List
|
||||||
|
import json
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
def format_data(data: List[Dict[str, Any]], format: str) -> str:
|
||||||
|
"""Format parsed data into the specified output format."""
|
||||||
|
if not data:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
if format == 'json':
|
||||||
|
return json.dumps(data, indent=2)
|
||||||
|
elif format == 'yaml':
|
||||||
|
return yaml.safe_dump(data, default_flow_style=False)
|
||||||
|
elif format == 'csv':
|
||||||
|
if not data:
|
||||||
|
return ''
|
||||||
|
headers = list(data[0].keys())
|
||||||
|
lines = [','.join(headers)]
|
||||||
|
for row in data:
|
||||||
|
lines.append(','.join(str(row.get(h, '')) for h in headers))
|
||||||
|
return '\n'.join(lines)
|
||||||
|
else:
|
||||||
|
return '\n'.join(str(row) for row in data)
|
||||||
Reference in New Issue
Block a user