Skip to content

Commit 7932750

Browse files
committed
add now downloads programs
for libraries use require fix remove and remove all fir error on wrong scm argument 1
1 parent 40b8a92 commit 7932750

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Download SCM with the following command:
1515
# Commands
1616
**Note:** "From GitHub" usually refers to repositories within this project. "Script" refers to programs **and** libraries.
1717
## add
18-
- `<name>`: Downloads a library from GitHub. Libraries always have the suffix `-lib` ([Naming Conventions](https://github.com/mc-cc-scripts/.github/blob/master/profile/README.md#naming-conventions)). The suffix should not be added to the name.
19-
- `<name>@<pastebin code>`: Downloads a library from Pastebin.
20-
## get
2118
- `<name>`: Downloads a program from GitHub. Programs always have the suffix `-prog` ([Naming Conventions](https://github.com/mc-cc-scripts/.github/blob/master/profile/README.md#naming-conventions)). The suffix should not be added to the name.
2219
- `<name>@<pastebin code>`: Downloads a program from Pastebin.
20+
## require
21+
- `<name>`: Downloads a library from GitHub. Libraries always have the suffix `-lib` ([Naming Conventions](https://github.com/mc-cc-scripts/.github/blob/master/profile/README.md#naming-conventions)). The suffix should not be added to the name.
22+
- `<name>@<pastebin code>`: Downloads a library from Pastebin.
2323
## update
2424
By default, without parameters, `update` updates the SCM script.
2525
- `<name>`: Removes and downloads an installed script by name.

scm.lua

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@ scm.config = {
2626

2727
scm.scripts = {}
2828
scm.commands = {
29-
["add"] = {
29+
["require"] = {
3030
---@param args table
3131
func = function (args)
3232
scm:download(args[2], "library", nil)
3333
end,
3434
description = [[
3535
Adds a library with all its dependencies.
3636
If only a name is given, it will try to download from the official GitHub repositories.
37-
$ add <name>
38-
$ add <name>@<pastebinCode>
37+
$ require <name>
38+
$ require <name>@<pastebinCode>
3939
]]
4040
},
41-
["get"] = {
41+
["add"] = {
4242
---@param args table
4343
func = function (args)
4444
scm:download(args[2], "program", nil)
4545
end,
4646
description = [[
4747
Adds a program with all its dependencies.
4848
If only a name is given, it will try to download from the official GitHub repositories.
49-
$ get <name>
50-
$ get <name>@<pastebinCode>
49+
$ add <name>
50+
$ add <name>@<pastebinCode>
5151
]]
5252
},
5353
["update"] = {
@@ -404,22 +404,30 @@ function scm:removeScript (name)
404404

405405
if scriptType and fs.exists(self.config[scriptType .. "Directory"] .. name .. self.config[scriptType .. "Suffix"]) then
406406
fs.delete(self.config[scriptType .. "Directory"] .. name .. self.config[scriptType .. "Suffix"])
407-
if scriptType == "program" then
408-
fs.delete(name)
409-
elseif scriptType == "library" then
407+
if scriptType == "library" then
410408
fs.delete(self.config[scriptType .. "Directory"] .. name .. ".lua")
411409
end
412410
end
411+
412+
if scriptType == "program" then
413+
fs.delete(name)
414+
end
413415
end
414416

415417
function scm:removeAllScripts ()
418+
local tmpScripts = {}
416419
for i = 1, #self.scripts, 1 do
417-
self:removeScript(self.scripts[i].name)
420+
table.insert(tmpScripts, self.scripts[i].name)
421+
end
422+
423+
for i = 1, #tmpScripts, 1 do
424+
self:removeScript(tmpScripts[i])
418425
end
419426
end
420427

421428
---@param name string
422429
---@param sourceName string
430+
---@return boolean
423431
function scm:updateScript (name, sourceName)
424432
if not sourceName then sourceName = "default" end
425433

@@ -438,8 +446,12 @@ function scm:updateScript (name, sourceName)
438446
end
439447

440448
if updateObj.source[sourceName] and updateObj.type then
441-
self:download(updateObj.source[sourceName], updateObj.type, updateObj)
449+
self:removeScript(name)
450+
self:download(updateObj.source[sourceName], updateObj.type)
451+
return true
442452
end
453+
454+
return false
443455
end
444456

445457
function scm:updateAllScripts ()
@@ -530,7 +542,7 @@ end
530542

531543
---@param args table
532544
function scm:handleArguments (args)
533-
if args[1] then
545+
if args[1] and self.commands[args[1]] then
534546
self.commands[args[1]]["func"](args)
535547
end
536548
end

0 commit comments

Comments
 (0)