diff --git a/sphinx/_cli/__init__.py b/sphinx/_cli/__init__.py index 8c305442de3..5569e68ae1c 100644 --- a/sphinx/_cli/__init__.py +++ b/sphinx/_cli/__init__.py @@ -52,7 +52,7 @@ class _SubcommandModule(Protocol): # Map of command name to import path. -_COMMANDS: dict[str, str] = {} +_COMMANDS: dict[str, str] = {'quickstart': 'sphinx.cmd._quickstart'} def _load_subcommand_descriptions() -> Iterator[tuple[str, str]]: diff --git a/sphinx/cmd/_quickstart.py b/sphinx/cmd/_quickstart.py new file mode 100644 index 00000000000..e9979cfa689 --- /dev/null +++ b/sphinx/cmd/_quickstart.py @@ -0,0 +1,24 @@ +"""The module implementing the subcommand ``sphinx quickstart``. + +This delegates everything to the module :mod:`sphinx.cmd.quickstart`, which +is the implementation for the historic standalone ``sphinx-quickstart`` command. +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +from . import quickstart + +if TYPE_CHECKING: + import argparse + +parser_description = quickstart.COMMAND_DESCRIPTION.lstrip() + + +def set_up_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser: + return quickstart.set_up_parser(parser) + + +def run(args: argparse.Namespace) -> int: + return quickstart.run(args) diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index a11856e497a..c85e460ed12 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -48,6 +48,15 @@ else: readline.parse_and_bind('tab: complete') +COMMAND_DESCRIPTION = __( + '\n' + 'Generate required files for a Sphinx project.\n' + '\n' + 'sphinx-quickstart is an interactive tool that asks some questions about your\n' + 'project and then generates a complete documentation directory and sample\n' + 'Makefile to be used with sphinx-build.\n', +) + EXTENSIONS = { 'autodoc': __('automatically insert docstrings from modules'), 'doctest': __('automatically test code snippets in doctest blocks'), @@ -569,20 +578,15 @@ def valid_dir(d: dict[str, Any]) -> bool: def get_parser() -> argparse.ArgumentParser: - description = __( - '\n' - 'Generate required files for a Sphinx project.\n' - '\n' - 'sphinx-quickstart is an interactive tool that asks some questions about your\n' - 'project and then generates a complete documentation directory and sample\n' - 'Makefile to be used with sphinx-build.\n', - ) parser = argparse.ArgumentParser( usage='%(prog)s [OPTIONS] ', epilog=__('For more information, visit .'), - description=description, + description=str(COMMAND_DESCRIPTION), # str() for resolving TranslationProxy ) + return set_up_parser(parser) + +def set_up_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser: parser.add_argument( '-q', '--quiet', @@ -748,6 +752,10 @@ def main(argv: Sequence[str] = (), /) -> int: except SystemExit as err: return err.code # type: ignore[return-value] + return run(args) + + +def run(args: argparse.Namespace) -> int: d = vars(args) # delete None or False value d = {k: v for k, v in d.items() if v is not None}