#!/usr/bin/python
from l3tlib.command import L3tCommand, L3tIncidentStateMixIn
from l3tlib.template import format_objects, make_color_helper


class Next(L3tIncidentStateMixIn, L3tCommand):

    descr = "Suggest the next incident to work on"

    def run(self):
        template = self.config.l3t.incident_oneline
        C = make_color_helper(self.config)
        for incident, status in self.l3t.next(self.selected_groups()):
            for _, formatted in format_objects(template, [incident], C=C):
                print formatted
            if not self.opts.quiet and status and status.next:
                print "Next: %s" % (status.next)
            break
        else:
            print "nothing to work on"


Next().main()
