Improved beau.yml file discovery.
If a beau.yml file is not currently open it'll attempt to look for one in the current project.
This commit is contained in:
parent
eb654ad43d
commit
4af47841de
41
beau.py
41
beau.py
|
|
@ -18,12 +18,19 @@ class InsertTextCommand(sublime_plugin.TextCommand):
|
||||||
class BeauCommand(sublime_plugin.TextCommand):
|
class BeauCommand(sublime_plugin.TextCommand):
|
||||||
requests = []
|
requests = []
|
||||||
path = ''
|
path = ''
|
||||||
|
active_view = None
|
||||||
|
scope = None
|
||||||
|
folders = []
|
||||||
|
|
||||||
def inThread(self, command, onComplete):
|
def inThread(self, command, onComplete, cwd=None):
|
||||||
def thread(command, onComplete):
|
def thread(command, onComplete):
|
||||||
proc = check_output(command, shell=is_windows)
|
try:
|
||||||
onComplete(proc)
|
proc = check_output(command, shell=is_windows, stderr=subprocess.STDOUT, cwd=cwd)
|
||||||
return
|
onComplete(proc)
|
||||||
|
return
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
active_window().status_message('Beau Command Failed. Open the console for more info.')
|
||||||
|
print(e.output)
|
||||||
|
|
||||||
thread = Thread(target=thread, args=(command, onComplete))
|
thread = Thread(target=thread, args=(command, onComplete))
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
@ -33,16 +40,18 @@ class BeauCommand(sublime_plugin.TextCommand):
|
||||||
def run(self, edit):
|
def run(self, edit):
|
||||||
settings = load_settings(SETTINGS_FILE)
|
settings = load_settings(SETTINGS_FILE)
|
||||||
self.path = settings.get('cli_path', '')
|
self.path = settings.get('cli_path', '')
|
||||||
active_view = active_window().active_view()
|
self.active_view = active_window().active_view()
|
||||||
|
self.folders = active_window().folders()
|
||||||
|
|
||||||
scope = active_view.scope_name(active_view.sel()[0].b)
|
self.scope = self.active_view.scope_name(self.active_view.sel()[0].b)
|
||||||
if not scope.startswith('source.yaml'):
|
command = [self.path, 'list', '--no-format']
|
||||||
active_window().status_message('Beau can only be ran on yaml files.')
|
if self.scope.startswith('source.yaml'):
|
||||||
return
|
command.extend(['-c', self.active_view.file_name()])
|
||||||
|
|
||||||
self.inThread(
|
self.inThread(
|
||||||
[self.path, 'list', '-c', active_view.file_name(), '--no-format'],
|
command,
|
||||||
self.listFetched
|
self.listFetched,
|
||||||
|
cwd=self.folders[0] if len(self.folders) > 0 else None
|
||||||
)
|
)
|
||||||
|
|
||||||
def listFetched(self, list):
|
def listFetched(self, list):
|
||||||
|
|
@ -60,7 +69,6 @@ class BeauCommand(sublime_plugin.TextCommand):
|
||||||
if index == -1:
|
if index == -1:
|
||||||
return
|
return
|
||||||
|
|
||||||
active_view = active_window().active_view()
|
|
||||||
method, alias, endpoint = self.requests[index]
|
method, alias, endpoint = self.requests[index]
|
||||||
|
|
||||||
active_window().status_message('Running: ' + alias)
|
active_window().status_message('Running: ' + alias)
|
||||||
|
|
@ -95,9 +103,14 @@ class BeauCommand(sublime_plugin.TextCommand):
|
||||||
results_view.set_scratch(True)
|
results_view.set_scratch(True)
|
||||||
results_view.set_syntax_file(SYNTAX)
|
results_view.set_syntax_file(SYNTAX)
|
||||||
|
|
||||||
|
command = [self.path, 'request', alias, '--no-format']
|
||||||
|
if self.scope.startswith('source.yaml'):
|
||||||
|
command.extend(['-c', self.active_view.file_name()])
|
||||||
|
|
||||||
self.inThread(
|
self.inThread(
|
||||||
[self.path, 'request', alias,'-c', active_view.file_name(), '--no-format'],
|
command,
|
||||||
onComplete=handleResult
|
onComplete=handleResult,
|
||||||
|
cwd=self.folders[0] if len(self.folders) > 0 else None
|
||||||
)
|
)
|
||||||
|
|
||||||
def autoindent(self, obj):
|
def autoindent(self, obj):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue