import os
import subprocess

from .mixins.output_panel import OutputPanelMixin
from .mixins.steps import StepsMixin


class BehaveCommand(OutputPanelMixin,
                    StepsMixin):

    '''
    Base class for all Sublime commands that interact with behave
    '''

    def behave(self, *args, **kwargs):
        '''
        Run the behave command specified in `*args` and return the output
        of the git command as a string. If output=True, the output will be
        shown live in an output panel.
        '''

        command = tuple(self.behave_command) + \
            tuple(arg for arg in args if arg)

        print('Command %s' % (command,))

        stdout = ''
        stderr = ''
        with subprocess.Popen(command,
                              stdout=subprocess.PIPE,
                              bufsize=1,
                              universal_newlines=True,
                              cwd=self.view.window().folders()[0]) as p:

            # Premature optimization is the root of all evil
            # But this could be more DRY
            if kwargs.get('output', False):
                self.erase()
                for line in p.stdout:
                    stdout += line
                    self.append(line, end='')

            else:
                stdout, stderr = p.communicate()

        if stderr:
            print('STDERR: %s' % stderr)
        return stdout

    @property
    def behave_command(self):
        '''
        The command used to launch behave. This can be set by modifying the
        behave_command setting. The setting should be a list. If not set, the
        plugin uses value of `which behave`.
        '''
        behave = self.view.settings().get('behave_command')

        if behave:
            return behave
        else:
            return [subprocess.check_output(['which', 'behave']).strip()]

@@ -4,10 +4,19 @@
 ort 
-o
 s
+ubprocess%0A
 %0Aimp
@@ -22,23 +22,20 @@
 port sub
-process
+lime
 %0A%0Afrom .
@@ -1790,32 +1790,182 @@
 e%0A        else:%0A
+            # Find the behave executable%0A            which = 'which'%0A            if sublime.platform() == 'windows':%0A                which = 'where'%0A%0A
             retu
@@ -1993,23 +1993,21 @@
 output(%5B
-'
 which
-'
 , 'behav

Call the 'where' command on Windows instead