From e826c31048b9be65563f230aa87a8cfaeebe94c7 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Mon, 20 Dec 2021 03:01:56 +0100 Subject: [PATCH] added unique and first modifiers to lookup subcommand --- filetags.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/filetags.py b/filetags.py index 6bb26f1..322cac7 100644 --- a/filetags.py +++ b/filetags.py @@ -389,7 +389,17 @@ if __name__ == "__main__": for file_hash in common_file_hashes: lookup_results[file_hash] = get_tags_by_hash(storage_directory, file_hash) - print(json.dumps(lookup_results)) + if 'unique' in command: + if(len(lookup_results)==1): + print(json.dumps(lookup_results)) + else: + print("More than one matching file found.", file=sys.stderr) + sys.exit(GENERAL_ERROR) + elif 'first' in command: + file_hash, tags = list(lookup_results.items())[0] + print(json.dumps({file_hash : tags})) + else: + print(json.dumps(lookup_results))