make the cache command write to a file by default
Compute the name of the file the loader is going to look for and write to that if no other output is given. Use '-' to write to stdout. Change-Id: I3f2cebb1c7a8e77cf8ed8d78c8ab85ccdd4ee325 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
9cb8c4bf1b
commit
c805665f6b
|
@ -10,6 +10,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from reno import loader
|
||||||
from reno import scanner
|
from reno import scanner
|
||||||
from reno import utils
|
from reno import utils
|
||||||
|
|
||||||
|
@ -62,10 +63,15 @@ def cache_cmd(args):
|
||||||
"Generates a release notes cache"
|
"Generates a release notes cache"
|
||||||
reporoot = args.reporoot.rstrip('/') + '/'
|
reporoot = args.reporoot.rstrip('/') + '/'
|
||||||
notesdir = utils.get_notes_dir(args)
|
notesdir = utils.get_notes_dir(args)
|
||||||
if args.output:
|
if args.output == '-':
|
||||||
stream = open(args.output, 'w')
|
|
||||||
else:
|
|
||||||
stream = sys.stdout
|
stream = sys.stdout
|
||||||
|
close_stream = False
|
||||||
|
elif args.output:
|
||||||
|
stream = open(args.output, 'w')
|
||||||
|
close_stream = True
|
||||||
|
else:
|
||||||
|
stream = open(loader.get_cache_filename(reporoot, notesdir), 'w')
|
||||||
|
close_stream = True
|
||||||
try:
|
try:
|
||||||
cache = build_cache_db(
|
cache = build_cache_db(
|
||||||
reporoot=reporoot,
|
reporoot=reporoot,
|
||||||
|
@ -83,6 +89,6 @@ def cache_cmd(args):
|
||||||
encoding='utf-8',
|
encoding='utf-8',
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
if args.output:
|
if close_stream:
|
||||||
stream.close()
|
stream.close()
|
||||||
return
|
return
|
||||||
|
|
|
@ -127,7 +127,9 @@ def main(argv=sys.argv[1:]):
|
||||||
do_cache.add_argument(
|
do_cache.add_argument(
|
||||||
'--output', '-o',
|
'--output', '-o',
|
||||||
default=None,
|
default=None,
|
||||||
help='output filename, defaults to stdout',
|
help=('output filename, '
|
||||||
|
'defaults to the cache file within the notesdir, '
|
||||||
|
'use "-" for stdout'),
|
||||||
)
|
)
|
||||||
_build_query_arg_group(do_cache)
|
_build_query_arg_group(do_cache)
|
||||||
do_cache.set_defaults(func=cache.cache_cmd)
|
do_cache.set_defaults(func=cache.cache_cmd)
|
||||||
|
|
Loading…
Reference in New Issue