Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 30 spilt scm #32

Merged
merged 52 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
88bd38b
Issue-30 Require Issues
ChristophLHR Jul 19, 2023
ea5ac06
Issue-30 Fixed require
ChristophLHR Jul 21, 2023
40b1368
Issue 30 fixed require again
ChristophLHR Jul 21, 2023
9e70540
Issue-30 Fixed Requires
ChristophLHR Jul 22, 2023
27747e4
Issue-30 first working tests
ChristophLHR Jul 23, 2023
1019d22
Issue-30 Started Testing
ChristophLHR Aug 5, 2023
1a70277
Issue-30 Updated LuaAction Version
ChristophLHR Aug 5, 2023
b3e9833
Issue-30 Removed Terminal
ChristophLHR Aug 5, 2023
934f52c
Issue-30 luasocket
ChristophLHR Aug 5, 2023
489e329
Issue-30 MakeDir
ChristophLHR Aug 5, 2023
a07d7a5
Issue-30 OS.Day
ChristophLHR Aug 5, 2023
7714594
maybe fix https
ChristophLHR Aug 23, 2023
fa80cfc
ooof
ChristophLHR Aug 23, 2023
1434a81
ooooooooof
ChristophLHR Aug 23, 2023
224a1e7
oooooooooooooof
ChristophLHR Aug 23, 2023
2840ff7
lua does not rock
ChristophLHR Aug 23, 2023
7cdd586
try again
ChristophLHR Aug 23, 2023
d3705a2
daskos
ChristophLHR Aug 23, 2023
1f6029d
Issue-30 macht sinn!
ChristophLHR Aug 23, 2023
41abb8a
no
ChristophLHR Aug 23, 2023
ab670a6
ooko
ChristophLHR Aug 23, 2023
8db884f
dasd
ChristophLHR Aug 23, 2023
cae6b7d
sodu
ChristophLHR Aug 23, 2023
a545207
kik
ChristophLHR Aug 24, 2023
ba50f36
asdsa
ChristophLHR Aug 24, 2023
ce88296
asdas
ChristophLHR Aug 24, 2023
ccb017b
adsa
ChristophLHR Aug 24, 2023
627c753
dsds
ChristophLHR Aug 24, 2023
b7d781b
daisj
ChristophLHR Aug 24, 2023
c56afd6
Update test.yml
ColdIV Aug 27, 2023
4b536da
Update test.yml
ColdIV Aug 27, 2023
0a965ec
Update test.yml
ColdIV Aug 27, 2023
0047d16
Update test.yml
ColdIV Aug 27, 2023
fa959e5
Update test.yml
ColdIV Aug 27, 2023
e5f8320
Update test.yml
ColdIV Aug 27, 2023
8044844
Update test.yml
ColdIV Aug 27, 2023
d9f55ae
remove debug from test
ColdIV Aug 27, 2023
b4d3393
Small Fixes. Testsuit not working
ChristophLHR Dec 3, 2023
5d60eb5
Small Fixes. Testsuit not working
ChristophLHR Dec 3, 2023
6bcf9d6
Merge branch 'Issue-30-Spilt-SCM' of https://github.com/mc-cc-scripts…
ChristophLHR Dec 3, 2023
1388dff
Fixed autocomplete
ChristophLHR Dec 3, 2023
cb3cd8b
resolves Issue-33
ChristophLHR Dec 3, 2023
adec0a6
Fixed Testing - FileSystem
ChristophLHR Dec 3, 2023
d0fc8e6
HotFixes
ChristophLHR Dec 4, 2023
b55f597
Log function fixed
ChristophLHR Dec 4, 2023
73519b4
Added Files txt and Installer WIP
ChristophLHR Dec 7, 2023
04ec0d6
Updated Installer
ChristophLHR Dec 7, 2023
39d74f2
Removed downloadURL function
ChristophLHR Dec 7, 2023
ecc7cf9
removed redundant refresh
ChristophLHR Dec 7, 2023
f3ed4f2
remove old files
ChristophLHR Dec 7, 2023
39a8553
updated comments
ChristophLHR Dec 7, 2023
f49b5f6
Formatted Files
ChristophLHR Dec 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
return {
_all = {
coverage = false
},
default = {
verbose = true
},
apiUnit = {
tags = "api",
ROOT = {"tests"},
verbose = false
}
}
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Busted

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v2

- name: get lua
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "5.1"

- name: get luarocks
uses: leafo/gh-actions-luarocks@v4
with:
luaVersion: "5.1"

- name: get busted and luasocket
run: |
luarocks install busted
luarocks install luasocket
luarocks install luasec

- name: test
run: |
busted .
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
libs/
config/
TODO
7 changes: 7 additions & 0 deletions files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
scm.lua
/libs/scm/autocomplete.lua
/libs/scm/config.lua
/libs/scm/log.lua
/libs/scm/net.lua
/libs/scm/scriptManager.lua
/libs/scm/ui.lua
242 changes: 242 additions & 0 deletions libs/scm/autocomplete.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
---@class Autocomplete
local Autocomplete = {}
SCM.Autocomplete = Autocomplete

do
local log = function(...) SCM.Log:log(...) end
Autocomplete.commands = {
["require"] = {
---@param args table
func = function(args)
SCM.Net:download(args[2], "library", nil)
end,
description = [[
Adds a library with all its dependencies.
If only a name is given, it will try to download from the official GitHub repositories.
$ require <name>
$ require <name>@<pastebinCode>
]]
},
["add"] = {
---@param args table
func = function(args)
SCM.Net:download(args[2], "program", nil)
end,
description = [[
Adds a program with all its dependencies.
If only a name is given, it will try to download from the official GitHub repositories.
$ add <name>
$ add <name>@<pastebinCode>
]]
},
["update"] = {
---@param args table
func = function(args)
if args[2] == "all" then
SCM.ScriptManager:updateAllScripts()
elseif args[3] then
SCM.ScriptManager:updateScript(args[2], args[3])
elseif args[2] then
SCM.ScriptManager:updateScript(args[2], nil)
else
SCM.Net:updateSCM()
end
end,
description = [[
$ update
Updates this program (SCM)
$ update <name>
Updates the script with the given name
$ update all
Updates all installed programs and libraries
$ update <name> <srcName>
Updates the script with an specific source
]]
},
["remove"] = {
---@param args table
func = function(args)
if args[2] == "all" then
SCM.ScriptManager:removeAllScripts()
else
SCM.ScriptManager:removeScript(args[2])
end
end,
description = [[
$ remove <name>
Removes the given script
$ remove all
Removes all scripts
]]
},
["list"] = {
---@param _ table
func = function(_)
SCM.UI:listScripts()
end,
description = [[
$ list
Lists all installed scripts
]]
},
["config"] = {
---@param args table
func = function(args)
if args[3] then
SCM.Config:updateConfig(args[2], args[3])
elseif args[2] then
if SCM.Config.getAll(SCM.Config)[args[2]] ~= nil then
print(args[2], tostring(SCM.Config.getAll(SCM.Config)[args[2]]))
end
else
print("You can currently configure the following variables:")
for cname, cvalue in pairs(SCM.Config.getAll(SCM.Config)) do
textutils.pagedPrint(cname .. "\t" .. tostring(cvalue))
end
end
end,
description = [[
$ config
Lists all available configurations
$ config <name>
Shows a specific configuration
$ config <name> <value>
Updates the configuration
]]
},
["refresh"] = {
func = function(args)
SCM.Autocomplete:refreshAutocomplete()
end,
description = [[
$ refresh
Downloads the names of all programs and libraries of the official repository.
Refreshes autocomplete.
]]
},
["help"] = {
---@param args table
func = function(args)
if args[2] then
if SCM.Autocomplete.commands[args[2]] then
textutils.pagedPrint(args[2] .. "\n" .. SCM.Autocomplete.commands[args[2]]["description"])
end
else
for k, v in pairs(SCM.Autocomplete.commands) do
textutils.pagedPrint("# " .. k .. "\n" .. v.description)
end
end
end,
description = [[
$ help
Shows all available commands and their description
$ help <name>
Shows the description of the given command
]]
}
}

function Autocomplete:addScriptToAutoComplete(source)
self.commands["update"]["args"] = self.commands["update"]["args"] or {}
self.commands["remove"]["args"] = self.commands["remove"]["args"] or {}
self.commands["update"]["args"][source.name] = {}
self.commands["remove"]["args"][source.name] = {}
end

function Autocomplete:prepareAutocomplete()
-- prepare update and remove
SCM.ScriptManager:loadScripts()
local installedScripts = {}
for i = 1, #SCM.ScriptManager.scripts, 1 do
installedScripts[SCM.ScriptManager.scripts[i].name] = {}
end
installedScripts["all"] = {}

self.commands["update"]["args"] = installedScripts
self.commands["remove"]["args"] = installedScripts

-- prepare add and require
SCM.Net:loadRepoScripts()

-- prepare config
local availableConfigs = {}

for k, _ in pairs(SCM.Config:getAll()) do
availableConfigs[k] = {}
end

self.commands["config"]["args"] = availableConfigs

-- prepare help
local availableCommands = {}

for k, _ in pairs(self.commands) do
availableCommands[k] = {}
end

self.commands["help"]["args"] = availableCommands
end

---@param shell table
---@param index integer
---@param argument string
---@param previous table
---@return table | nil
local function completionFunction(shell, index, argument, previous)
local commands = {}
for k, _ in pairs(Autocomplete.commands) do
commands[k] = Autocomplete.commands[k]["args"] or {}
end

local currArg = commands
for i = 2, #previous do
if currArg[previous[i]] then
currArg = currArg[previous[i]]
else
return nil
end
end

local results = {}
for word, _ in pairs(currArg) do
if word:sub(1, #argument) == argument then
results[#results + 1] = word:sub(#argument + 1)
end
end
return results;
end

function Autocomplete:updateAutocomplete()
shell.setCompletionFunction("scm.lua", completionFunction)
end

function Autocomplete:refreshAutocomplete()
SCM.Net:refreshRepoScripts()
self:prepareAutocomplete()
self:updateAutocomplete()
end

---@param t table
function Autocomplete:setPrograms(t)
self.commands["add"]["args"] = t
end

---@param t table
function Autocomplete:setLibaries(t)
self.commands["require"]["args"] = t
end

function Autocomplete:handleArguments(args)
if #args == 0 then
SCM.UI:cli(false, args)
return
end

if args[1] and self.commands[args[1]] then
self.commands[args[1]]["func"](args)
if SCM.Config.config["cliPrefix"] then
shell.run(read(nil, nil, shell.complete, "scm "))
end
end
end
end
Loading
Loading