dockge-cli/dockge_cli/client/utils.py

45 lines
1.4 KiB
Python
Raw Normal View History

2024-07-03 18:36:22 +00:00
import argparse
2024-07-02 16:09:56 +00:00
from tabulate import tabulate
2024-07-03 18:36:22 +00:00
from ..models import StackStatus
2024-07-02 16:09:56 +00:00
2024-07-05 22:16:41 +00:00
def credential_parser_factory():
2024-07-05 14:05:35 +00:00
"""
Creates a new parser for login credentials
"""
2024-07-03 18:36:22 +00:00
credentialparser = argparse.ArgumentParser(
prog="login",
description="Subparser for login credentials provided by CI"
)
credentialparser.add_argument("--username", action="store", type=str, required=True)
credentialparser.add_argument("--password", action="store", type=str, required=True)
return credentialparser
2024-07-02 16:09:56 +00:00
def stack_formatter(stacks):
2024-07-05 14:05:35 +00:00
"""
Prints a given stack list formatted as a table
"""
2024-07-02 16:09:56 +00:00
if not stacks["ok"]:
raise RuntimeError("Stack GET didn't work")
table, headers = [], ["Stackname", "Status"]
for key, val in stacks["stackList"].items():
2024-07-05 22:16:41 +00:00
table.append([key, StackStatus(val['status']).name.lower()])
2024-07-02 16:09:56 +00:00
print(tabulate(table, headers=headers, tablefmt="github"), "\n")
def status_formatter(status):
2024-07-05 14:05:35 +00:00
"""
Prints the status for a given stack
"""
2024-07-02 16:09:56 +00:00
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-05 14:05:35 +00:00
"""
Prints a generic dockge message
"""
2024-07-02 16:09:56 +00:00
print(f"Is Ok? {'Yes' if status['ok'] else 'No'}")
print(f"Stack status: {status['msg']}")