diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/vgstash_cli.py | 17 |
1 files changed, 12 insertions, 5 deletions
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?") |