Skip to content

Instantly share code, notes, and snippets.

@JayWood
Created January 27, 2015 03:28
Show Gist options
  • Save JayWood/f2f379ffc29f7c660db3 to your computer and use it in GitHub Desktop.
Save JayWood/f2f379ffc29f7c660db3 to your computer and use it in GitHub Desktop.
local tArgs = { ... }
if (#tArgs ~= 3) then
print( "USAGE: gist get GIST_ID PROGRAM_NAME" )
return
end
local action = tArgs[1]
local gist_id = tArgs[2]
local program = tArgs[3]
if "get" ~= action then
print( "Only 'get' is supported right now" )
return
end
if fs.exists( program ) then
print( "File "..program.." already exists. No action taken" )
return
end
-- TODO: maybe handle multifile gists?
local gist_url = "https://gist.github.com/raw/" .. gist_id
local request = http.get( gist_url )
local response = request.readAll()
request.close()
local file = fs.open( program, "w" )
file.write( response )
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment