diff --git a/lua/hurl/main.lua b/lua/hurl/main.lua index 5038b52..70d6f55 100644 --- a/lua/hurl/main.lua +++ b/lua/hurl/main.lua @@ -146,6 +146,8 @@ local function execute_hurl_cmd(opts, callback) local is_verbose_mode = vim.tbl_contains(opts, '--verbose') local is_json_mode = vim.tbl_contains(opts, '--json') + local is_file_mode = utils.has_file_in_opts(opts) + if not _HURL_GLOBAL_CONFIG.auto_close and not is_verbose_mode @@ -190,6 +192,10 @@ local function execute_hurl_cmd(opts, callback) -- Include the HTTP headers in the output and do not colorize output. local cmd = vim.list_extend({ 'hurl', '-i', '--no-color' }, opts) + if is_file_mode then + local file_root = _HURL_GLOBAL_CONFIG.file_root or vim.fn.getcwd() + vim.list_extend(cmd, { '--file-root', file_root }) + end response = {} utils.log_info('hurl: running command' .. vim.inspect(cmd)) diff --git a/lua/hurl/utils.lua b/lua/hurl/utils.lua index 193ab4e..5bcd608 100644 --- a/lua/hurl/utils.lua +++ b/lua/hurl/utils.lua @@ -286,5 +286,30 @@ util.find_env_files_in_folders = function() return env_files end +util.has_file_in_opts = function(opts) + if #opts == 0 then + vim.notify('No file path provided in opts.', vim.log.levels.DEBUG) + return false + end + + local file_path = opts[1] + + local file = io.open(file_path, 'r') + if not file then + print('Error: Failed to open file: ' .. file_path) + return false + end + + for line in file:lines() do + if line:lower():find('file') or line:lower():find('multipart') then + file:close() -- Close the file before returning + return true -- Return true if any line contains the keyword + end + end + + file:close() + + return false +end return util