SHARE
    TWEET
    Krenair

    gist command for computercraft turtles

    Apr 28th, 2013
    178
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    Lua 1.13 KB | None | 0 0
    1. local function printUsage()
    2. print( "Usage: gist get <code> <filename>" )
    3. end
    4. local tArgs = { ... }
    5. if #tArgs < 2 then
    6. printUsage()
    7. return
    8. end
    9. if not http then
    10. print( "Gist requires http API" )
    11. print( "Set enableAPI_http to 1 in mod_ComputerCraft.cfg" )
    12. return
    13. end
    14. local sCommand = tArgs[1]
    15. if sCommand == "get" then
    16. -- Download a file from gist.github.com
    17. if #tArgs < 3 then
    18. printUsage()
    19. return
    20. end
    21. -- Determine file to download
    22. local sCode = tArgs[2]
    23. local sFile = tArgs[3]
    24. local sPath = shell.resolve( sFile )
    25. if fs.exists( sPath ) then
    26. print( "File already exists" )
    27. return
    28. end
    29. -- GET the contents from github
    30. print( "Connecting to gist.github.com... " )
    31. local response = http.get( "https://gist.github.com/"..sCode.."/raw" )
    32. print( "https://gist.github.com/"..sCode.."/raw" )
    33. if response then
    34. print( "Success." )
    35. local sResponse = response.readAll()
    36. response.close()
    37. local file = fs.open( sPath, "w" )
    38. file.write( sResponse )
    39. file.close()
    40. print( "Downloaded as "..sFile )
    41. else
    42. print( "Failed." )
    43. end
    44. else
    45. printUsage()
    46. return
    47. end
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /