summary refs log tree commit diff
path: root/unscoop.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--unscoop.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/unscoop.c b/unscoop.c
index 6e7b362..eabb594 100644
--- a/unscoop.c
+++ b/unscoop.c
@@ -299,24 +299,33 @@ static void dedupEvents(sqlite3 *db) {
 }
 
 int main(int argc, char *argv[]) {
+	bool test = false;
 	char *path = NULL;
 	bool dedup = false;
 	const char *network = NULL;
 	const char *context = NULL;
 	const struct Format *format = &Formats[0];
 
-	for (int opt; 0 < (opt = getopt(argc, argv, "DN:c:d:f:v"));) {
+	for (int opt; 0 < (opt = getopt(argc, argv, "DN:c:d:f:nv"));) {
 		switch (opt) {
 			break; case 'D': dedup = true;
 			break; case 'N': network = optarg;
 			break; case 'c': context = optarg;
 			break; case 'd': path = optarg;
 			break; case 'f': format = formatParse(optarg);
+			break; case 'n': test = true;
 			break; case 'v': verbose = true;
 			break; default:  return EX_USAGE;
 		}
 	}
 
+	regex_t pathRegex = compile(format->pattern);
+	regex_t regex[format->len];
+	for (size_t i = 0; i < format->len; ++i) {
+		regex[i] = compile(format->matchers[i].pattern);
+	}
+	if (test) return EX_OK;
+
 	dbFind(path, SQLITE_OPEN_READWRITE);
 	if (dbVersion() != DatabaseVersion) {
 		errx(EX_CONFIG, "database out of date; migrate with litterbox -m");
@@ -328,12 +337,6 @@ int main(int argc, char *argv[]) {
 		return EX_OK;
 	}
 
-	regex_t pathRegex = compile(format->pattern);
-	regex_t regex[format->len];
-	for (size_t i = 0; i < format->len; ++i) {
-		regex[i] = compile(format->matchers[i].pattern);
-	}
-
 	sqlite3_stmt *insertContext = NULL;
 	const char *InsertContext = SQL(
 		INSERT OR IGNORE INTO contexts (network, name, query)