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:
Doug Hellmann 2016-03-07 17:44:45 -05:00
parent 9cb8c4bf1b
commit c805665f6b
2 changed files with 13 additions and 5 deletions

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from reno import loader
from reno import scanner
from reno import utils
@ -62,10 +63,15 @@ def cache_cmd(args):
"Generates a release notes cache"
reporoot = args.reporoot.rstrip('/') + '/'
notesdir = utils.get_notes_dir(args)
if args.output:
stream = open(args.output, 'w')
else:
if args.output == '-':
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:
cache = build_cache_db(
reporoot=reporoot,
@ -83,6 +89,6 @@ def cache_cmd(args):
encoding='utf-8',
)
finally:
if args.output:
if close_stream:
stream.close()
return

View File

@ -127,7 +127,9 @@ def main(argv=sys.argv[1:]):
do_cache.add_argument(
'--output', '-o',
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)
do_cache.set_defaults(func=cache.cache_cmd)