Pretty-print dict with one list

This commit is contained in:
Bridget
2020-04-19 22:34:53 +02:00
parent ff08336d1e
commit 9a4c3bd44c

View File

@@ -61,6 +61,13 @@ class Shell(cmd.Cmd):
data[0][i] = f"\033[4m{Style.BRIGHT}{item}{Style.NORMAL}\033[0m"
return tabulate(data, headers="firstrow", tablefmt="plain")
elif isinstance(data, dict) and len(data.values()) == 1:
# Dict with one list; return a single column with header
header: str = next(iter(data.keys()))
values: list = next(iter(data.values()))
result = [f"\033[4m{Style.BRIGHT}{header}{Style.NORMAL}\033[0m"]
result.extend(values)
return "\n".join(result)
except TypeError:
pass