summary refs log tree commit diff
path: root/litterbox.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-13 23:37:33 -0500
committerJune McEnroe <june@causal.agency>2019-12-13 23:37:33 -0500
commit5f96a227824fe85b815e01305630fbbeefbeb087 (patch)
treead8411444c8e6dd9e25e9b076323fa52a9b972a8 /litterbox.c
parentCompact matcher arrays a little (diff)
downloadlitterbox-5f96a227824fe85b815e01305630fbbeefbeb087.tar.gz
litterbox-5f96a227824fe85b815e01305630fbbeefbeb087.zip
Style cleanup
Diffstat (limited to 'litterbox.c')
-rw-r--r--litterbox.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/litterbox.c b/litterbox.c
index ca59df0..2fa52fb 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -25,12 +25,14 @@
 #include "database.h"
 
 int main(int argc, char *argv[]) {
+	char *path = NULL;
 	bool init = false;
 	bool migrate = false;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "im"))) {
+	while (0 < (opt = getopt(argc, argv, "d:im"))) {
 		switch (opt) {
+			break; case 'd': path = optarg;
 			break; case 'i': init = true;
 			break; case 'm': migrate = true;
 			break; default:  return EX_USAGE;
@@ -40,12 +42,7 @@ int main(int argc, char *argv[]) {
 	int flags = SQLITE_OPEN_READWRITE;
 	if (init) flags |= SQLITE_OPEN_CREATE;
 
-	sqlite3 *db;
-	if (optind < argc) {
-		db = dbOpen(argv[optind], flags);
-	} else {
-		db = dbFind(flags);
-	}
+	sqlite3 *db = (path ? dbOpen(path, flags) : dbFind(flags));
 	if (!db) errx(EX_NOINPUT, "database not found");
 
 	if (init) {
@@ -57,8 +54,7 @@ int main(int argc, char *argv[]) {
 		return EX_OK;
 	}
 
-	int version = dbVersion(db);
-	if (version != DatabaseVersion) {
-		errx(EX_CONFIG, "database needs migration");
+	if (dbVersion(db) != DatabaseVersion) {
+		errx(EX_CONFIG, "database out of date; migrate with -m");
 	}
 }