Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function e(q)
- local j=setmetatable({},{__index=_ENV or getfenv()})if setfenv then setfenv(q,j)end;return q(j)or j end
- local t=e(function(q,...)
- local j={["\n"]="\\n",["\r"]="\\r",["\t"]="\\t",["\b"]="\\b",["\f"]="\\f",["\""]="\\\"",["\\"]="\\\\"}
- local x={['\n']=true,['r']=true,['\t']=true,[' ']=true,[',']=true,[':']=true}
- local function z(D)while x[D:sub(1,1)]do D=D:sub(2)end;return D end;local _
- local function E(D)if D:sub(1,4)=="true"then return true,z(D:sub(5))else
- return false,z(D:sub(6))end end;local function T(D)return nil,z(D:sub(5))end
- local A={['e']=true,['E']=true,['+']=true,['-']=true,['.']=true}
- local function O(D)local L=1
- while A[D:sub(L,L)]or tonumber(D:sub(L,L))do L=L+1 end;local U=tonumber(D:sub(1,L-1))D=z(D:sub(L))return U,D end
- local function I(D)local L,U=D:find('^".-[^\\]"')local C=D:sub(L+1,U-1)for M,F in pairs(j)do
- C=C:gsub(F,M)end;D=z(D:sub(U+1))return C,D end
- local function N(D)D=z(D:sub(2))local L={}local U=1;while D:sub(1,1)~="]"do local C=nil;C,D=_(D)L[U]=C
- U=U+1;D=z(D)end;D=z(D:sub(2))return L,D end;local function S(D)local L=nil;L,D=_(D)local U=nil;U,D=_(D)return L,U,D end
- local function H(D)
- D=z(D:sub(2))local L={}
- while D:sub(1,1)~="}"do local U,C=nil,nil;U,C,D=S(D)L[U]=C;D=z(D)end;D=z(D:sub(2))return L,D end
- function _(D)local L=D:sub(1,1)
- if L=="{"then return H(D)elseif L=="["then return N(D)elseif
- tonumber(L)~=nil or A[L]then return O(D)elseif D:sub(1,4)=="true"or D:sub(1,5)=="false"then
- return E(D)elseif L=="\""then return I(D)elseif D:sub(1,4)=="null"then return T(D)end;return nil end;local function R(D)D=z(D)t=_(D)return t end
- return function(D)local L=http.get(D)return L and
- R(L.readAll())end end)
- local a=e(function(q,...)
- local function j(z,_,E)
- local T='https://api.github.com/repos/'..z..'/git/trees/'.._..'?recursive=1'
- for A=1,E do local O=t(T)if O and O.tree then return O.tree end end;return nil end
- local function x(z,_,E,T,A)
- local O='https://raw.github.com/'..z..'/'.._..'/'local I={}local N=0;local S=0
- local function x(R)local D=R.path;local L;for U=1,T do local C=(O..D):gsub(' ','%%20')
- local M=http.get(C)
- if M then N=N+1;I[D]=M.readAll()A(true,D,R,N,S)return end end
- A(false,D,R,N,S)end;local H={}
- for R,D in ipairs(E)do if D.type=='tree'then I[D.path]=true else S=S+1
- H[S]=function()x(D)end end end;parallel.waitForAll(unpack(H))return I end;return{getTree=j,download=x}end)
- local o=e(function(q,...)local j=fs
- local x={["^"]="%^",["$"]="%$",["("]="%(",[")"]="%)",["%"]="%%",["."]="%.",["["]="%[",["]"]="%]",["*"]="%*",["+"]="%+",["-"]="%-",["?"]="%?",["\0"]="%z"}local function z(A)return(A:gsub(".",x))end
- local function _(A,O)return A==""or O==A or
- O:sub(1,#A+1)==A.."/"end
- local function E(A,O)if A==""then return O else return O:sub(#A+2)end end
- local function T(A)local O={}for I,N in pairs(A)do O[I]=N end;return O end
- return
- function(A,O)O=T(O)local I
- I={fs={list=function(N)N=j.combine(N,"")
- local S=j.isDir(N)and j.list(N)or{}if _(A,N)then local H="^"..z(E(A,N))if H~="^"then H=H..'/'end
- H=H..'([^/]+)$'
- for R,D in pairs(O)do local L=R:match(H)if L then S[#S+1]=L end end end
- return S end,exists=function(N)
- N=j.combine(N,"")
- if j.exists(N)then return true elseif _(A,N)then return O[E(A,N)]~=nil end end,isDir=function(N)
- N=j.combine(N,"")
- if j.isDir(N)then return true elseif _(A,N)then return O[E(A,N)]==true end end,isReadOnly=function(N)
- N=j.combine(N,"")if j.exists(N)then return j.isReadOnly(N)elseif _(A,N)and O[E(A,N)]~=nil then
- return true else return false end end,getName=j.getName,getDir=j.getDir,getSize=j.getSize,getFreespace=j.getFreespace,combine=j.combine,move=j.move,copy=j.copy,makeDir=function(N)
- end,delete=j.delete,open=function(N,S)N=j.combine(N,"")
- if _(A,N)then local H=E(A,N)
- if type(O[H])=='string'then
- local R={close=function()end}
- if S=='r'then local D=O[H]R.readAll=function()return D end;local L=1;local U
- R.readLine=function()if not U then
- U={D:match((D:gsub("[^\n]+\n?","([^\n]+)\n?")))}end;if L>#U then return nil else return U[L]end
- L=L+1 end;return R else error('Cannot write to read-only file.',2)end end end;return j.open(N,S)end},loadfile=function(N)
- local S=I.fs.open(N,"r")if S then local H,R=loadstring(S.readAll(),j.getName(N))
- S.close()return H,R end
- return nil,"File not found: "..N end,dofile=function(N)
- local S,H=I.loadfile(N)
- if S then setfenv(S,getfenv(2))return S()else error(H,2)end end}I._G=I;return I end end)local i=2;local n="master"local s=false;local h;local r,d;local l={...}local u,c=1,#l
- while u<=c do local q=l[u]
- if
- q=="--branch"or q=="-branch"or q=="-b"then u=u+1;n=l[u]elseif q=="--repo"or q==
- "-repo"or q=="-r"then u=u+1;d=l[u]elseif
- q=="--tries"or q=="-tries"then u=u+1;i=tonumber(l[u])
- if i==nil then
- error("Invalid number for tries: "..l[u],0)elseif i<=0 then error("Tries must be >= 1",0)end elseif q=="--once"then s=true elseif q=="--local"or q=="-l"then u=u+1;h=l[u]
- if h==nil then
- error("Invalid Howl path",0)else h=shell.resolve(h)if not fs.exists(h)then
- error("Cannot find Howl",0)end end elseif q=="--task"or q=="-task"or q=="-t"then u=u+1;r=l[u]elseif not d then d=q elseif not r then
- r=q else error("Unexpected argument "..q)end;u=u+1 end;while d==nil or d==""do write("Repo > ")d=read()end
- local m=a.getTree(d,n,i)if not m then
- error("Could not fetch tree. Does the repo/branch exist?",0)end;local f=false
- for q,j in ipairs(m)do if
- j.path=="Howlfile.lua"or j.path=="Howlfile"and j.type=="blob"then f=true;break end end;if not f then
- error("Cannot find a Howlfile. It must be in the root of the project",0)end
- local function w(m)local q={}
- write("Downloading...")
- local function j(x,z,_,E,T)if not x then q[#q+1]=_;local I,N=term.getCursorPos()
- term.setCursorPos(1,N)term.clearLine()
- printError("Cannot download "..z)end
- local A,O=term.getCursorPos()term.setCursorPos(1,O)term.clearLine()
- write(("Downloading: %s/%s (%s%%)"):format(E,T,
- E/T*100))end;local a=a.download(d,n,m,i,j)print()return a,q end;local y,p=w(m)
- while#p>0 do write("Failed to download. Retry? [y/n]")if
- read():sub(1,1):lower()=="y"then local q,j=w(p)p=j;for x,z in pairs(q)do y[x]=z end else
- error("Exiting",0)end end;local v={}do local q=y['.howl']
- if q then v=textutils.unserialize(q)if v==nil then
- error("Invalid format for .howl file",0)end end end;if not r then
- r=v.defaultTask end;local b=o(shell.dir(),y)local g
- if h then
- g=setfenv(assert(loadfile("/H")),setmetatable(b,{__index=_ENV}))else local q
- local j=v.howl or"http://pastebin.com/raw.php?i=uHRTm9hp"local x;if
- j:sub(1,7)=="http://"or j:sub(1,8)=="https://"then print("Downloading Howl...")x=http.get(j)else
- x=b.fs.open(j)end;if not x then error("Cannot find Howl at "..
- j,0)end
- q=x.readAll()x.close()
- g=assert(load(q,"Howl",nil,setmetatable(b,{__index=_ENV})))end
- local function k(q)local j={}local x=false;for z in(q.."\""):gmatch("(.-)\"")do if x then j[#j+1]=z else for _ in
- z:gmatch("[^ \t]+")do j[#j+1]=_ end end
- x=not x end;return j end;local l
- if r then l={r}else term.write("Task > ")l=k(read())end
- while true do local q,j=pcall(g,unpack(l))if not q then
- print("Running task failed:")printError(j)end;if s then break end
- term.write("Task > ")l=k(read())if#l==0 then break end end
Advertisement
Add Comment
Please, Sign In to add comment