Skip to content

Commit

Permalink
fix: status commands and use of error function
Browse files Browse the repository at this point in the history
  • Loading branch information
adalessa committed Dec 28, 2023
1 parent 174374a commit 51f8a03
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 32 deletions.
13 changes: 11 additions & 2 deletions lua/laravel/api/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ end

---@return string
function ApiResponse:prettyContent()
return vim.inspect(self:content())
return table.concat(self:content(), "\r\n")
end

---@return string|nil
Expand All @@ -54,7 +54,7 @@ end

---@return string[]|nil
function ApiResponse:errors()
if self:failed() then
if self:successful() then
return nil
end

Expand All @@ -65,4 +65,13 @@ function ApiResponse:errors()
return self:content()
end

function ApiResponse:prettyErrors()
local errors = self:errors()
if not errors then
return ""
end

return table.concat(errors, "\r\n")
end

return ApiResponse
5 changes: 3 additions & 2 deletions lua/laravel/recipes/doctrine-dbal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ function M.run()
---@param response ApiResponse
function(response)
if response:failed() then
error({ "Cant install doctrine/dbal", response:errors() }, vim.log.levels.ERROR)
vim.notify("Cant install doctrine/dbal\n\r" .. response:prettyErrors(), vim.log.levels.ERROR)
else
vim.notify("Installation completed", vim.log.levels.INFO)
end
vim.notify("Installation completed", vim.log.levels.INFO)
end
)
else
Expand Down
14 changes: 7 additions & 7 deletions lua/laravel/recipes/ide-helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ local function writeModels()
---@param response ApiResponse
function(response)
if response:failed() then
error(response:errors(), vim.log.levels.ERROR)
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
else
vim.notify("Ide Helper Models Complete", vim.log.levels.INFO)
end

vim.notify("Ide Helper Models Complete", vim.log.levels.INFO)
end
)
end
Expand All @@ -24,11 +24,11 @@ local function installIdeHelperAndWrite()
---@param response ApiResponse
function(response)
if response:failed() then
error({ "Cant install ide-helper", response:errors() }, vim.log.levels.ERROR)
vim.notify("Cant install ide-helper\n\r" .. response:prettyErrors(), vim.log.levels.ERROR)
else
require("laravel.commands").list = {}
writeModels()
end

require("laravel.commands").list = {}
writeModels()
end
)
end
Expand Down
9 changes: 6 additions & 3 deletions lua/laravel/resources/create.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ return function(command)
local name = command[2]

if not is_resource(resource) then
error(string.format("Command %s is not a resource creation suported", resource), vim.log.levels.ERROR)
vim.notify(string.format("Command %s is not a resource creation suported", resource), vim.log.levels.ERROR)

return
end

api.async(
Expand All @@ -16,9 +18,10 @@ return function(command)
---@param response ApiResponse
function(response)
if response:failed() then
error(response:errors(), vim.log.levels.ERROR)
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
else
open(resource, name)
end
open(resource, name)
end
)
end
21 changes: 12 additions & 9 deletions lua/laravel/user_commands/docker_compose.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ function M.setup()
---@param response ApiResponse
function(response)
if response:failed() then
error(response:errors(), vim.log.levels.ERROR)
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
else
vim.notify("Compose Up Completed", vim.log.levels.INFO)
end
vim.notify("Compose Up Completed", vim.log.levels.INFO)
end
)
end,
Expand All @@ -31,9 +32,10 @@ function M.setup()
---@param response ApiResponse
function(response)
if response:failed() then
error(response:errors(), vim.log.levels.ERROR)
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
else
vim.notify(response:prettyContent(), vim.log.levels.INFO)
end
vim.notify(response:prettyContent(), vim.log.levels.INFO)
end
)
end,
Expand All @@ -45,10 +47,10 @@ function M.setup()
---@param response ApiResponse
function(response)
if response:failed() then
error(response:errors(), vim.log.levels.ERROR)
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
else
vim.notify("Compose restart complete", vim.log.levels.INFO)
end

vim.notify("Compose restart complete", vim.log.levels.INFO)
end
)
vim.notify("Compose restart starting", vim.log.levels.INFO)
Expand All @@ -61,9 +63,10 @@ function M.setup()
---@param response ApiResponse
function(response)
if response:failed() then
error(response:errors(), vim.log.levels.ERROR)
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
else
vim.notify("Compose Down complete", vim.log.levels.INFO)
end
vim.notify("Compose Down complete", vim.log.levels.INFO)
end
)
end,
Expand Down
21 changes: 12 additions & 9 deletions lua/laravel/user_commands/sail.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function M.setup()
---@param response ApiResponse
function(response)
if response:failed() then
error(response:content(), vim.log.levels.ERROR)
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
else
vim.notify("Sail up completed", vim.log.levels.INFO)
end

vim.notify("Sail up completed", vim.log.levels.INFO)
end
)
end,
Expand All @@ -37,9 +37,10 @@ function M.setup()
---@param response ApiResponse
function(response)
if response:failed() then
error(response:errors(), vim.log.levels.ERROR)
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
else
vim.notify(response:prettyContent(), vim.log.levels.INFO)
end
vim.notify(response:prettyContent(), vim.log.levels.INFO)
end
)
end,
Expand All @@ -51,9 +52,10 @@ function M.setup()
---@param response ApiResponse
function(response)
if response:failed() then
error(response:errors(), vim.log.levels.ERROR)
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
else
vim.notify("Sail restart complete", vim.log.levels.INFO)
end
vim.notify("Sail restart complete", vim.log.levels.INFO)
end
)
vim.notify("Sail restart starting", vim.log.levels.INFO)
Expand All @@ -66,9 +68,10 @@ function M.setup()
---@param response ApiResponse
function(response)
if response:failed() then
error(response:errors(), vim.log.levels.ERROR)
vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
else
vim.notify("Sail Down complete", vim.log.levels.INFO)
end
vim.notify("Sail Down complete", vim.log.levels.INFO)
end
)
end,
Expand Down

0 comments on commit 51f8a03

Please sign in to comment.