diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2018-06-25 16:57:09 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2018-07-24 22:05:57 +0100 |
commit | 5834b460cf805457a0f7d58acee4aa8fb6759840 (patch) | |
tree | bbe5fbf7e909f9a9fbe8f78a2261e2bc89cfd957 /alot/commands/globals.py | |
parent | 65dad4acfdc45abfc03b56b9a1860c53a0e85912 (diff) |
add global command 'removequery'
that removes a named query string from the notmuch index
Diffstat (limited to 'alot/commands/globals.py')
-rw-r--r-- | alot/commands/globals.py | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 92918269..0f1d6e26 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -1004,7 +1004,7 @@ class ReloadCommand(Command): 'help': 'postpone a writeout to the index'}), (['alias'], {'help': 'alias to use for query string'}), (['query'], {'help': 'query string to store', - 'nargs': argparse.REMAINDER}) + 'nargs': '+'}) ], help='store query string as a "named query" in the database') class SaveQueryCommand(Command): @@ -1030,8 +1030,6 @@ class SaveQueryCommand(Command): Command.__init__(self, **kwargs) def apply(self, ui): - searchbuffer = ui.current_buffer - query = searchbuffer.querystring msg = 'saved alias "%s" for query string "%s"' % (self.alias, self.query) @@ -1046,3 +1044,44 @@ class SaveQueryCommand(Command): # flush index if self.flush: ui.apply_command(commands.globals.FlushCommand()) + + +@registerCommand( + MODE, 'removequery', + arguments=[ + (['--no-flush'], {'action': 'store_false', 'dest': 'flush', + 'default': 'True', + 'help': 'postpone a writeout to the index'}), + (['alias'], {'help': 'alias to remove'}), + ], + help='removes a "named query" from the database') +class RemoveQueryCommand(Command): + + """remove named query string for given alias""" + repeatable = False + + def __init__(self, alias, flush=True, **kwargs): + """ + :param alias: name to use for query string + :type alias: str + :param flush: immediately write out to the index + :type flush: bool + """ + self.alias = alias + self.flush = flush + Command.__init__(self, **kwargs) + + def apply(self, ui): + msg = 'removed alias "%s"' % (self.alias) + + try: + ui.dbman.remove_named_query(self.alias) + logging.debug(msg) + ui.notify(msg) + except DatabaseROError: + ui.notify('index in read-only mode', priority='error') + return + + # flush index + if self.flush: + ui.apply_command(commands.globals.FlushCommand()) |