Example #1
0
def main(workspace_path: Path, sys_args: list):
    colorama_init()

    parser = create_parser()
    subparsers = parser.add_subparsers(dest="command", title="mygit tools")
    commands = create_commands(subparsers)
    namespace = parser.parse_args(sys_args)
    constants = Constants(workspace_path)
    state = State()

    log_handlers = ([
        logging.FileHandler(constants.mygit_log_path),
        logging.StreamHandler()
    ] if is_init(constants) else [logging.StreamHandler()])

    logging.basicConfig(level=logging.NOTSET,
                        format='%(message)s',
                        handlers=log_handlers)

    if namespace.command is None:
        logging.warning(Fore.YELLOW +
                        "write command or use 'mygit -h' for help")
    else:
        if is_init(constants):
            handle_command(commands, namespace, constants, state)
        elif namespace.command == "init":
            commands[namespace.command].work(namespace, constants, state)
        else:
            logging.warning(
                Fore.YELLOW +
                "directory doesn't contain a repository. Use 'mygit init' to create new one"
            )

    colorama_deinit()
Example #2
0
def get_current_state(c: Constants) -> State:
    state = State()
    state.load_cache(
        c,
        backend.get_compressed_file_content(c.mygit_index_path),
        backend.get_last_commit_index_content(c))

    backend.check_status(c, state)

    return state