about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--scoop.19
-rw-r--r--scoop.c13
2 files changed, 17 insertions, 5 deletions
diff --git a/scoop.1 b/scoop.1
index a16d9f2..253b2ea 100644
--- a/scoop.1
+++ b/scoop.1
@@ -23,6 +23,7 @@
 .Op Fl n Ar nick
 .Op Fl t Ar type
 .Op Fl u Ar user
+.Op Fl w Ar expr
 .Op Ar search
 .Nm
 .Fl s
@@ -157,6 +158,14 @@ Match events from users with the username
 .It Fl v
 Print the expanded SQL query being used to standard error.
 .
+.It Fl w Ar expr
+Add the SQL expression
+.Ar expr
+to the
+.Sy WHERE
+clause of the query.
+This option can only be used once.
+.
 .It Ar search
 Match events using full-text search.
 The searchable columns are
diff --git a/scoop.c b/scoop.c
index f75a32c..d21d77e 100644
--- a/scoop.c
+++ b/scoop.c
@@ -276,9 +276,10 @@ int main(int argc, char *argv[]) {
 	int n = 0;
 	struct Bind binds[argc];
 	const char *search = NULL;
+	const char *where = NULL;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "D:F:N:T:a:b:c:d:f:gh:l:n:pqst:u:v"))) {
+	while (0 < (opt = getopt(argc, argv, "D:F:N:T:a:b:c:d:f:gh:l:n:pqst:u:vw:"))) {
 		switch (opt) {
 			break; case 'D': binds[n++] = Bind(":date", optarg, 0);
 			break; case 'F': binds[n++] = Bind(":format", optarg, 0);
@@ -299,6 +300,7 @@ int main(int argc, char *argv[]) {
 			break; case 't': binds[n++] = Bind(":type", NULL, parseType(optarg));
 			break; case 'u': binds[n++] = Bind(":user", optarg, 0);
 			break; case 'v': verbose = true;
+			break; case 'w': where = optarg;
 			break; default:  return EX_USAGE;
 		}
 	}
@@ -347,15 +349,16 @@ int main(int argc, char *argv[]) {
 	if (search) {
 		snprintf(
 			sql, sizeof(sql),
-			"WITH results AS (%s AND %s %s) %s;",
-			Inner, Search, Limit, (group ? Group : Outer)
+			"WITH results AS (%s AND %s AND %s %s) %s;",
+			Inner, Search, (where ? where : "true"), Limit,
+			(group ? Group : Outer)
 		);
 		binds[n++] = Bind(":search", search, 0);
 	} else {
 		snprintf(
 			sql, sizeof(sql),
-			"WITH results AS (%s %s) %s;",
-			Inner, Limit, (group ? Group : Outer)
+			"WITH results AS (%s AND %s %s) %s;",
+			Inner, (where ? where : "true"), Limit, (group ? Group : Outer)
 		);
 	}