diff options
author | zlg <zlg@zlg.space> | 2021-10-16 18:33:48 -0700 |
---|---|---|
committer | zlg <zlg@zlg.space> | 2021-10-16 18:33:48 -0700 |
commit | 269aecb4478c4ed6e15e1b155f259d978b178d2e (patch) | |
tree | e0d6a9c06c2f37371dc9b81f62b4a234a4eb2202 /src | |
parent | vgstash: Support 'member' ownership status (diff) | |
download | vgstash-269aecb4478c4ed6e15e1b155f259d978b178d2e.tar.gz vgstash-269aecb4478c4ed6e15e1b155f259d978b178d2e.tar.bz2 vgstash-269aecb4478c4ed6e15e1b155f259d978b178d2e.tar.xz vgstash-269aecb4478c4ed6e15e1b155f259d978b178d2e.zip |
vgstash_cli: 'export' with no filename prints to stdout
ZLG-Bug: 6
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?") |