Skip to content

Commit

Permalink
feat: Updated lua/hurl/wrapper.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Oct 24, 2023
1 parent 029f784 commit bada578
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lua/hurl/wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ local M = {}

local response = {}

--- Output handler
--- Output handler. This function handles the output of the HTTP request. It logs the status code, parses the response headers and body, and logs the response status, headers, and body.
---@class Output
local on_output = function(code, data, event)
util.log_info('hurl: code ', code)
local head_state
-- Remove the first element from the data array if it is an empty string
if data[1] == '' then
table.remove(data, 1)
end
-- Return if the first element of the data array is nil
if not data[1] then
return
end
Expand Down Expand Up @@ -54,7 +56,7 @@ local on_output = function(code, data, event)
util.log_info('hurl: response body ' .. response.body)
end

--- Call hurl command
--- Call hurl command. This function runs the HTTP request, logs the request status, and handles the response output. It also handles any errors that occur during the request and calls the callback function if provided.
---@param opts table The options
---@param callback? function The callback function
local function request(opts, callback)
Expand Down Expand Up @@ -112,16 +114,15 @@ local function request(opts, callback)
})
end

--- Run current file
--- It will throw an error if that is not valid hurl file
--- Run current file. This function runs the HTTP request for the current file. It will throw an error if the file is not a valid hurl file.
---@param opts table The options
local function run_current_file(opts)
opts = opts or {}
table.insert(opts, vim.fn.expand('%:p'))
request(opts)
end

--- Run selection
--- Run selection. This function runs the HTTP request for the selected lines in the current file. It creates a temporary file with the selected lines and runs the request for this file.
---@param opts table The options
local function run_selection(opts)
opts = opts or {}
Expand Down

0 comments on commit bada578

Please sign in to comment.