summaryrefslogtreecommitdiff
path: root/alot/commands/namedqueries.py
blob: 59a644ee13bb2ca21688ae0ff5fa046c7482dcb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright (C) 2011-2018  Patrick Totzke <patricktotzke@gmail.com>
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file

import argparse

from .          import Command, registerCommand
from .globals   import SearchCommand

MODE = 'namedqueries'


@registerCommand(MODE, 'select', arguments=[
    (['filt'], {'nargs': argparse.REMAINDER,
                'help': 'additional filter to apply to query'}),
])
class NamedqueriesSelectCommand(Command):

    """search for messages with selected query"""
    def __init__(self, filt=None, **kwargs):
        self._filt = filt
        super().__init__(**kwargs)

    async def apply(self, ui):
        query_name = ui.current_buffer.get_selected_query()
        query = ['query:"%s"' % query_name]
        if self._filt:
            query.extend(['and'] + self._filt)

        cmd = SearchCommand(query=query)
        await ui.apply_command(cmd)