From ac3e84c9438ef964a08f2acf40ab58fe1c04675e Mon Sep 17 00:00:00 2001 From: zlg Date: Tue, 9 Oct 2018 04:33:52 -0700 Subject: cli: add 'update' command Two helper functions were also added to the vgstash package to ease client workflows. This commit marks the final core function necessary to manipulate a vgstash DB on the command line. --- src/vgstash_cli.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/vgstash_cli.py') diff --git a/src/vgstash_cli.py b/src/vgstash_cli.py index f88187c..29c1de8 100644 --- a/src/vgstash_cli.py +++ b/src/vgstash_cli.py @@ -40,7 +40,7 @@ def row_format(row, width, header): # progress (9) twidth = int(width) - 29 if header == True: - click.echo("{:<{w}s} | {:<8s} | {:^3s} | {:<9s}".format( + click.echo("{:<{w}s} | {:<8s} | {:^3s} | {}".format( "Title", "System", "Own", @@ -61,7 +61,7 @@ def row_format(row, width, header): 3: 'B', 4: 'C' } - progstr = "{: <7s}".format((" " * row['progress'] * 2) + progltr[row['progress']]) + progstr = "{}".format((" " * (row['progress'] - 1) * 2) + progltr[row['progress']]) print(" | ".join((titlestr, systemstr, ownstr, progstr))) @@ -139,3 +139,28 @@ def delete_game(title, system): target_game = vgstash.Game(title, system) if db.delete_game(target_game): click.echo("Removed {} for {} from your collection.".format(title, system)) + + +@cli.command('update') +@click.argument('title', required=True) +@click.argument('system', required=True) +@click.argument('attr', type=click.Choice(['title', 'system', 'ownership', 'progress']), required=True) +@click.argument('val', required=True) +def update_game(title, system, attr, val): + # TODO: Consider namedtuple as a solution + db = get_db() + target_game = db.get_game(title, system) + if attr == 'ownership': + val = vgstash.vtok(val, vgstash.OWNERSHIP) + if attr == 'progress': + val = vgstash.vtok(val, vgstash.PROGRESS) + updated_game = vgstash.Game( + val if attr == 'title' else target_game.title, + val if attr == 'system' else target_game.system, + val if attr == 'ownership' else target_game.ownership, + val if attr == 'progress' else target_game.progress, + target_game.notes + ) + if db.update_game(target_game, updated_game): + click.echo("Updated {} for {}. Its {} is now {}.".format(title, system, attr, val)) + pass -- cgit v1.2.3-54-g00ecf