diff --git a/src/jcloud_docsgen/cli/cli.py b/src/jcloud_docsgen/cli/cli.py index 7c7f43e..14c7e10 100644 --- a/src/jcloud_docsgen/cli/cli.py +++ b/src/jcloud_docsgen/cli/cli.py @@ -82,6 +82,15 @@ def create_argument_parser() -> argparse.ArgumentParser: default='docs/reference', help='the output directory the documentation will be written to', ) + common_parser.add_argument( + '-f', + '--force', + action='store_true', + help=( + 'generate documentation even if the output directory is not ' + 'empty. Warning: data can be lost when setting this flag.' + ), + ) argument_parser = argparse.ArgumentParser() @@ -151,6 +160,7 @@ def main(argv=None) -> int: exclude_sections=args.sections_exclude, allow_html=args.allow_html, allow_tables=args.allow_tables, + force=args.force, ) except FileNotFoundError as exc: return error(f'{exc.filename}: no such file or directory') diff --git a/src/jcloud_docsgen/cli/languages/python.py b/src/jcloud_docsgen/cli/languages/python.py index ae74fe9..c012e40 100644 --- a/src/jcloud_docsgen/cli/languages/python.py +++ b/src/jcloud_docsgen/cli/languages/python.py @@ -78,6 +78,7 @@ def _generate( ), allow_html: bool = False, allow_tables: bool = False, + force: bool = False, ) -> None: """ Generates the documentation for a Python project. @@ -94,6 +95,9 @@ def _generate( :type allow_html: bool :param allow_tables: Indicates whether Markdown tables are allowed. Warning: Markdown tables are not CommonMark. + :param force: Indicates whether the output directory shall be + overwritten if it is not empty. + :type force: bool """ docs_generator = PythonDocumentationGenerator( @@ -103,7 +107,7 @@ def _generate( allow_html=allow_html, allow_tables=allow_tables, ) - docs_generator.generate_documentation() + docs_generator.generate_documentation(force) def generate( @@ -114,6 +118,7 @@ def generate( exclude_sections: list[str] = [], allow_html: bool = False, allow_tables: bool = False, + force: bool = False, ) -> None: """ Generates the documentation for a Python project. @@ -133,6 +138,9 @@ def generate( :type allow_html: bool :param allow_tables: Indicates whether Markdown tables are allowed. Warning: Markdown tables are not CommonMark. + :param force: Indicates whether the output directory shall be + overwritten if it is not empty. + :type force: bool """ sections = parse_sections_list(include_sections, exclude_sections) @@ -143,4 +151,5 @@ def generate( include_sections=sections, allow_html=allow_html, allow_tables=allow_tables, + force=force, )