bliss

KISS in Lua
git clone git://bvnf.space/bliss.git
Log | Files | Refs | README | LICENSE

commit 062138c41ab5f6f81103133be7d6b084a1f441c3
parent eaa1ea5262b4ae3aed5d569906765aa886aa2993
Author: aabacchus <ben@bvnf.space>
Date:   Tue, 13 Jun 2023 00:28:59 +0100

implement search

Diffstat:
MREADME | 2+-
Mbliss/search.lua | 23+++++++++++++++++++----
2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/README b/README @@ -11,7 +11,7 @@ An implementation of the kiss package manager in Lua. [ ] install [ ] list [ ] remove -[ ] search +[x] search [ ] update [ ] upgrade [x] version diff --git a/bliss/search.lua b/bliss/search.lua @@ -1,14 +1,29 @@ local cwd = (...):gsub('%.[^%.]+$', '') local utils = require(cwd .. '.utils') +local glob = require 'posix.glob' +local sys_stat = require 'posix.sys.stat' local function search(env, arg) - -- prepend pkg_db to search path + -- append pkg_db to search path local path = utils.shallowcopy(env.PATH) - table.insert(path, 1, env.pkg_db) + table.insert(path, env.pkg_db) - for _, repo in ipairs(path) do - print(repo) + for _, a in ipairs(arg) do + local res = {} + for _, repo in ipairs(path) do + local g = glob.glob(repo .. '/' .. a, 0) + for _, i in pairs(g or {}) do + local sb = sys_stat.stat(i) + if sb and sys_stat.S_ISDIR(sb.st_mode) ~= 0 then + table.insert(res, i) + end + end + end + if #res == 0 then + utils.die("'"..a.."' not found") + end + for _, v in ipairs(res) do print(v) end end end