Mentions légales du service

Skip to content
Snippets Groups Projects
agdbentures_cli.py 1.9 KiB
Newer Older
BAROLLET Theo's avatar
BAROLLET Theo committed
#!/usr/bin/python3

import sys
import os
import argparse
BAROLLET Theo's avatar
BAROLLET Theo committed

from lib.progress.progress_manager import progress
BAROLLET Theo's avatar
BAROLLET Theo committed

parser = argparse.ArgumentParser()
parser.add_argument("mode", choices=["start", "status", "check"])
parser.add_argument("level", nargs="?", default=None)
parser.add_argument("-i", "--input", required=False, default=None, dest="input_file")


args = parser.parse_args()

BAROLLET Theo's avatar
BAROLLET Theo committed

def color(msg: str, unlocked: bool, done: bool) -> str:
    if done:
        # green
        color = "\033[92m"
    elif unlocked:
        # yellow
        color = "\033[93m"
    else:
        # red
        color = "\033[91m"
    return f"{color} {msg}\033[00m"


def start():
    # check if there is progress file
    progress.reset_progress()
BAROLLET Theo's avatar
BAROLLET Theo committed
    print("Agdbentures progress started or restarted")


def check(level=None):
    print("check")

    input_file = args.input_file

    undone = progress.next_undone()
    if args.level is not None:
        checked = progress.check_level(level, input_file)
    elif len(undone) == 1:
        checked = progress.check_level(undone[0], input_file)
BAROLLET Theo's avatar
BAROLLET Theo committed
    else:
        print(
            "Error multiple levels are doable at this point see ./agdbentures_cli status"
        )
        print("You can specify the level to check with ./agdbentures check level_name")
        sys.exit(1)
BAROLLET Theo's avatar
BAROLLET Theo committed

    if checked == 0:
        print("Level success")
    else:
        print("Level failed")


def status():

    unlocked = True
    for progress in progress.progress:
BAROLLET Theo's avatar
BAROLLET Theo committed
        display_strings = [
            color(os.path.basename(level), unlocked, done)
BAROLLET Theo's avatar
BAROLLET Theo committed
            for level, done in zip(progress.levels, progress.dones)
        ]
        print(" ".join(display_strings))
        unlocked = unlocked and progress.all_done()
        # if not unlocked:
        #    return


if args.mode == "start":
BAROLLET Theo's avatar
BAROLLET Theo committed
    start()
elif args.mode == "check":
    check(args.level)
elif args.mode == "status":
BAROLLET Theo's avatar
BAROLLET Theo committed
    status()
else:
    # invalid arg
    help()