예제 #1
0
def _interactive_check(*, use_color: bool) -> bool:
    def _quit() -> NoReturn:
        print('Goodbye!')
        raise SystemExit()

    while True:
        try:
            s = input(color.fmt(
                '***Looks good [y,n,s,q,?]? ',
                color.BLUE_B, use_color=use_color,
            ))
        except (EOFError, KeyboardInterrupt):
            _quit()

        s = s.strip().lower()
        if s in {'y', 'yes'}:
            return True
        elif s in {'n', 'no'}:
            return False
        elif s in {'s', 'shell'}:
            shell()
        elif s in {'q', 'quit'}:
            _quit()
        else:
            if s not in {'?', 'help'}:
                print(color.fmt(
                    f'Unexpected input: {s}', color.RED, use_color=use_color,
                ))
            print('y (yes): yes it looks good, commit and continue.')
            print('n (no): no, do not commit this repository.')
            print('s (shell): open an interactive shell in the repo.')
            print('q (quit, ^C): early exit from the autofixer.')
            print('? (help): show this help message.')
예제 #2
0
def repo_context(repo: str, *, use_color: bool) -> Generator[None, None, None]:
    print(color.fmt(f'***{repo}', color.TURQUOISE_H, use_color=use_color))
    try:
        remote = git.remote(repo)
        with tempfile.TemporaryDirectory() as tmpdir:
            run('git', 'clone', '--quiet', repo, tmpdir)
            with cwd(tmpdir):
                run('git', 'remote', 'set-url', 'origin', remote)
                run('git', 'fetch', '--prune', '--quiet')
                yield
    except Exception:
        print(color.fmt(f'***Errored', color.RED_H, use_color=use_color))
        traceback.print_exc()
예제 #3
0
def _interactive_check(*, use_color):
    def _quit():
        print('Goodbye!')
        raise SystemExit()

    while True:
        try:
            s = input(
                color.fmt(
                    '***Looks good [y,n,s,q,?]? ',
                    color.BLUE_B,
                    use_color=use_color,
                ))
        except (EOFError, KeyboardInterrupt):
            _quit()

        s = s.strip().lower()
        if s in {'y', 'yes'}:
            return True
        elif s in {'n', 'no'}:
            return False
        elif s in {'s', 'shell'}:
            print('Opening an interactive shell, type `exit` to continue.')
            print('Any modifications will be committed.')
            subprocess.call(os.environ.get('SHELL', 'bash'))
        elif s in {'q', 'quit'}:
            _quit()
        else:
            if s not in {'?', 'help'}:
                print(
                    color.fmt(
                        f'Unexpected input: {s}',
                        color.RED,
                        use_color=use_color,
                    ))
            print('y (yes): yes it looks good, commit and continue.')
            print('n (no): no, do not commit this repository.')
            print('s (shell): open an interactive shell in the repo.')
            print('q (quit, ^C): early exit from the autofixer.')
            print('? (help): show this help message.')
예제 #4
0
def test_fmt(use_color, expected):
    assert color.fmt('text', color.RED_H, use_color=use_color) == expected