Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function printUsage()
- print( "Usage:" )
- print( "dl <filename> [-e extension] [-s] [-i] [-r]" )
- end
- function getOpt(tArgs)
- local function isOption(text)
- --if text starts with a dash like "-something" consider it an option
- if (text == nil) or (string.sub(text, 0, 1) == "-") then
- return true
- else
- return false
- end
- end
- local opt = {}
- local i = 1
- while i <= #tArgs do
- if isOption(tArgs[i]) then
- if isOption(tArgs[i+1]) then
- --if no argument (no next arg or it's an option too)
- --interpret like options.something = true
- opt[string.sub(tArgs[i], 2)] = true
- else
- --interpret like options.something = value
- opt[string.sub(tArgs[i], 2)] = tArgs[i+1]
- i = i+1 --skip the next arg, it was the argument for -something
- end
- else
- --if not an option
- --aka a random arg, do options[number] = argument
- table.insert(opt, tArgs[i])
- end
- i = i+1
- end
- return opt
- end
- local tArgs = { ... }
- local options = getOpt(tArgs)
- local fileName = options[1]
- local extension = options.e
- if not extension then extension = "lua" end
- local file=http.get("http://wyvern67.free.fr/Minecraft/scripts/"..fileName.."."..extension)
- if not file then print("Url invalide") return false end
- local cFile = file.readAll()
- file.close()
- local fHandle = fs.open(fileName.."."..extension, "w")
- fHandle.write(cFile)
- fHandle.close()
- local action
- if options.i then
- if fs.exists("startup.lua") then
- fs.delete("startup.lua")
- action = " and startup overwritten"
- else
- action = " and startup written"
- end
- fHandle = fs.open("startup.lua", "w")
- if options.e then
- fHandle.writeLine('shell.run("dl", "' .. options[1] .. '", "-e", ' .. extension .. '"-s")')
- else
- fHandle.writeLine('shell.run("dl", "' .. options[1] .. '", "-s")')
- end
- fHandle.writeLine('shell.run("'..fileName.."."..extension..'")')
- fHandle.close()
- else
- action = ""
- end
- if options.s == nil then
- print("Downloaded as "..fileName.."."..extension..action)
- end
- if options.r then
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement