From 97fe37626973287fb0f744d03c9da1960258d407 Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Wed, 5 Aug 2015 04:34:42 +0300 Subject: [PATCH] Update github.lua --- Applications/github.lua | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/Applications/github.lua b/Applications/github.lua index 5b1321b1..e9c5e6b8 100644 --- a/Applications/github.lua +++ b/Applications/github.lua @@ -3,25 +3,31 @@ local internet = require("internet") local fs = require("filesystem") local seri = require("serialization") local shell = require("shell") +local config = require("config") local args, options = shell.parse(...) -if #args < 3 or string.lower(tostring(args[1])) == "help" then +local function printUsage() io.write("\nИспользование:") - io.write("github set <ссылка на репозиторий> - установить текущий репозиторий\n") + io.write("github set <ссылка на репозиторий> - установить указанный репозиторий в качестве постоянного\n") io.write("github get <ссылка> <путь сохранения> - загрузить указанный файл из текущего репозитория\n") io.write("github fast <ссылка на raw файл> <путь сохранения>- скачать файл без ебли мозгов\n\n") io.write(" Примеры:") - io.write(" github set <путь сохранения> - загрузить указанный файл из текущего репозитория\n") + io.write(" github set IgorTimofeev/OpenComputers\n") io.write(" github get Applications/Home.lua Home.lua\n") - io.write(" github fast Applications/Home.lua Home.lua\n") + io.write(" github fast IgorTimofeev/OpenComputers/master/Applications/Home.lua Home.lua\n") +end + +if #args < 3 or string.lower(tostring(args[1])) == "help" then + printUsage() return end local quiet = false -local ssilka, put = args[2], args[3] -if args[1] == "quiet" then quiet = true end +if args[1] == "fast" then quiet = true end +local pathToConfig = "System/GitHub/Repository.cfg" +local currentRepository local userUrl = "https://raw.githubusercontent.com/" --pastebin run SthviZvU IgorTimofeev/OpenComputers/master/Applications.txt hehe.txt @@ -44,8 +50,6 @@ local function getFromGitHub(url, path) return nil end - info(" ") - info("Успех!") info(" ") if result == "" or result == " " or result == "\n" then info("Файл пустой, либо ссылка неверная."); return end @@ -78,6 +82,26 @@ local function getFromGitHubSafely(url, path) return sRepos end +if args[1] == "set" then + if fs.exists(pathToConfig) then fs.remove(pathToConfig) end + fs.makeDirectory(fs.path(pathToConfig)) + config.write(pathToConfig, "currentRepository", args[2]) + currentRepository = args[2] + info("Текущий репозиторий изменен на "..currentRepository) +elseif args[1] == "get" then + if not fs.exists(pathToConfig) then + io.stderr:write("Текущий репозиторий не установлен. Используйте \"github set <путь>\".") + else + currentRepository = config.readAll(pathToConfig).currentRepository + getFromGitHubSafely(userUrl .. "/" .. currentRepository .. "/master/" .. args[2], args[3]) + end +elseif args[1] == "fast" then + +else + printUsage() + return +end + getFromGitHub(userUrl..ssilka, put)