feat(cli): add Python CLI handling

Added a subparser for Python documentation and a function to generate
Python documentation.
This commit is contained in:
jakob.scheid committed 2026-09-10 09:46:04 +02:00
1 parent 350f8f9941
commit bce073746e
3 files changed
+198 -2

No files matched your search

+65 -2
View File
@@ -22,6 +22,9 @@ __all__ = [
import argparse
import pathlib
from .parsers.python import VALID_SECTIONS as VALID_PYTHON_SECTIONS
_LANG_PYTHON = 'python'
def existing_directory(path: str) -> pathlib.Path:
_path = path
@@ -33,12 +36,72 @@ def existing_directory(path: str) -> pathlib.Path:
return path
def main() -> int:
common_parser = argparse.ArgumentParser(add_help = False)
common_parser.add_argument(
'project_directory',
type = existing_directory,
nargs = '?',
default = pathlib.Path('.'),
help = 'The directory of the project'
)
common_parser.add_argument(
'-o',
'--output-dir',
type = pathlib.Path,
help = 'the output directory the documentation will be written to'
)
argument_parser = argparse.ArgumentParser()
argument_parser.add_argument('project_directory', type = existing_directory, nargs = '?', default = pathlib.Path('.'), help = 'The directory of the project')
argument_parser.add_argument('-o', '--output-dir', type = pathlib.Path, help = 'the output directory the documentation will be written to')
subparsers = argument_parser.add_subparsers(dest = 'language', required = True)
python_parser = subparsers.add_parser(
_LANG_PYTHON,
parents = [common_parser],
help = 'generate documentation for Python project'
)
python_parser.add_argument(
'-s',
'--sections',
nargs = '+',
choices = VALID_PYTHON_SECTIONS,
help = 'the sections to be included in the documentation'
)
python_parser.add_argument(
'-S',
'--sections-exclude',
nargs = '+',
default = [],
choices = VALID_PYTHON_SECTIONS,
help = 'the sections to be excluded in the documentation. If a section shall be included AND excluded, it is excluded.'
)
python_parser.add_argument(
'-H',
'--allow-html',
action = 'store_true',
help = 'indicates whether HTML is allowed in the documentation. By default, HTML is disabled.'
)
python_parser.add_argument(
'-T',
'--allow-tables',
action = 'store_true',
help = 'indicates whether Markdown tables are allowed in the documentation. By default, Markdown tables are disabled. Warning: Markdown tables are not CommonMark.'
)
args = argument_parser.parse_args()
if args.output_dir is None:
args.output_dir = args.project_directory / 'docs/reference'
if args.language == _LANG_PYTHON:
from .parsers.python import generate
generate(
args.project_directory,
args.output_dir,
include_sections = args.sections,
exclude_sections = args.sections_exclude,
allow_html = args.allow_html,
allow_tables = args.allow_tables
)
return 0