diff --git a/orvani/cmd.py b/orvani/cmd.py index 54f19f7..371b30b 100644 --- a/orvani/cmd.py +++ b/orvani/cmd.py @@ -47,11 +47,24 @@ def mktable(query: str, index: dict, filter=None, trunc_len: int=25): table.add_row(*elements) console.print(table) else: - console.print(f"No results found for `{query}`", style="red") - + console.print(f":thinking_face: [red]No results found for [white]{query}") + +def nice_context(context): + string = '' + if context['projects']: + string += '[cyan]' + ' '.join(['+' + tag for tag in context['projects']]) + '[/cyan] ' + if context['contexts']: + string += '[yellow]' + ' '.join(['+' + tag for tag in context['contexts']]) + '[/yellow] ' + if context['tags']: + string += '[magenta]' + ' '.join(['+' + tag for tag in context['tags']]) + '[/magenta] ' + if 'note' in context: + string += '[green]\'' + context['note'] + '\'[/green] ' + return string def main(): + console = Console() + command_help = """{add,a} FILE [CONTEXT ...] {remove,rem,r} FILE [CONTEXT ...] @@ -103,11 +116,21 @@ def main(): if args.command in ['add', 'a']: if args.file and args.context: - orvani.add(args.file, *args.context) + fb = orvani.add(args.file, *args.context) + if fb[0] == 0: + console.print(f':label: File [strong]{fb[1]}[/strong] successfully tagged: {nice_context(fb[2])}') + elif fb[0] == 1: + console.print(f":thinking_face: Sorry, the file [strong]{fb[1]}[/strong] doesn't exist.") elif args.command in ['remove', 'rem', 'r']: if args.file and args.context: - orvani.remove(args.file, *args.context) + fb = orvani.remove(args.file, *args.context) + if fb[0] == 0: + console.print(f':wastebasket: Tags {nice_context(fb[2])}of file [white][strong]{fb[1]}[/strong][/white] successfully removed.') + elif fb[0] == 1: + console.print(f":thinking_face: Sorry, the file [strong]{fb[1]}[/strong] doesn't exist.") + elif fb[0] == 2: + console.print(f":mag: Sorry, could not find an entry for [white][strong]{fb[1]}[/strong][/white] and {nice_context(fb[2])}") elif args.command in ['list', 'ls', 'dir', 'l']: query = [args.file] + args.context diff --git a/orvani/orvani.py b/orvani/orvani.py index c29eb82..6a7fcfc 100644 --- a/orvani/orvani.py +++ b/orvani/orvani.py @@ -44,7 +44,7 @@ class OrvaniTag: ERRORS: 0 - Success 1 - File Not Found - 2 - Content not found + 2 - Entry not found 3 - Path is wrong type 4 - Wrong File Type 5 - Plugin has no method @@ -183,9 +183,9 @@ class OrvaniTag: self.DB.update( { target.name : context } ) saved = self.__save() if saved and context: - return [0, saved, context] + return [0, file, context] else: - return [1] + return [1, file] def remove(self, file: str, *argv: str): """ @@ -199,20 +199,21 @@ class OrvaniTag: if target.exists(): self.__cd(target.parent) context = self.__context(argv) - if file in self.DB: + if target.name in self.DB: + saved = False for context_key in self.CTX.keys(): # Only works for context list items if self.CTX[context_key] != None: for item in context[context_key]: - if item in self.DB[file][context_key]: - self.DB[file][context_key].remove(item) + if item in self.DB[target.name][context_key]: + self.DB[target.name][context_key].remove(item) saved = self.__save() - if saved and self.DB[file]: - return [0, saved, self.DB[file]] - else: - return [2, item] + if saved and self.DB[target.name]: + return [0, file, context] + else: + return [2, file, context] else: - return [2, file] + return [2, file, context] else: return [1, file] diff --git a/test/.context.yaml b/test/.context.yaml index 4f2447a..a3fa3e6 100644 --- a/test/.context.yaml +++ b/test/.context.yaml @@ -21,3 +21,9 @@ items: tags: - whoa - that + test.txt: + contexts: [] + note: dededede + projects: [] + tags: + - ttt