SHARE
TWEET

lib/core.lua

throwawayrobot Feb 19th, 2019 (edited) 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. core = {}
  2.  
  3. core.update = function (test)
  4.   return 'update: ' .. test
  5. end
  6.  
  7. core.install = function()
  8.   print('install')
  9. end
  10.  
  11. local cli = {
  12.   ["update"] = { [1] = ""; usage = ""};
  13.   ["install"] = { [1] = ""; usage = ""};
  14.   validate = function(self, cmd, ...)
  15.     if #arg < #self[cmd] then
  16.       error({code = 100; message = "Not enough arguments."})
  17.     end
  18.     return true
  19.   end;
  20.   info = function(self, cmd, ...)
  21.     local func = nil
  22.     status, err = pcall(self.validate, self, cmd, unpack(arg or {}))
  23.     if status then func = core[cmd] else func = function (...) print(err.code, err.message) end end
  24.     return func, arg
  25.   end;
  26. }
  27.  
  28. local arg0 = 'update'
  29. local args = {}
  30. local func, args = cli:info(arg0, unpack(args))
  31.  
  32. print(arg0, ': ', func,': ',args, ' :: ', func(unpack(args)))
  33. print("\ndone.")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top