Kagee

github

May 15th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. -- created by hildenae
  2. -- Public domain
  3.  
  4. if not http then
  5.   error("The Computercraft HTTP API is not enabled")
  6. end
  7.  
  8. function main(args)
  9.   if #args < 1 then
  10.     help()
  11.   elseif args[1] == "--update" then
  12.     update_self()  
  13.   elseif #args < 4  then
  14.     help()
  15.   else
  16.     local a=args
  17.     branch = "master"
  18.     if a[1] == "--branch" or a[1] == "-b" then
  19.       branch=a[2]
  20.       i=1
  21.       for key,value in pairs(args) do
  22.         if key > 2 then
  23.           a[i] = value
  24.           i=i+1
  25.         end
  26.       end
  27.     end
  28.     for path in string.gmatch(a[3], "[^,]+") do
  29.       download(a, branch, path)
  30.     end
  31.   end
  32. end
  33.  
  34. function download(args, branch, path)
  35.   print("Downloading " .. path)
  36.   url = "https://raw.github.com/"..args[1].."/"..args[2].."/"..branch.."/"..path
  37.   local content = http.get(url)
  38.   fs.delete(path)
  39.   local file = fs.open(path, "w")
  40.   file.write(content.readAll())
  41.   file.close()
  42. end
  43.  
  44. function update_self()
  45.   print("Will update self (master branch)")
  46.   download({"Kagee","cc"},"master", "github")
  47. end
  48.  
  49. function help()
  50.     print("Arguments:")
  51.     print("github <user> <repo> <path[s] separated by ,>")
  52.     print("--update script will update itself")
  53.     print("--branch <branch> as first arguments will download from <branch>")
  54.     error()
  55. end
  56.  
  57. main({...})
Advertisement
Add Comment
Please, Sign In to add comment