apidoc: Add `-q` option for quiet mode (refs: #6772)

This commit is contained in:
Takeshi KOMIYA 2020-02-01 00:30:09 +09:00
parent b73cc5652a
commit aced2be1fb
3 changed files with 18 additions and 3 deletions

View File

@ -59,6 +59,7 @@ Features added
* SphinxTranslator now calls visitor/departure method for super node class if
visitor/departure method for original node class not found
* #6418: Add new event: :event:`object-description-transform`
* #6772: apidoc: Add ``-q`` option for quiet mode
Bugs fixed
----------

View File

@ -39,6 +39,11 @@ Options
Directory to place the output files. If it does not exist, it is created.
.. option:: -q
Do not output anything on standard output, only write warnings and errors to
standard error.
.. option:: -f, --force
Force overwriting of any existing generated files.

View File

@ -73,14 +73,19 @@ def module_join(*modnames: str) -> str:
def write_file(name: str, text: str, opts: Any) -> None:
"""Write the output file for module/package <name>."""
quiet = getattr(opts, 'quiet', None)
fname = path.join(opts.destdir, '%s.%s' % (name, opts.suffix))
if opts.dryrun:
print(__('Would create file %s.') % fname)
if not quiet:
print(__('Would create file %s.') % fname)
return
if not opts.force and path.isfile(fname):
print(__('File %s already exists, skipping.') % fname)
if not quiet:
print(__('File %s already exists, skipping.') % fname)
else:
print(__('Creating file %s.') % fname)
if not quiet:
print(__('Creating file %s.') % fname)
with FileAvoidWrite(fname) as f:
f.write(text)
@ -324,6 +329,8 @@ Note: By default this script will not overwrite already created files."""))
parser.add_argument('-o', '--output-dir', action='store', dest='destdir',
required=True,
help=__('directory to place all output'))
parser.add_argument('-q', action='store_true', dest='quiet',
help=__('no output on stdout, just warnings on stderr'))
parser.add_argument('-d', '--maxdepth', action='store', dest='maxdepth',
type=int, default=4,
help=__('maximum depth of submodules to show in the TOC '
@ -451,6 +458,8 @@ def main(argv: List[str] = sys.argv[1:]) -> int:
}
if args.extensions:
d['extensions'].extend(args.extensions)
if args.quiet:
d['quiet'] = True
for ext in d['extensions'][:]:
if ',' in ext: