So I have several commands which inherit from Default.exec.ExecCommand
. Let’s call them:
class FirstCommand(Default.exec.ExecCommand):
def run(self):
# do stuff ...
super().run(shell_cmd='pwd', working_dir='/home')
def on_finished(self, proc):
super().on_finished(proc)
# finishing touches ...
class SecondCommand(Default.exec.ExecCommand):
def run(self):
# do stuff
super().run(shell_cmd='ls', working_dir='/home')
def on_finished(self, proc):
super().on_finished(proc)
# finishing touches ...
Now I have another command that wants to run these two sequentially, say:
class CombinedCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('first')
self.window.run_command('second') # OOPS!
The problem here is that these two commands are running parallel now… So obviously we need callbacks, right? So we adjust the FirstCommand
class:
class FirstCommand(Default.exec.ExecCommand):
def run(self, on_done=None):
self.on_done_callback = on_done
# do stuff ...
super().run(shell_cmd='pwd', working_dir='/home')
def on_finished(self, proc):
super().on_finished(proc)
# finishing touches ...
if self.on_done_callback:
self.on_done_callback()
And then adjust the CombinedCommand
as follows:
class CombinedCommand(sublime_plugin.WindowCommand):
def run(self):
def on_done():
self.window.run_command('second')
self.window.run_command('first', args={"on_done": on_done})
I was hoping this would work, after all Sublime should just pass this args
dictionary straight to the run
method, right? Well, unfortunately I get:
File "/Applications/Sublime Text.app/Contents/MacOS/sublime.py", line 299, in run_command
sublime_api.window_run_command(self.window_id, cmd, args)
TypeError: Value required
So does anyone have another idea to sequentially run these kinds of commands?