git even gudder
This commit is contained in:
parent
c01b9304b9
commit
8485ae5f32
@ -18,19 +18,16 @@ fetch and exec file from repo
|
||||
if not http then error("http is not enabled") end
|
||||
|
||||
local function get(url)
|
||||
print("GET " .. url)
|
||||
local response, err = http.get(url)
|
||||
if not response then
|
||||
printError(err)
|
||||
return
|
||||
return nil, err
|
||||
end
|
||||
|
||||
local status, err = response.getResponseCode()
|
||||
if status ~= 200 then
|
||||
printError(status .. " " .. err)
|
||||
return nil, (status .. " " .. err)
|
||||
return
|
||||
end
|
||||
print(status .. " " .. err)
|
||||
|
||||
local result = response.readAll()
|
||||
response.close()
|
||||
@ -50,14 +47,19 @@ local function gitea_url(path)
|
||||
end
|
||||
|
||||
local function download_file(repo_path, local_path)
|
||||
local result = get(gitea_url(repo_path))
|
||||
write("Downloading " .. repo_path .. " as " .. local_path .. "... ")
|
||||
local result, err = get(gitea_url(repo_path))
|
||||
if not result then
|
||||
error("download failed")
|
||||
print()
|
||||
printError(err)
|
||||
return
|
||||
end
|
||||
|
||||
local f = fs.open(local_path, "w")
|
||||
f.write(result)
|
||||
f.close()
|
||||
|
||||
print("OK")
|
||||
end
|
||||
|
||||
-- keep track of downloaded files
|
||||
@ -79,11 +81,14 @@ end
|
||||
local args = {...}
|
||||
|
||||
if #args == 0 then
|
||||
print("Syncing " .. #storage .. " files.")
|
||||
|
||||
for local_path, repo_path in pairs(storage) do
|
||||
download_file(repo_path, local_path)
|
||||
end
|
||||
|
||||
print("Done.")
|
||||
|
||||
elseif args[1] == "sync" then
|
||||
local usage = "gitgud sync <repo path> <local path>"
|
||||
local repo_path = args[2] or error(usage)
|
||||
@ -114,9 +119,13 @@ elseif args[1] == "run" then
|
||||
|
||||
repo_path = ensure_dotlua(repo_path)
|
||||
|
||||
local result = get(gitea_url(repo_path))
|
||||
write("Downloading " .. repo_path .. "... ")
|
||||
local result, err = get(gitea_url(repo_path))
|
||||
if not result then
|
||||
error("download failed")
|
||||
print()
|
||||
printError(err)
|
||||
else
|
||||
print("OK")
|
||||
end
|
||||
|
||||
local func, err = load(result, repo_path, "t", _ENV)
|
||||
|
Loading…
Reference in New Issue
Block a user