git even gudder

This commit is contained in:
Kai Vogelgesang 2020-07-07 04:27:58 +02:00
parent c01b9304b9
commit 8485ae5f32

View File

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