Skip to content
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

local function printUsage()
print( "Usage:" )
print( "wget <url> <filename>" )
print( "wget <url> [filename]" )
end

local tArgs = { ... }
if #tArgs < 2 then
if #tArgs < 1 then
printUsage()
return
end
Expand All @@ -15,7 +15,12 @@ if not http then
printError( "Set http_enable to true in ComputerCraft.cfg" )
return
end


local function getFilename( sUrl )
sUrl = sUrl:gsub( "[#?].*" , "" ):gsub( "/+$" , "" )
return sUrl:match( "/([^/]+)$" ) or " "
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the or " " should be here or further down(See comment on line 52)

end

local function get( sUrl )
write( "Connecting to " .. sUrl .. "... " )

Expand Down Expand Up @@ -43,7 +48,7 @@ end

-- Determine file to download
local sUrl = tArgs[1]
local sFile = tArgs[2]
local sFile = tArgs[2] or getFilename(sUrl)
local sPath = shell.resolve( sFile )
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be replaced by shell.resolve( sFile or " ")

if fs.exists( sPath ) then
print( "File already exists" )
Expand Down