Skip to content

Commit

Permalink
Merge pull request #1 from you-n-g/patch-2
Browse files Browse the repository at this point in the history
Porting pending PR: jackMort#300
  • Loading branch information
gmatheu authored Jun 19, 2024
2 parents df53728 + a5a7192 commit 6be2aa6
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lua/chatgpt/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,24 @@ end

local function loadConfigFromCommand(command, optionName, callback, defaultValue)
local cmd = splitCommandIntoTable(command)
job
:new({
command = cmd[1],
args = vim.list_slice(cmd, 2, #cmd),
on_exit = function(j, exit_code)
if exit_code ~= 0 then
logger.warn("Config '" .. optionName .. "' did not return a value when executed")
return
end
local value = j:result()[1]:gsub("%s+$", "")
if value ~= nil and value ~= "" then
callback(value)
elseif defaultValue ~= nil and defaultValue ~= "" then
callback(defaultValue)
end
end,
})
:start()
local j = job:new({
command = cmd[1],
args = vim.list_slice(cmd, 2, #cmd),
on_exit = function(j, exit_code)
if exit_code ~= 0 then
logger.warn("Config '" .. optionName .. "' did not return a value when executed")
return
end
local value = j:result()[1]:gsub("%s+$", "")
if value ~= nil and value ~= "" then
callback(value)
elseif defaultValue ~= nil and defaultValue ~= "" then
callback(defaultValue)
end
end,
})
j:start()
j:wait() -- we should wait the job to finish. Otherwise we can't ensure correctly reading config before using it.
end

local function loadConfigFromEnv(envName, configName, callback)
Expand Down

0 comments on commit 6be2aa6

Please sign in to comment.