commit 3b9c9d7d4dc0f16ca35e411e9b8c7c1146600928
parent 062138c41ab5f6f81103133be7d6b084a1f441c3
Author: aabacchus <ben@bvnf.space>
Date: Tue, 13 Jun 2023 10:20:20 +0100
implement list
Diffstat:
4 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/README b/README
@@ -9,7 +9,7 @@ An implementation of the kiss package manager in Lua.
[ ] checksum
[ ] download
[ ] install
-[ ] list
+[x] list
[ ] remove
[x] search
[ ] update
diff --git a/bliss/init.lua b/bliss/init.lua
@@ -2,7 +2,7 @@ local cwd = (...):gsub('%.init$', '')
local M = {}
-local names = {'utils', 'search'}
+local names = {'utils', 'search', 'list'}
for i = 1, #names do
local name = names[i]
local t = require(cwd .. '.' .. name)
diff --git a/bliss/list.lua b/bliss/list.lua
@@ -0,0 +1,33 @@
+local cwd = (...):gsub('%.[^%.]+$', '')
+local utils = require(cwd .. '.utils')
+local dirent = require 'posix.dirent'
+
+local function pkg_version(env, pkg)
+ local v = env.pkg_db .. '/' .. pkg .. "/version"
+ local f = io.open(v, 'r')
+ if not f then utils.die("'"..pkg.."' not found") end
+ local ver = f:read()
+ f:close()
+ if not ver then utils.die(pkg, "error reading version") end
+ return utils.split(ver, ' ')
+end
+
+local function list(env, arg)
+ if #arg == 0 then
+ for file in dirent.files(env.pkg_db) do
+ if string.sub(file, 1, 1) ~= '.' then
+ table.insert(arg, file)
+ end
+ end
+ table.sort(arg)
+ end
+ for _,pkg in ipairs(arg) do
+ local ver = pkg_version(env, pkg)
+ io.write(string.format("%s %s-%s\n", pkg, ver[1], ver[2]))
+ end
+end
+
+local M = {
+ list = list,
+}
+return M
diff --git a/bliss/utils.lua b/bliss/utils.lua
@@ -58,7 +58,7 @@ end
function split(s, sep)
local c = {}
- for a in s:gmatch("[^%s"..sep.."]+") do
+ for a in string.gmatch(s, "[^%s"..sep.."]+") do
table.insert(c, a)
end
return c
@@ -110,6 +110,7 @@ end
local M = {
setup = setup,
+ split = split,
log = log,
warn = warn,
die = die,