Skip to content

Commit

Permalink
feat: introduce new config for env file
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Oct 31, 2023
1 parent d0cd7e9 commit 2cef196
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions lua/hurl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
local default_config = {
debug = false,
mode = 'split',
env_file = 'vars.env',
formatters = {
json = { 'jq' },
html = {
Expand Down
14 changes: 10 additions & 4 deletions lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ local function get_env_file_in_folders()
local root_dir = vim.fn.expand('%:p:h')
local cache_dir = vim.fn.stdpath('cache')
local env_files = {
{ path = root_dir .. '/vars.env', dest = cache_dir .. '/vars.env' },
{
path = root_dir .. '/' .. _HURL_GLOBAL_CONFIG.env_file,
dest = cache_dir .. '/' .. _HURL_GLOBAL_CONFIG.env_file,
},
}
local scan_dir = {
{
Expand All @@ -38,7 +41,10 @@ local function get_env_file_in_folders()
for _, s in ipairs(scan_dir) do
local dir = root_dir .. s.dir
if vim.fn.isdirectory(dir) == 1 then
table.insert(env_files, { path = dir .. '/vars.env', dest = cache_dir .. '/vars.env' })
table.insert(env_files, {
path = dir .. '/' .. _HURL_GLOBAL_CONFIG.env_file,
dest = cache_dir .. '/' .. _HURL_GLOBAL_CONFIG.env_file,
})
end
end

Expand Down Expand Up @@ -111,7 +117,7 @@ local function request(opts, callback)
local env_files = get_env_file_in_folders()
for _, env in ipairs(env_files) do
if vim.fn.filereadable(env.path) == 1 then
utils.log_info('hurl: found vars.env ' .. env.path)
utils.log_info('hurl: found ' .. _HURL_GLOBAL_CONFIG.env_file .. ' in ' .. env.path)
table.insert(opts, '--variables-file')
table.insert(opts, env.path)
break
Expand Down Expand Up @@ -277,7 +283,7 @@ function M.setup()
opts.fargs = vim.list_extend(opts.fargs, { '--to-entry', result.current })
run_current_file(opts.fargs)
else
vim.notify('hurl: no http method found in the current line', vim.log.levels.INFO)
vim.notify('hurl: no HTTP method found in the current line', vim.log.levels.INFO)
end
end, { nargs = '*', range = true })
end
Expand Down

0 comments on commit 2cef196

Please sign in to comment.