syntax revamp
This commit is contained in:
+54
-28
@@ -193,7 +193,7 @@ class search_file(Cmdlet):
|
||||
"URL search: url:* (any URL) or url:<value> (URL substring)",
|
||||
"Extension search: ext:<value> (e.g., ext:png)",
|
||||
"Hydrus-style extension: system:filetype = png",
|
||||
"Results include hash for downstream commands (get-file, add-tag, etc.)",
|
||||
"Results include hash for downstream commands (download-file, add-tag, etc.)",
|
||||
"Examples:",
|
||||
"search-file -query foo # Search all storage backends",
|
||||
"search-file -instance home -query '*' # Search 'home' Hydrus instance",
|
||||
@@ -1755,6 +1755,13 @@ class search_file(Cmdlet):
|
||||
f.lower()
|
||||
for f in (flag_registry.get("open") or {"-open", "--open"})
|
||||
}
|
||||
valued_flags = (
|
||||
query_flags
|
||||
| instance_flags
|
||||
| limit_flags
|
||||
| plugin_flags
|
||||
| open_flags
|
||||
)
|
||||
|
||||
# Parse arguments
|
||||
query = ""
|
||||
@@ -1771,37 +1778,56 @@ class search_file(Cmdlet):
|
||||
while i < len(args_list):
|
||||
arg = args_list[i]
|
||||
low = arg.lower()
|
||||
if low in query_flags and i + 1 < len(args_list):
|
||||
chunk = args_list[i + 1]
|
||||
query = f"{query} {chunk}".strip() if query else chunk
|
||||
i += 2
|
||||
next_arg = args_list[i + 1] if i + 1 < len(args_list) else None
|
||||
next_low = str(next_arg or "").lower()
|
||||
next_is_flag = bool(next_arg) and next_low in valued_flags
|
||||
|
||||
if low in query_flags:
|
||||
if next_arg is not None and not next_is_flag:
|
||||
chunk = next_arg
|
||||
query = f"{query} {chunk}".strip() if query else chunk
|
||||
i += 2
|
||||
continue
|
||||
i += 1
|
||||
continue
|
||||
if low in plugin_flags and i + 1 < len(args_list):
|
||||
plugin_name = args_list[i + 1]
|
||||
i += 2
|
||||
if low in plugin_flags:
|
||||
if next_arg is not None and not next_is_flag:
|
||||
plugin_name = next_arg
|
||||
i += 2
|
||||
continue
|
||||
i += 1
|
||||
continue
|
||||
if low in instance_flags and i + 1 < len(args_list):
|
||||
instance_name = args_list[i + 1]
|
||||
i += 2
|
||||
if low in instance_flags:
|
||||
if next_arg is not None and not next_is_flag:
|
||||
instance_name = next_arg
|
||||
i += 2
|
||||
continue
|
||||
i += 1
|
||||
continue
|
||||
if low in open_flags and i + 1 < len(args_list):
|
||||
try:
|
||||
open_id = int(args_list[i + 1])
|
||||
except ValueError:
|
||||
log(
|
||||
f"Warning: Invalid open value '{args_list[i + 1]}', ignoring",
|
||||
file=sys.stderr,
|
||||
)
|
||||
open_id = None
|
||||
i += 2
|
||||
if low in open_flags:
|
||||
if next_arg is not None and not next_is_flag:
|
||||
try:
|
||||
open_id = int(next_arg)
|
||||
except ValueError:
|
||||
log(
|
||||
f"Warning: Invalid open value '{next_arg}', ignoring",
|
||||
file=sys.stderr,
|
||||
)
|
||||
open_id = None
|
||||
i += 2
|
||||
continue
|
||||
i += 1
|
||||
continue
|
||||
if low in limit_flags and i + 1 < len(args_list):
|
||||
limit_set = True
|
||||
try:
|
||||
limit = int(args_list[i + 1])
|
||||
except ValueError:
|
||||
limit = 100
|
||||
i += 2
|
||||
if low in limit_flags:
|
||||
if next_arg is not None and not next_is_flag:
|
||||
limit_set = True
|
||||
try:
|
||||
limit = int(next_arg)
|
||||
except ValueError:
|
||||
limit = 100
|
||||
i += 2
|
||||
continue
|
||||
i += 1
|
||||
elif not arg.startswith("-"):
|
||||
positional_args.append(arg)
|
||||
query = f"{query} {arg}".strip() if query else arg
|
||||
|
||||
Reference in New Issue
Block a user