Skip to content

Commit a86a1ba

Browse files
committed
ENH: Implement sphinx quickstart subcommand
`sphinx quickstart` is now equivalent to `sphinx-quickstart` A first step towards sphinx-doc#5618.
1 parent de745a9 commit a86a1ba

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

sphinx/_cli/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class _SubcommandModule(Protocol):
5252

5353

5454
# Map of command name to import path.
55-
_COMMANDS: dict[str, str] = {}
55+
_COMMANDS: dict[str, str] = {
56+
"quickstart": "sphinx.cmd._quickstart"
57+
}
5658

5759

5860
def _load_subcommand_descriptions() -> Iterator[tuple[str, str]]:

sphinx/cmd/_quickstart.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
The module implementing the subcommand ``sphinx quickstart``.
3+
4+
This delegates everything to the module :mod:`sphinx.cmd.quickstart`, which
5+
is the implementation for the historic standalone ``sphinx-quickstart`` command.
6+
"""
7+
8+
import argparse
9+
10+
from . import quickstart
11+
12+
13+
parser_description = quickstart.COMMAND_DESCRIPTION.lstrip()
14+
15+
16+
def set_up_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
17+
return quickstart.set_up_parser(parser)
18+
19+
20+
def run(args: argparse.Namespace) -> int:
21+
return quickstart.run(args)

sphinx/cmd/quickstart.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@
4848
else:
4949
readline.parse_and_bind('tab: complete')
5050

51+
COMMAND_DESCRIPTION = __(
52+
'\n'
53+
'Generate required files for a Sphinx project.\n'
54+
'\n'
55+
'sphinx-quickstart is an interactive tool that asks some questions about your\n'
56+
'project and then generates a complete documentation directory and sample\n'
57+
'Makefile to be used with sphinx-build.\n',
58+
)
59+
5160
EXTENSIONS = {
5261
'autodoc': __('automatically insert docstrings from modules'),
5362
'doctest': __('automatically test code snippets in doctest blocks'),
@@ -569,20 +578,14 @@ def valid_dir(d: dict[str, Any]) -> bool:
569578

570579

571580
def get_parser() -> argparse.ArgumentParser:
572-
description = __(
573-
'\n'
574-
'Generate required files for a Sphinx project.\n'
575-
'\n'
576-
'sphinx-quickstart is an interactive tool that asks some questions about your\n'
577-
'project and then generates a complete documentation directory and sample\n'
578-
'Makefile to be used with sphinx-build.\n',
579-
)
580581
parser = argparse.ArgumentParser(
581582
usage='%(prog)s [OPTIONS] <PROJECT_DIR>',
582583
epilog=__('For more information, visit <https://www.sphinx-doc.org/>.'),
583-
description=description,
584+
description=COMMAND_DESCRIPTION,
584585
)
586+
return set_up_parser(parser)
585587

588+
def set_up_parser(parser: argparse.ArgumentParser) -> None:
586589
parser.add_argument(
587590
'-q',
588591
'--quiet',
@@ -748,6 +751,10 @@ def main(argv: Sequence[str] = (), /) -> int:
748751
except SystemExit as err:
749752
return err.code # type: ignore[return-value]
750753

754+
return run(args)
755+
756+
757+
def run(args: Namespace) -> int:
751758
d = vars(args)
752759
# delete None or False value
753760
d = {k: v for k, v in d.items() if v is not None}

0 commit comments

Comments
 (0)