Skip to content

Commit

Permalink
refactor: commands and add new error handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Diogo-ss committed Mar 26, 2024
1 parent 552d3df commit 227e8e4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
32 changes: 25 additions & 7 deletions lua/fs/utils/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
--- flag to generate another file even if one already
--- exists in the current directory.
---
--- - `:FiveServer install`: Install Five-Server.
---
---NOTE: The commands will only be available after running setup().
---
---@brief ]]
Expand Down Expand Up @@ -51,6 +53,11 @@ M.flags = {
return
end

if flag then
logger.logger_warn("Invalid sub flag: " .. flag)
return
end

process.start()
end,
},
Expand All @@ -65,14 +72,20 @@ M.flags = {
---Stop Job with corresponding ID.
---@param id string: The ID of the process to stop.
execute = function(id)
id = tonumber(id) or process.get_path_instance(vim.fn.getcwd())
id = id or tostring(process.get_path_instance(vim.fn.getcwd()))

if not id:match "^%d+$" then
logger.logger_warn "Invalid ID format"
return
end

if not process.job_exists(id) then
logger.logger_warn "Job not found"
local num_id = tonumber(id)
if not num_id or not process.job_exists(num_id) then
logger.logger_warn "Invalid or no instance exists with ID"
return
end

process.stop(id)
process.stop(num_id)
end,
},

Expand All @@ -91,16 +104,21 @@ M.flags = {
return
end

if flag then
logger.logger_warn("Invalid sub flag: " .. flag)
return
end

rc.gen_rc()
end,
},

---Install flag.
install = {
execute = function(_)
require "fs.utils.install"()
end
}

end,
},
}

---Filters flags based on a leading argument.
Expand Down
4 changes: 2 additions & 2 deletions lua/fs/utils/install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ local config = require "fs.config"
local logger = require "fs.utils.logger"

local function cmd(command)
logger.logger_info("starting installation with: " .. tostring(command[1]))
logger.logger_info("Starting installation with: " .. tostring(command[1]))

vim.fn.jobstart(command, {
on_exit = function(_, code)
if code ~= 0 then
logger.logger_error("error when trying to install with: " .. table.concat(command, " "))
logger.logger_error("Error when trying to install with: " .. table.concat(command, " "))
else
logger.logger_info "Five Server was installed."
end
Expand Down

0 comments on commit 227e8e4

Please sign in to comment.