verbosity for add, remove, list
This commit is contained in:
parent
f3dbe32fc5
commit
2bfe336339
3 changed files with 45 additions and 15 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue