summaryrefslogtreecommitdiff
path: root/src/vgstash_cli.py
diff options
context:
space:
mode:
authorzlg <zlg@zlg.space>2018-09-03 02:52:57 -0700
committerzlg <zlg@zlg.space>2018-09-03 02:55:21 -0700
commit565812a92cd22d41aa6f5f85a6b451386422fb4a (patch)
tree5858923eb443465c078040c0e8cc13739290f195 /src/vgstash_cli.py
parentFlesh out filter types and ownership status (diff)
downloadvgstash-565812a92cd22d41aa6f5f85a6b451386422fb4a.tar.gz
vgstash-565812a92cd22d41aa6f5f85a6b451386422fb4a.tar.bz2
vgstash-565812a92cd22d41aa6f5f85a6b451386422fb4a.tar.xz
vgstash-565812a92cd22d41aa6f5f85a6b451386422fb4a.zip
Branch off from master with pytest, tox, click
This commit is huge, but contains everything needed for a "proper" build system built on pytest + tox and a CLI built with click. For now, this branch will contain all new vgstash development activity until it reaches feature parity with master. The CLI is installed to pip's PATH. Only the 'init', 'add', and 'list' commands work, with only two filters. This is pre-alpha software, and is therefore not stable yet.
Diffstat (limited to '')
-rw-r--r--src/vgstash_cli.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/vgstash_cli.py b/src/vgstash_cli.py
new file mode 100644
index 0000000..9f5eef4
--- /dev/null
+++ b/src/vgstash_cli.py
@@ -0,0 +1,64 @@
+import vgstash
+import sqlite3
+import click
+import sys
+
+def get_db():
+ """
+ Convenience function to fetch a vgstash DB object from the default location.
+ """
+ return vgstash.DB(vgstash.DEFAULT_CONFIG['db_location'])
+
+
+@click.group('vgstash')
+def cli():
+ pass
+
+
+@cli.command()
+def init():
+ db = get_db()
+ click.echo("Initializing the database...")
+ if db.create_schema():
+ click.echo("Schema created.")
+ else:
+ raise sqlite3.OperationalError("Cannot create schema.")
+
+@cli.command('add')
+@click.argument('title', type=str)
+@click.argument('system', type=str)
+@click.argument('ownership', type=str, required=False, default=vgstash.DEFAULT_CONFIG['ownership'])
+@click.argument('progress', type=str, required=False, default=vgstash.DEFAULT_CONFIG['progress'])
+@click.argument('notes', type=str, required=False, default="")
+def add(title, system, ownership, progress, notes):
+ db = get_db()
+ game = vgstash.Game(title, system, ownership, progress, notes)
+ try:
+ db.add_game(game, update=False)
+ own_clause = (
+ "do not own",
+ "physically own",
+ "digitally own",
+ "digitally and physically own",
+ )
+ progress_clause = (
+ "cannot beat",
+ "haven't started",
+ "are playing",
+ "have beaten",
+ "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))
+ 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"):
+ 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']))