Created
September 12, 2019 09:45
-
-
Save DarkWiiPlayer/54fc982fe2bf6475bd0fe8344caaea33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local lfs = require 'lfs' | |
local commands = {} | |
setmetatable(commands, {__call = function(self, name, func, description) | |
if func then | |
self[name] = func | |
table.insert(self, {name=name, description=description}) | |
else | |
for index, command in ipairs(self) do | |
print(command.name .. ': ' .. command.description) | |
end | |
end | |
end}) | |
return commands |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env lua | |
require 'tasks' | |
local commands = require 'commands' | |
local command = commands[...] | |
if not command then | |
commands() | |
else | |
command(...) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'commands' ('run', function(name, task, ...) | |
if task == 'list' then | |
-- TODO: Check if directory exists | |
-- TODO: Tasks in folders | |
for file in lfs.dir('tasks') do | |
if file:sub(1,1)~='.' then | |
print((file:gsub('.lua$', ''))) | |
end | |
end | |
elseif task then | |
local file = io.open('tasks/'..task..'.lua') | |
if not file then error("Task "..task.." not found!") end | |
local code = load(file:read('*a')) | |
file:close() | |
return code(...) | |
else | |
print(name..' [task]: Runs a given task') | |
end | |
end, 'Runs a task') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment