aboutsummaryrefslogtreecommitdiff
path: root/src/vgstash_cli.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/vgstash_cli.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/vgstash_cli.py b/src/vgstash_cli.py
index 29c1de8..6289dba 100644
--- a/src/vgstash_cli.py
+++ b/src/vgstash_cli.py
@@ -2,8 +2,11 @@ import vgstash
import sqlite3
import click
import os
+import subprocess
import sys
+import tempfile
+# Click also has this, but it doesn't support a fallback value.
from shutil import get_terminal_size
def get_db():
@@ -164,3 +167,32 @@ def update_game(title, system, attr, val):
if db.update_game(target_game, updated_game):
click.echo("Updated {} for {}. Its {} is now {}.".format(title, system, attr, val))
pass
+
+
+@cli.command('notes')
+@click.argument('title', required=True)
+@click.argument('system', required=True)
+@click.option('--edit', '-e', is_flag=True, default=False)
+def notes(title, system, edit):
+ db = get_db()
+ target_game = db.get_game(title, system)
+ if edit:
+ with tempfile.NamedTemporaryFile() as tmpfile:
+ tmpfile.write(target_game.notes.encode("UTF-8"))
+ tmpfile.flush()
+ process = subprocess.run([os.getenv("EDITOR", "vim"), tmpfile.name])
+ tmpfile.flush()
+ tmpfile.seek(0)
+ note_arr = []
+ for line in tmpfile:
+ note_arr.append(line.decode("UTF-8").rstrip("\r\n"))
+ target_game.notes = "\n".join(note_arr)
+ db.update_game(target_game, target_game)
+ if process.returncode == 0:
+ click.echo("Notes for {} on {} have been updated!".format(target_game.title, target_game.system))
+ else:
+ click.echo("Couldn't find an editor for notes. Check the EDITOR environment variable and try again.")
+ else:
+ click.echo("Notes for {} on {}:".format(target_game.title, target_game.system))
+ click.echo()
+ click.echo(target_game.notes)
class='insertions'>+0 Sourcing them in .bash_profile screws up login if they're set. 2016-11-15Correct phrasing in README.Ze Libertine Gamer1-4/+4 2016-11-13DerpZe Libertine Gamer1-0/+1 2016-11-03Improve error handling in shell scriptsZe Libertine Gamer4-3/+23 2016-10-24Correct run_again, add recursionZe Libertine Gamer1-0/+4 Loops and functions -- oh my, what a useful combination. :) 2016-10-21Add quotes to correct behavior for arglistZe Libertine Gamer1-1/+1 2016-10-14updater.sh: add recursion, error handlingZe Libertine Gamer1-43/+101 2016-10-14Correct pipe-handling behaviorZe Libertine Gamer1-1/+9 2016-10-12Clarify a method to move between platformsZe Libertine Gamer1-2/+5 Also correct a typo.