1
0
mirror of https://github.com/kepler155c/opus synced 2025-12-20 07:08:06 +00:00

pastebin rework round 3

This commit is contained in:
kepler155c@gmail.com
2019-04-12 08:33:41 -04:00
parent f011e7b14f
commit a77d55e33f
3 changed files with 157 additions and 135 deletions

View File

@@ -1,4 +1,3 @@
local function printUsage()
print( "Usages:" )
print( "pastebin put <filename>" )
@@ -6,12 +5,6 @@ local function printUsage()
print( "pastebin run <code> <arguments>" )
end
local tArgs = { ... }
if #tArgs < 2 then
printUsage()
return
end
if not http then
printError( "Pastebin requires http API" )
printError( "Set http_enable to true in ComputerCraft.cfg" )
@@ -20,9 +13,17 @@ end
local pastebin = require('http.pastebin')
local tArgs = { ... }
local sCommand = tArgs[1]
if sCommand == "put" then
-- Upload a file to pastebin.com
if #tArgs < 2 then
printUsage()
return
end
-- Determine file to upload
local sFile = tArgs[2]
local sPath = shell.resolve( sFile )
@@ -45,15 +46,18 @@ if sCommand == "put" then
elseif sCommand == "get" then
-- Download a file from pastebin.com
if #tArgs < 3 then
printUsage()
return
end
print( "Connecting to pastebin.com... " )
local sCode = pastebin.parseCode(tArgs[2])
if not sCode then
return false, "Invalid pastebin code. The code is the ID at the end of the pastebin.com URL."
end
-- Determine file to download
local sCode = tArgs[2]
local sFile = tArgs[3]
local sPath = shell.resolve( sFile )
if fs.exists( sPath ) then
@@ -61,21 +65,45 @@ elseif sCommand == "get" then
return
end
print( "Connecting to pastebin.com... " )
local resp, msg = pastebin.get(sCode, sPath)
if resp then
print( "Downloaded as "..resp )
print( "Downloaded as " .. sPath )
else
printError( msg )
end
elseif sCommand == "run" then
local sCode = tArgs[2]
-- Download and run a file from pastebin.com
if #tArgs < 2 then
printUsage()
return
end
local sCode = pastebin.parseCode(tArgs[2])
if not sCode then
return false, "Invalid pastebin code. The code is the ID at the end of the pastebin.com URL."
end
print( "Connecting to pastebin.com... " )
local resp, msg = pastebin.run(sCode, table.unpack(tArgs, 3))
if not resp then
local res, msg = pastebin.download(sCode)
if not res then
printError( msg )
return res, msg
end
res, msg = load(res, sCode, "t", _ENV)
if not res then
printError( msg )
return res, msg
end
res, msg = pcall(res, table.unpack(tArgs, 3))
if not res then
printError( msg )
end
else
@@ -83,3 +111,4 @@ else
printUsage()
return
end