Skip to content

Commit

Permalink
Introduce SemVer
Browse files Browse the repository at this point in the history
- Moved files that are used for configuration and aren't strictly programs to /cfg
- Moved libraries and programs that are necessary for running Allium, or libraries to /lib
- Added function `allium.verify` which compares a minimum, and maximum semver string to the current Allium version
- Added function `allium.getVersion` which returns a semver parsed table holding the version of a plugin
- Added `allium.version`, a parsed semver version to compare to
  • Loading branch information
hugeblank authored Mar 9, 2019
2 parents 6ac045d + 1f7a3d5 commit 713ea25
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 34 deletions.
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
repolist.csh
persistence.ltn
gitget.lua
debug.cfg
json
cfg/repolist.csh
cfg/persistence.ltn
cfg/debug.cfg
lib/semver.lua
lib/nap.lua
lib/json.lua
lib/gget.lua
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "raisin"]
path = raisin
path = lib/raisin
url = https://github.com/hugeblank/raisin
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ To install Allium, run this command, it's that simple!

The installer installs:

- The Allium Repo - allium.lua, plugins/allium-stem.lua, colors.lua, readme.md
- The latest Allium Repo - allium.lua, plugins/allium-stem.lua, colors.lua, readme.md

- The Raisin Repo - raisin/raisin.lua, raisin/readme.md

- Apemanzilla's [gitget](http://www.computercraft.info/forums2/index.php?/topic/17387-gitget-version-2-release/), a github repository downloader that is necessary to download Allium, and the plugins that can be installed.
- My [gget](https://github.com/hugeblank/qs-cc/tree/master/src/gget.lua), a github repository downloader that is necessary to download Allium, and the plugins that can be installed.

- repolist.csh - A _Craftos SHell_ file, where you can gitget various plugins and utilities and keep them up to date.

Expand All @@ -33,4 +33,4 @@ The installer installs:
It's worth noting that there are some places you might want to check out after you fork, and before you start testing your code.

1. The pastebin [installer](https://www.pastebin.com/LGwrkjxm). You are free to make your own installer to your fork with this code, simply change the `repo` string to "[your github username] [the name of your Allium repository] [the branch you want to clone from] [location]".
2. The startup file of your fork. Change the debug variable, and make sure to replace the marked line with your repo, like above.
2. The startup file of your fork. Set debug.cfg to true, and make sure to replace the marked line with your repo, like above.
50 changes: 38 additions & 12 deletions allium.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Allium by hugeblank

local version = "0.6.0"
local label = "<&r&dAll&5&h[[Hugeblank was here. Hi.]]&i[[https://www.youtube.com/watch?v=hjGZLnja1o8]]i&r&dum&r>" --bot title
local raisin, color = require("raisin.raisin"), require("color") --Sponsored by roger109z
local raisin, color, semver = require("lib.raisin.raisin"), require("lib.color"), require("lib.semver") -- color.lua sponsored by roger109z
local allium, plugins, group = {}, {}, {thread = raisin.group.add(1) , command = raisin.group.add(2)}

local function print(noline, ...) -- Magical function that takes in a table and changes the text color/writes at the same time
Expand Down Expand Up @@ -59,7 +59,7 @@ do -- Allium image setup <3
multishell.setTitle(multishell.getFocus(), "Allium")
term.clear()
local x, y = term.getSize()
paintutils.drawImage(paintutils.loadImage("allium.nfp"), x-7, 2) -- Draw the Allium image on the side
paintutils.drawImage(paintutils.loadImage("cfg/allium.nfp"), x-7, 2) -- Draw the Allium image on the side
local win = window.create(term.current(), 1, 1, x-9, y, true) -- Create a window to prevent text from writing over the image
term.redirect(win) -- Redirect the terminal
term.setCursorPos(1, 1)
Expand Down Expand Up @@ -173,11 +173,14 @@ allium.getName = function(plugin)
end
end

allium.register = function(p_name, fullname)
allium.register = function(p_name, version, fullname)
assert(type(p_name) == "string", "Invalid argument #1 (string expected, got "..type(p_name)..")")
local real_name = allium.sanitize(p_name)
assert(plugins[real_name] == nil, "Invalid argument #1 (plugin exists under name "..real_name..")")
plugins[real_name] = {threads = {}, commands = {}, name = fullname or p_name}
local version, rule = semver.parse(version)
if not rule then rule = "" end
assert(type(version) == "table", "Invalid argument #2 (malformed SemVer, breaks rule "..rule..")")
plugins[real_name] = {threads = {}, commands = {}, name = fullname or p_name, version = version}
local funcs = {}
local this = plugins[real_name]

Expand Down Expand Up @@ -208,8 +211,8 @@ allium.register = function(p_name, fullname)

funcs.getPersistence = function(name)
assert(type(name) ~= "nil", "Invalid argument #1 (expected anything but nil, got "..type(name)..")")
if fs.exists("persistence.ltn") then
local fper = fs.open("persistence.ltn", "r")
if fs.exists("cfg/persistence.ltn") then
local fper = fs.open("cfg/persistence.ltn", "r")
local tpersist = textutils.unserialize(fper.readAll())
fper.close()
if not tpersist[real_name] then
Expand All @@ -225,8 +228,8 @@ allium.register = function(p_name, fullname)
funcs.setPersistence = function(name, data)
assert(type(name) ~= "nil", "Invalid argument #1 (expected anything but nil, got "..type(name)..")")
local tpersist
if fs.exists("persistence.ltn") then
local fper = fs.open("persistence.ltn", "r")
if fs.exists("cfg/persistence.ltn") then
local fper = fs.open("cfg/persistence.ltn", "r")
tpersist = textutils.unserialize(fper.readAll())
fper.close()
end
Expand All @@ -235,7 +238,7 @@ allium.register = function(p_name, fullname)
end
if type(name) == "string" then
tpersist[real_name][name] = data
local fpers = fs.open("persistence.ltn", "w")
local fpers = fs.open("cfg/persistence.ltn", "w")
fpers.write(textutils.serialise(tpersist))
fpers.close()
return true
Expand Down Expand Up @@ -274,6 +277,29 @@ allium.register = function(p_name, fullname)
return funcs
end

allium.version = semver.parse(version)

allium.verify = function(min, max)
local smin, smax = min, max
local min, max = semver.parse(min), semver.parse(max)
if smin and not min then return false end
if smax and not max then return false end
if min and allium.version < min then
return false
end
if max and allium.version > max then
return false
end
return true
end

allium.getVersion = function(plugin)
assert(type(plugin) == "string", "Invalid argument #1 (string expected, got "..type(plugin)..")")
if plugins[plugin] then
return plugins[plugin].version
end
end

for _, side in pairs(peripheral.getNames()) do -- Finding the chat module
if peripheral.getMethods(side) then
for _, method in pairs(peripheral.getMethods(side)) do
Expand Down Expand Up @@ -437,8 +463,8 @@ end
raisin.thread.add(interpreter, 0)
raisin.thread.add(scanner, 1)

if not fs.exists("persistence.ltn") then --In the situation that this is a first installation, let's do some setup
local fpers = fs.open("persistence.ltn", "w")
if not fs.exists("cfg/persistence.ltn") then --In the situation that this is a first installation, let's do some setup
local fpers = fs.open("cfg/persistence.ltn", "w")
fpers.write("{}")
fpers.close()
end
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions plugins/allium-stem.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local stem = allium.register("allium", "Allium Stem (Core)")

assert(allium.verify("0.6.0", "0.6.0"), "This stem is for Allium version 0.6.0.")
local stem = allium.register("allium", "0.3.0", "Allium Stem")
local addDetails
do -- Just a block for organization of command parsing stuffs
local function infill(variant, execute)
Expand Down Expand Up @@ -210,7 +210,7 @@ local plugins = function(name)
local str = ""
local plugins = allium.getInfo()
for p_name in pairs(plugins) do
local p_str = "&h[[Tag: "..p_name.."]]"
local p_str = "&h[["..p_name.." v"..tostring(allium.getVersion(p_name)).."]]"
if plugins[p_name]["credits"] then
p_str = p_str.."&g[[!"..p_name..":credits]]"
end
Expand Down
28 changes: 18 additions & 10 deletions startup.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
multishell.setTitle(shell.openTab("shell"), "CraftOS")
shell.openTab("shell")
local debug = false
if fs.exists("debug.cfg") then
file = fs.open("debug.cfg", "r")
if fs.exists("cfg/debug.cfg") then
file = fs.open("cfg/debug.cfg", "r")
debug = load("return "..file.readAll())() -- for use when debugging, so auto-update script doesn't get triggered
file.close()
end
if not debug then
if fs.exists("repolist.csh") then -- Checking for a repolist shell executable
if fs.exists("cfg/repolist.csh") then -- Checking for a repolist shell executable
-- Update all plugins and programs on the repolist
for line in io.lines("repolist.csh") do
for line in io.lines("cfg/repolist.csh") do
shell.run(line)
end
else
-- Generate a repolist file
local file = fs.open("repolist.csh", "w")
file.write("gitget hugeblank Allium master /") --Forkers change this to their repository.
file.close()
printError("No valid repo file, default file created")
printError("No valid repo file found")
end
end
-- Installing some critical libraries if they aren't already
local libs = {
semver = "hugeblank/semparse/master/semver.lua",
gget = "hugeblank/qs-cc/master/src/gget.lua",
json = "rxi/json.lua/master/json.lua",
nap = "hugeblank/qs-cc/master/src/nap.lua"
}
for k, v in pairs(libs) do
if not fs.exists("/lib/"..k..".lua") then
shell.run("wget https://raw.github.com/"..v.." /lib/"..k..".lua")
end
end
-- Clearing the screen
Expand Down

0 comments on commit 713ea25

Please sign in to comment.