bliss

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

commit b2dc5a6e890d7d66a8b686a30250f2f0dcd24dea
parent 496e7524e0ddddbb543ff38113275eae9b156f08
Author: phoebos <ben@bvnf.space>
Date:   Fri, 16 Jun 2023 02:07:48 +0100

luacheck

Diffstat:
Mbliss/checksum.lua | 2+-
Mbliss/list.lua | 1-
Mbliss/pkg.lua | 1-
Mbliss/utils.lua | 33++++++++++++++++-----------------
Mmain.lua | 6+++---
5 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/bliss/checksum.lua b/bliss/checksum.lua @@ -46,7 +46,7 @@ local function checksum(env, arg) end end -local function verify_checksums(pkg, path) +local function verify_checksums(p, path) -- TODO end diff --git a/bliss/list.lua b/bliss/list.lua @@ -1,4 +1,3 @@ -local utils = require 'bliss.utils' local pkg = require 'bliss.pkg' local dirent = require 'posix.dirent' diff --git a/bliss/pkg.lua b/bliss/pkg.lua @@ -1,5 +1,4 @@ local utils = require 'bliss.utils' -local search = require 'bliss.search' local sys_stat = require 'posix.sys.stat' local function read_lines(file) diff --git a/bliss/utils.lua b/bliss/utils.lua @@ -4,7 +4,7 @@ local unistd = require 'posix.unistd' local signal = require 'posix.signal' local colors = {"", "", ""} -local setup, setup_colors, check_execute, get_available, trap_on, trap_off, split, mkdirp, rm_rf, log, warn, die, run, capture, shallowcopy +local setup, setup_colors, check_execute, get_available, get_pkg_clean, trap_on, trap_off, split, mkdirp, rm_rf, log, warn, die, run, capture, shallowcopy function setup() colors = setup_colors() @@ -77,7 +77,7 @@ function check_execute() end function get_available(...) - local x, p, res + local x, res for i = 1, select('#', ...) do x = select(i, ...) res = capture("command -v " .. x) @@ -86,6 +86,18 @@ function get_available(...) return nil end +-- returns a function with cached env so that it can be called without args or globals. +function get_pkg_clean(env) + return function () + if env.DEBUG ~= 0 then return end + if env._LVL == 1 then + rm_rf(env.proc) + else + rm_rf(env.tar_dir) + end + end +end + function trap_on(env) signal.signal(signal.SIGINT, function () os.exit(false) end) -- use a finalizer to get pkg_clean to run on EXIT. A reference to atexit must @@ -99,18 +111,6 @@ function trap_off(atexit) setmetatable(atexit, {}) end --- returns a function with cached env so that it can be called without args or globals. -function get_pkg_clean(env) - return function () - if env.DEBUG ~= 0 then return end - if env._LVL == 1 then - rm_rf(env.proc) - else - rm_rf(env.tar_dir) - end - end -end - function split(s, sep) local c = {} for a in string.gmatch(s, "[^%s"..sep.."]+") do @@ -165,8 +165,7 @@ end function run(cmd) io.stderr:write(cmd.."\n") -- faster to use fork + posix.unistd.execp? - local res, ty, code = os.execute(cmd) - return res + return os.execute(cmd) end -- Returns an array of lines printed by cmd @@ -182,7 +181,7 @@ end function shallowcopy(t) local u = {} for k,v in pairs(t) do u[k] = v end - return t + return u end local M = { diff --git a/main.lua b/main.lua @@ -22,7 +22,7 @@ local function usage() os.exit(true) end -local function args(arg) +local function args(env, arg) local args_map = { a = bliss.alternatives, b = bliss.build, @@ -58,5 +58,5 @@ local function args(arg) end end -env, atexit = bliss.setup() -args(arg) +local env, atexit = bliss.setup() +args(env, arg)