implement: jq path setting

This commit is contained in:
TheSecEng 2020-04-17 22:43:01 -04:00
parent 394353d5bf
commit 3f2841d109
No known key found for this signature in database
GPG Key ID: A7C3BA459E8C5C4E
2 changed files with 9 additions and 8 deletions

View File

@ -8,5 +8,6 @@
"keep_arrays_single_line": false, "keep_arrays_single_line": false,
"max_arrays_line_length": 120, "max_arrays_line_length": 120,
"pretty_on_save": false, "pretty_on_save": false,
"validate_on_save": true "validate_on_save": true,
"jq_binary": "jq"
} }

View File

@ -27,7 +27,7 @@ SUBLIME_MAJOR_VERSION = int(sublime.version()) / 1000
jq_exits = False jq_exits = False
jq_init = False jq_init = False
jq_path = str()
""" for OSX we need to manually add brew bin path so jq can be found """ """ for OSX we need to manually add brew bin path so jq can be found """
if sys.platform != "win32" and "/usr/local/bin" not in os.environ["PATH"]: if sys.platform != "win32" and "/usr/local/bin" not in os.environ["PATH"]:
@ -38,20 +38,20 @@ if sys.platform != "win32" and "/usr/local/bin" not in os.environ["PATH"]:
def check_jq(): def check_jq():
global jq_exits global jq_exits, jq_init, jq_path
global jq_init
if not jq_init: if not jq_init:
jq_init = True jq_init = True
jq_path = s.get("jq_binary", "jq")
try: try:
# checking if ./jq tool is available so we can use it # checking if ./jq tool is available so we can use it
s = subprocess.Popen( jq = subprocess.Popen(
["jq", "--version"], [jq_path, "--version"],
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
) )
out, err = s.communicate() out, err = jq.communicate()
jq_exits = True jq_exits = True
except OSError: except OSError:
os_exception = sys.exc_info()[1] os_exception = sys.exc_info()[1]
@ -334,7 +334,7 @@ class JqPrettyJson(sublime_plugin.WindowCommand):
def done(self, query): def done(self, query):
try: try:
p = subprocess.Popen( p = subprocess.Popen(
["jq", query], [jq_path, query],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,