Example #1
0
def shell(args: List[str] = None, error: bool = True):
    """Endpoint for console.

    Parse a command arguments, configuration files and run a checkers.
    """
    if args is None:
        args = sys.argv[1:]

    options = parse_options(args)
    setup_logger(options)
    LOGGER.info(options)

    # Install VSC hook
    if options.hook:
        from .hook import install_hook  # noqa

        for path in options.paths:
            return install_hook(path)

    if options.from_stdin and not options.paths:
        LOGGER.error("--from-stdin requires a filename")
        return sys.exit(1)

    errors = check_paths(
        options.paths,
        code=read_stdin() if options.from_stdin else None,
        options=options,
        rootdir=CURDIR,
    )
    display_errors(errors, options)

    if error:
        sys.exit(int(bool(errors)))

    return errors