From 08029476350de4f1f741c5145a33c5d9309ff4bc Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sun, 9 Apr 2023 17:20:48 -0700 Subject: [PATCH] add support for valueless searches.. --- ui/fixtures/cmd.search.json | 12 +++++++++++- ui/medashare/cli.py | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ui/fixtures/cmd.search.json b/ui/fixtures/cmd.search.json index 13c08e7..504e9f7 100644 --- a/ui/fixtures/cmd.search.json +++ b/ui/fixtures/cmd.search.json @@ -10,7 +10,7 @@ }, { "title": "add tag b", - "cmd": [ "modify", "+tag=bar", "+dc:creator=John-Mark Gurney", "test.txt" ] + "cmd": [ "modify", "+tag=bar", "+dc:creator=John-Mark Gurney", "+other=baz", "test.txt" ] }, { "special": "verify store object cnt", @@ -31,5 +31,15 @@ "title": "search no tag bar", "cmd": [ "search", "file", "-tag=bar" ], "stdout_re": "/newfile.txt\n$" +}, +{ + "title": "search no other", + "cmd": [ "search", "file", "-other" ], + "stdout_re": "/newfile.txt\n$" +}, +{ + "title": "search other", + "cmd": [ "search", "file", "+other" ], + "stdout_re": "/test.txt\n$" } ] diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index 9193662..4a80d69 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -1426,12 +1426,23 @@ def cmd_search(options, persona, objstr, cache): def testfun(x, s=searches): try: for i in s: - op, key, value = i + try: + op, key, value = i + except ValueError: + op, key = i + value = None + if op == '+': - if value not in x[key]: + if value is None: + if key not in x: + return False + elif value not in x[key]: return False elif op == '-': - if value in x[key]: + if value is None: + if key in x: + return False + elif value in x[key]: return False else: raise ValueError('unhandled op: %s' % repr(op))