2023-11-21 17:13:30 +00:00
|
|
|
import argparse
|
2024-02-02 05:04:30 +00:00
|
|
|
import logging
|
2023-11-21 17:13:30 +00:00
|
|
|
|
2024-01-20 09:11:52 +00:00
|
|
|
from clan_cli.clan_uri import ClanURI
|
2024-02-02 05:04:30 +00:00
|
|
|
from clan_cli.custom_logger import setup_logging
|
2024-01-20 09:11:52 +00:00
|
|
|
|
|
|
|
from clan_vm_manager.models.interfaces import ClanConfig
|
|
|
|
|
|
|
|
from .app import MainApplication
|
2023-11-21 17:13:30 +00:00
|
|
|
|
2024-02-02 05:04:30 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2023-11-21 17:13:30 +00:00
|
|
|
|
2023-11-23 13:37:05 +00:00
|
|
|
def main() -> None:
|
2023-11-23 12:56:25 +00:00
|
|
|
parser = argparse.ArgumentParser(description="clan-vm-manager")
|
2023-12-05 12:41:02 +00:00
|
|
|
|
2024-02-02 05:04:30 +00:00
|
|
|
parser.add_argument("--debug", action="store_true", help="enable debug mode")
|
|
|
|
|
2023-12-05 12:41:02 +00:00
|
|
|
# Add join subcommand
|
2023-12-04 18:23:35 +00:00
|
|
|
subparser = parser.add_subparsers(
|
|
|
|
title="command",
|
|
|
|
description="command to execute",
|
|
|
|
help="the command to execute",
|
|
|
|
)
|
|
|
|
register_join_parser(subparser.add_parser("join", help="join a clan"))
|
2023-12-05 12:41:02 +00:00
|
|
|
|
2023-12-08 10:56:27 +00:00
|
|
|
register_overview_parser(subparser.add_parser("overview", help="overview screen"))
|
|
|
|
|
2023-12-05 12:41:02 +00:00
|
|
|
# Executed when no command is given
|
2023-12-06 17:38:19 +00:00
|
|
|
parser.set_defaults(func=show_overview)
|
2023-11-23 13:37:05 +00:00
|
|
|
args = parser.parse_args()
|
2024-02-02 05:04:30 +00:00
|
|
|
|
|
|
|
if args.debug:
|
|
|
|
setup_logging("DEBUG", root_log_name=__name__.split(".")[0])
|
|
|
|
else:
|
|
|
|
setup_logging("INFO", root_log_name=__name__.split(".")[0])
|
|
|
|
|
|
|
|
log.debug("Debug logging enabled")
|
|
|
|
log.info("Info logging enabled")
|
|
|
|
|
2023-11-23 13:37:05 +00:00
|
|
|
args.func(args)
|
2024-01-20 09:11:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def show_join(args: argparse.Namespace) -> None:
|
|
|
|
app = MainApplication(
|
2024-01-20 12:15:25 +00:00
|
|
|
config=ClanConfig(url=args.clan_uri, initial_view="list"),
|
2024-01-20 09:11:52 +00:00
|
|
|
)
|
|
|
|
return app.run()
|
|
|
|
|
|
|
|
|
|
|
|
def register_join_parser(parser: argparse.ArgumentParser) -> None:
|
|
|
|
parser.add_argument("clan_uri", type=ClanURI, help="clan URI to join")
|
|
|
|
parser.set_defaults(func=show_join)
|
|
|
|
|
|
|
|
|
|
|
|
def show_overview(args: argparse.Namespace) -> None:
|
|
|
|
app = MainApplication(
|
|
|
|
config=ClanConfig(url=None, initial_view="list"),
|
|
|
|
)
|
|
|
|
return app.run()
|
|
|
|
|
|
|
|
|
|
|
|
def register_overview_parser(parser: argparse.ArgumentParser) -> None:
|
|
|
|
parser.set_defaults(func=show_overview)
|