-- You can also find the program here:
-- http://pastebin.com/bKJZMvey
-- pastebin get bKJZMvey get
--(( Variables ))--
local url = "https://raw.github.com/jilleJr/ShopProg/master/"
local filename = ""
local extension = ".lua"
local savepath = ""
local args = {...}
--(( Functions ))--
local function color(fg,bg)
if term.isColor() then
if fg then term.setTextColor(fg) end
if bg then term.setBackgroundColor(bg) end
end
end
local function usage(text)
color(colors.red)
if text then print(text) end
local file = fs.getName(shell.getRunningProgram())
print("Usage: "..file.." <file> [save name]")
end
local function get(url)
local site = http.get(url)
if site then return site.readAll() end
end
local function save(content,path)
local file = fs.open(path,"w")
file.write(content)
file.close()
end
--(( Error handling ))--
if #args < 1 then
usage("Missing file")
return
end
filename = args[1]
savepath = args[2] or filename
--(( Main program ))--
color(colors.yellow)
write("Getting file ")
color(colors.orange)
write("'"..filename.."'")
color(colors.yellow)
print(" from github!")
print("Downloading...")
local content = get(url..filename..extension)
if content == nil then error("Failed!",0) end
color(colors.lime)
print("Success!")
color(colors.yellow)
write("Saving to file ")
color(colors.orange)
write("'"..savepath.."'")
color(colors.yellow)
print("...")
save(content,savepath)
color(colors.lime)
print("Done!")
--(( EOF ))--
Comments