#!/usr/bin/python
import shlex
import subprocess
from l3tlib.command import L3tBugCommand
from l3tlib.template import format


class Open(L3tBugCommand):

    descr = "Opens a bug using xdg-open"

    def run(self):
        if self.opts.bug:
            bug_id = self.opts.bug
        else:
            incident = self.l3t.get_incident(self.opts.incident,
                                             self.opts.bug)
            bug_id = incident.bug.id
        raw_cmd = format(self.config.l3t.bug_open_command, bug=bug_id)
        args = shlex.split(raw_cmd)
        subprocess.call(args)


Open().main()
