async def validate(verbose: bool, cwd: str, enabled: bool, current_branch: str,
                   color: bool, tty: bool, auto_fetch: bool,
                   commit_count_soft_fail_threshold: bool,
                   commit_count_hard_fail_threshold: bool,
                   commit_count_auto_bypass_soft_fail: bool):
    """Examine the current Git workspace and perform some sanity-checking"""
    cliOptions = ValidateCLIOptions(
        verbose=verbose,
        cwd=cwd,
        current_branch=current_branch,
        color=color,
        tty=tty,
        auto_fetch=auto_fetch,
        commit_count_soft_fail_threshold=commit_count_soft_fail_threshold,
        commit_count_hard_fail_threshold=commit_count_hard_fail_threshold,
        commit_count_auto_bypass_soft_fail=commit_count_auto_bypass_soft_fail)
    opts = ValidateOptions(cliOptions)
    log_level = DEBUG if opts.is_verbose() else INFO
    cli = CLIUX(log_level=log_level,
                supports_color=opts.is_terminal_color_supported(),
                supports_tty=opts.is_terminal_tty_supported())
    if (enabled == False):
        print(
            "skipping validation, due to '--no-enabled' CLI arg, or GIT_GUARDRAILS_ENABLED=False env variable"
        )
        return
    await do_validate(cli, opts)
def test_color_arg_infer():
    """
    absence of --color argument results in inference
    """
    o = ValidateOptions(ValidateCLIOptions())

    callback_invocation_count = 0

    def fake_color_detector() -> bool:
        nonlocal callback_invocation_count
        callback_invocation_count += 1
        return True

    def fake_no_color_detector() -> bool:
        nonlocal callback_invocation_count
        callback_invocation_count += 1
        return False

    assert callback_invocation_count == 0
    assert o.is_terminal_color_supported(fake_color_detector) == True
    assert callback_invocation_count == 1
    assert o.is_terminal_color_supported(fake_no_color_detector) == False
    assert callback_invocation_count == 2
def test_color_arg_passthrough():
    o1 = ValidateOptions(ValidateCLIOptions(color=True))
    assert o1.is_terminal_color_supported() == True, "--color passes through correctly in ValidateOptions (True)"
    o2 = ValidateOptions(ValidateCLIOptions(color=False))
    assert o2.is_terminal_color_supported() == False, "--color passes through correctly in ValidateOptions (False)"