sollaires

gist.lua

Feb 2nd, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.65 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if (#tArgs ~= 3) then
  4.   print( "USAGE: gist get GIST_ID PROGRAM_NAME" )
  5.   return
  6. end
  7.  
  8. local action = tArgs[1]
  9. local gist_id = tArgs[2]
  10. local program = tArgs[3]
  11.  
  12. if "get" ~= action then
  13.   print( "Only 'get' is supported right now" )
  14.   return
  15. end
  16.  
  17. if fs.exists( program ) then
  18.   print( "File "..program.." already exists.  No action taken" )
  19.   return
  20. end
  21.  
  22. -- TODO: maybe handle multifile gists?
  23. local gist_url = "https://gist.github.com/raw/" .. gist_id
  24.  
  25. local request = http.get( gist_url )
  26. local response = request.readAll()
  27. request.close()
  28.  
  29. local file = fs.open( program, "w" )
  30. file.write( response )
  31. file.close()
Add Comment
Please, Sign In to add comment