diff options
author | June McEnroe <june@causal.agency> | 2020-01-01 16:39:09 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-01-01 16:39:09 -0500 |
commit | 1ba0d0b91a339ef2d684b628347674a756569c52 (patch) | |
tree | 499e5fb5d78f58f9e6d1aef127c533223913bb10 | |
parent | Document ENVIRONMENT in scoop(1) (diff) | |
download | litterbox-1ba0d0b91a339ef2d684b628347674a756569c52.tar.gz litterbox-1ba0d0b91a339ef2d684b628347674a756569c52.zip |
Add option for custom where expression to scoop
-rw-r--r-- | scoop.1 | 9 | ||||
-rw-r--r-- | scoop.c | 13 |
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) ); } |