SquidDev

Gistbin

Apr 11th, 2016
1,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. local function get(id, file)
  2.     local handle, message
  3.     print("Connecting to GitHub...")
  4.     if file then
  5.         handle, message = http.get("https://gist.githubusercontent.com/SquidDev/" .. id .. "/raw/" .. file)
  6.     else
  7.         handle, message = http.get("https://gist.githubusercontent.com/SquidDev/" .. id .. "/raw/")
  8.     end
  9.  
  10.     if not handle then error(message or "Unknown error", 0) end
  11.  
  12.     local contents = handle.readAll()
  13.     handle.close()
  14.  
  15.     return contents
  16. end
  17.  
  18. local command = ...
  19. if command == "get" then
  20.     local _, id, dest = ...
  21.     if not id then error("No id specified", 0) end
  22.  
  23.     local mainId, file = id:match("^([^/]+)/(.+)$")
  24.     dest = dest or file
  25.     if not dest then error("No destination specified", 0) end
  26.  
  27.     local contents = get(mainId or id, file)
  28.     local path = shell.resolve(dest)
  29.  
  30.     local handle = fs.open(path, "w")
  31.     if not handle then error("Cannot open " .. dest) end
  32.     handle.write(contents)
  33.     handle.close()
  34. elseif command == "run" then
  35.     local _, id = ...
  36.     if not id then error("No id specified", 0) end
  37.  
  38.     local mainId, file = id:match("^([^/]+)/(.+)$")
  39.     local contents = get(mainId or id, file)
  40.  
  41.     local func, msg = load(contents, file or id, nil, _ENV)
  42.     if not func then error(msg, 0) end
  43.  
  44.     func(select(3, ...))
  45. elseif not command then
  46.     error("Must specify command", 0)
  47. else
  48.     error("No such command: " .. command, 0)
  49. end
Advertisement
Add Comment
Please, Sign In to add comment