added unique and first modifiers to lookup subcommand

master
BodgeMaster 2021-12-20 03:01:56 +01:00
parent f592f2808a
commit e826c31048
1 changed files with 11 additions and 1 deletions

View File

@ -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))