Skip to content

Commit

Permalink
Resolve redundant path computation
Browse files Browse the repository at this point in the history
This doesn't seem like the best solution, but I can't think of something better that would keep it somewhat readable *and* remove the redundancy.
  • Loading branch information
Duckwhale committed Oct 3, 2021
1 parent 51b13b0 commit bc4d523
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ function commandLine.executeCommand(command)
commandLine.exitWithCode(EXIT_SUCCESS)
end

if commandLine.isValidCommand(command) then
local commandHandler = "./commands/" .. command .. ".lua"
if commandLine.isValidCommand(commandHandler) then
log("command", table.concat(args, " "), "highlight")
commandLine.executeCommandHandler(command)
commandLine.executeCommandHandler(commandHandler)
else
log("invalid command", command, "failure")
commandLine.executeCommandHandler("help")
commandLine.executeCommandHandler("./commands/help.lua")
commandLine.reportFailure("Invalid Command: " .. command)
end
end
Expand Down Expand Up @@ -116,13 +117,11 @@ function commandLine.exitWithCode(exitCode)
os.exit(exitCode)
end

function commandLine.isValidCommand(command)
local commandHandler = "./commands/" .. command .. ".lua"
function commandLine.isValidCommand(commandHandler)
return bundle.stat(commandHandler:sub(3)) -- A command is valid if a script handler for it exists
end

function commandLine.executeCommandHandler(command)
local commandHandler = "./commands/" .. command .. ".lua"
function commandLine.executeCommandHandler(commandHandler)
require(commandHandler)()
end

Expand Down

0 comments on commit bc4d523

Please sign in to comment.