Skip to content

Commit

Permalink
feat: add verbose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancheley authored and guilatrova committed Jul 30, 2021
1 parent 4cdb60a commit 95a34b6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/tryceratops/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
runner = Runner()
discovery = FileDiscovery()
interface = CliInterface(runner, discovery)
logger = logging.getLogger("tryceratops")


EXPERIMENTAL_FLAG_OPTION = dict(is_flag=True, help="Whether to enable experimental analyzers.")
Expand All @@ -22,16 +23,22 @@
type=click.Choice(CODE_CHOICES),
)
EXCLUDE_OPTION = dict(multiple=True, help="A dir to be excluded. e.g. -x tests/ -x fixtures/")
VERBOSE_OPTION = dict(is_flag=True, help="Will print more logging messages.")


@click.command()
@click.argument("dir", nargs=-1)
@click.option("--experimental", **EXPERIMENTAL_FLAG_OPTION)
@click.option("-i", "--ignore", **IGNORE_OPTION)
@click.option("-x", "--exclude", **EXCLUDE_OPTION)
@click.option("-v", "--verbose", **VERBOSE_OPTION)
@click.version_option(tryceratops.__version__)
def entrypoint(
dir: Tuple[str], experimental: bool, ignore: Tuple[str, ...], exclude: Tuple[str, ...]
dir: Tuple[str],
experimental: bool,
ignore: Tuple[str, ...],
exclude: Tuple[str, ...],
verbose: bool,
):
pyproj_config = load_config(dir)
if pyproj_config:
Expand All @@ -40,6 +47,10 @@ def entrypoint(
else:
global_filter = GlobalFilter(experimental, ignore, exclude)

if verbose:
logger = logging.getLogger("tryceratops")
logger.setLevel(logging.DEBUG)

parsed_files = list(discovery.parse_python_files(dir))
runner.analyze(parsed_files, global_filter)

Expand Down
19 changes: 18 additions & 1 deletion src/tryceratops/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"default": {
"format": "%(asctime)s:%(name)s:%(process)d:%(lineno)d " "%(levelname)s %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
}
},
"simple": {
"format": "%(message)s",
},
},
"handlers": {
"logfile": {
Expand All @@ -17,6 +20,20 @@
"formatter": "default",
"backupCount": 2,
},
"verbose_output": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "simple",
"stream": "ext://sys.stdout",
},
},
"loggers": {
"tryceratops": {
"level": "INFO",
"handlers": [
"verbose_output",
],
},
},
"root": {"level": "INFO", "handlers": ["logfile"]},
}

0 comments on commit 95a34b6

Please sign in to comment.