diff options
Diffstat (limited to 'src/vgstash_cli.py')
-rw-r--r-- | src/vgstash_cli.py | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/src/vgstash_cli.py b/src/vgstash_cli.py index 9f5eef4..3d1d1db 100644 --- a/src/vgstash_cli.py +++ b/src/vgstash_cli.py @@ -4,9 +4,10 @@ import click import sys def get_db(): - """ - Convenience function to fetch a vgstash DB object from the default location. - """ + """Fetch a vgstash DB object from the default location. + + Change DEFAULT_CONFIG['db_location'] before calling this function + to alter behavior.""" return vgstash.DB(vgstash.DEFAULT_CONFIG['db_location']) @@ -24,6 +25,7 @@ def init(): else: raise sqlite3.OperationalError("Cannot create schema.") + @cli.command('add') @click.argument('title', type=str) @click.argument('system', type=str) @@ -49,16 +51,40 @@ def add(title, system, ownership, progress, notes): "have completed", ) note_clause = "" if len(game.notes) == 0 else " It also has notes." - click.echo("Added {} for {}. You {} it and {} it.{}".format(game.title, game.system, own_clause[game.ownership], progress_clause[game.progress], note_clause)) + click.echo("Added {} for {}. You {} it and {} it.{}".format( + game.title, + game.system, + own_clause[game.ownership], + progress_clause[game.progress], + note_clause, + )) except sqlite3.IntegrityError as e: print(e) click.echo("Couldn't add game.") @cli.command('list') -@click.argument('filter', required=False) -def list_games(filter="allgames"): +@click.argument('filter', required=False, default="allgames") +@click.option('--raw', '-r', is_flag=True, show_default=True, default=False, help="Output raw, pipe-delimited lines") +def list_games(filter, raw): db = get_db() res = db.list_games(filter) for r in res: - click.echo("{}|{}|{}|{}|{}".format(r['title'], r['system'], r['ownership'], r['progress'], r['notes'])) + if 'notes' in r.keys() and len(r['notes']) > 0: + notes = r['notes'].replace('\n', '\\n') + notes = notes.replace('\r', '\\r') + else: + notes = '' + + if raw: + click.echo("|".join(( + r['title'], + r['system'], + str(r['ownership']), + str(r['progress']), + notes + ) + )) + else: + pass + #pretty_print(r) |