5
""" tail bot results. """
7
__copyright__ = 'this file is in the public domain'
10
from gozerbot.utils.generic import waitforqueue
11
from gozerbot.commands import cmnds
12
from gozerbot.plughelp import plughelp
13
from gozerbot.examples import examples
14
from gozerbot.tests import tests
16
plughelp.add('tail', 'show last <nr> elements of pipeline')
18
def handle_tail(bot, ievent):
20
""" used in a pipeline .. show last <nr> elements. """
22
if not ievent.inqueue:
23
ievent.reply("use tail in a pipeline")
27
nr = int(ievent.args[0])
28
except (ValueError, IndexError):
29
ievent.reply('tail <nr>')
32
result = waitforqueue(ievent.inqueue, 30)
35
ievent.reply('no data to tail')
38
ievent.reply(result[-nr:])
40
cmnds.add('tail', handle_tail, ['USER', 'CLOUD'], threaded=True)
41
examples.add('tail', 'show last <nr> lines of pipeline output', 'list | tail 5')
42
tests.add('list | tail 5')