From 269aecb4478c4ed6e15e1b155f259d978b178d2e Mon Sep 17 00:00:00 2001 From: zlg Date: Sat, 16 Oct 2021 18:33:48 -0700 Subject: vgstash_cli: 'export' with no filename prints to stdout ZLG-Bug: 6 --- src/vgstash_cli.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/vgstash_cli.py') diff --git a/src/vgstash_cli.py b/src/vgstash_cli.py index 7b9a9b4..29f6026 100755 --- a/src/vgstash_cli.py +++ b/src/vgstash_cli.py @@ -294,7 +294,6 @@ def import_file(format, filepath, update): resolve_path=True, dir_okay=False, file_okay=True), - default=sys.stdout, required=False, ) def export_file(format, filepath): @@ -317,14 +316,22 @@ def export_file(format, filepath): for field in game.keys(): g.update({field: game[field]}) game_set.append(g) - with open(filepath, "w") as fp: + if not filepath: if format == "yaml": - yaml.dump(game_set, fp, default_flow_style=False, + yaml.dump(game_set, sys.stdout, default_flow_style=False, indent=4, allow_unicode=True) if format == "json": - json.dump(game_set, fp, allow_nan=False, indent=1, skipkeys=True, sort_keys=True) + json.dump(game_set, sys.stdout, allow_nan=False, indent=1, skipkeys=True, sort_keys=True) + else: + with open(filepath, "w") as fp: + if format == "yaml": + yaml.dump(game_set, fp, default_flow_style=False, + indent=4, allow_unicode=True) + if format == "json": + json.dump(game_set, fp, allow_nan=False, indent=1, skipkeys=True, sort_keys=True) if len(game_set) > 0: - click.echo("Successfully exported {} games to {}.".format(len(game_set), filepath)) + if filepath: + click.echo("Successfully exported {} games to {}.".format(len(game_set), filepath)) else: click.echo("Could not export any games; have you made sure your collection has games in it?") -- cgit v1.2.3-54-g00ecf