commands: Add --header and --update options to spack commands

The Spack documentation currently hard-codes some functionality in
`conf.py`, which makes the doc build less "pluggable" for things like
localized doc builds.

In particular, we unconditionally generate an index of commands and a
package list as part of the docs, but those should really only be done if
things are not up to date.

This commit does the following:

- Add `--header` option to `spack commands` so that it can do the work of
  prepending text to its output.

- Add `--update FILE` option to `spack commands` that makes it generate a
  new command index *only* if FILE is out of date w.r.t. commands in the
  Spack source.

- Simplify code in `conf.py` to use these options and only update the
  command index when needed.
This commit is contained in:
Todd Gamblin
2019-05-20 12:44:36 -07:00
parent 43aaf8c404
commit 6380f1917a
4 changed files with 143 additions and 54 deletions

View File

@@ -12,8 +12,9 @@
class ArgparseWriter(object):
"""Analyzes an argparse ArgumentParser for easy generation of help."""
def __init__(self):
def __init__(self, out=sys.stdout):
self.level = 0
self.out = out
def _write(self, parser, root=True, level=0):
self.parser = parser
@@ -148,8 +149,7 @@ def __init__(self, out=sys.stdout, rst_levels=_rst_levels,
strip_root_prog (bool): if ``True``, strip the base command name
from subcommands in output
"""
super(ArgparseWriter, self).__init__()
self.out = out
super(ArgparseRstWriter, self).__init__(out)
self.rst_levels = rst_levels
self.strip_root_prog = strip_root_prog