From c805665f6b661dcc8409cd27c7fc741e6fef31d6 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 7 Mar 2016 17:44:45 -0500 Subject: [PATCH] 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 --- reno/cache.py | 14 ++++++++++---- reno/main.py | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/reno/cache.py b/reno/cache.py index 5c8d923..f870c1b 100644 --- a/reno/cache.py +++ b/reno/cache.py @@ -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 diff --git a/reno/main.py b/reno/main.py index 248a25b..cba08ad 100644 --- a/reno/main.py +++ b/reno/main.py @@ -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)