dockge-cli/dockge_cli/components/utils.py

31 lines
1 KiB
Python
Raw Normal View History

2024-07-02 16:09:56 +00:00
from tabulate import tabulate
from ..models import commands, StackStatus
def display_help(extra_args):
if not extra_args:
print(f"{commands['help'].description}")
return
if len(extra_args) > 1:
raise ValueError("Invalid arguments for help command")
print(f"{commands[extra_args[0]].description}")
def stack_formatter(stacks):
if not stacks["ok"]:
raise RuntimeError("Stack GET didn't work")
table, headers = [], ["Stackname", "Status"]
for key, val in stacks["stackList"].items():
table.append([key, StackStatus(val['status']).name])
print(tabulate(table, headers=headers, tablefmt="github"), "\n")
def status_formatter(status):
print(f"Is Stack Ok? {'Yes' if status['ok'] else 'No'}")
headers = ["Container", "Status"]
table = [[k, v] for k, v in status["serviceStatusList"].items()]
print(tabulate(table, headers=headers, tablefmt="github"), "\n")
2024-07-02 19:45:56 +00:00
def generic_formatter(status):
2024-07-02 16:09:56 +00:00
print(f"Is Ok? {'Yes' if status['ok'] else 'No'}")
print(f"Stack status: {status['msg']}")