Skip to content
Merged
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ docstr-coverage some_project/src

#### Options

- _--output=\<type\>, -o \<type\>_ - Set the output target (default stdout)
- stdout - Output to standard STDOUT.
- file - Save output to file.
- _--format=\<type\>, -r \<type\>_ - Set output style (default text)
- text - Output in simple style.
- markdown - Output in Markdown notation.
- _--skip-magic, -m_ - Ignore all magic methods (except `__init__`)
- _--skip-init, -i_ - Ignore all `__init__` methods
- _--skip-file-doc, -f_ - Ignore module docstrings (at the top of files)
Expand Down
36 changes: 34 additions & 2 deletions docstr_coverage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from docstr_coverage.config_file import set_config_defaults
from docstr_coverage.coverage import analyze
from docstr_coverage.ignore_config import IgnoreConfig
from docstr_coverage.printers import LegacyPrinter
from docstr_coverage.printers import LegacyPrinter, MarkdownPrinter


def do_include_filepath(filepath: str, exclude_re: Optional["re.Pattern"]) -> bool:
Expand Down Expand Up @@ -261,6 +261,24 @@ def _assert_valid_key_value(k, v):
default=".docstr_coverage",
help="Deprecated. Use json config (--config / -C) instead",
)
@click.option(
"-o",
"--output",
type=click.Choice(["stdout", "file"]),
default="stdout",
help="Format of output",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really the "format" of the output (that comes from the --format option. Maybe output target/location/destination. I can't really think of the right word. But this option is used to specify "where" to save the output rather than how to format the output

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You right. I think the destination with combination of choices (stdout, file) clearly saying about param appointment.

Maby change --output to --destination?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good idea. I like --destination

show_default=True,
metavar="FORMAT",
)
@click.option(
"-r",
"--format",
type=click.Choice(["text", "markdown"]),
default="text",
help="Format of output",
show_default=True,
metavar="FORMAT",
)
def execute(paths, **kwargs):
"""Measure docstring coverage for `PATHS`"""

Expand Down Expand Up @@ -328,7 +346,21 @@ def execute(paths, **kwargs):
show_progress = not kwargs["percentage_only"]
results = analyze(all_paths, ignore_config=ignore_config, show_progress=show_progress)

LegacyPrinter(verbosity=kwargs["verbose"], ignore_config=ignore_config).print(results)
report_format: str = kwargs["format"]
if report_format == "markdown":
printer = MarkdownPrinter(results, verbosity=kwargs["verbose"], ignore_config=ignore_config)
elif report_format == "text":
printer = LegacyPrinter(results, verbosity=kwargs["verbose"], ignore_config=ignore_config)
else:
raise SystemError("Unknown report format: {0}".format(report_format))

output_type: str = kwargs["output"]
if output_type == "file":
printer.save_to_file()
elif output_type == "stdout":
printer.print_to_stdout()
else:
raise SystemError("Unknown output type: {0}".format(output_type))

file_results, total_results = results.to_legacy()

Expand Down
2 changes: 1 addition & 1 deletion docstr_coverage/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def get_docstring_coverage(
ignore_names=ignore_names,
)
results = analyze(filenames, ignore_config)
LegacyPrinter(verbosity=verbose, ignore_config=ignore_config).print(results)
LegacyPrinter(results, verbosity=verbose, ignore_config=ignore_config).print_to_stdout()
return results.to_legacy()


Expand Down
Loading