From 20f4d8b86f47e59a8bd392ec2c37e4dd4c7b5e5e Mon Sep 17 00:00:00 2001 From: garret Date: Sun, 20 Nov 2022 06:46:03 +0000 Subject: feedmaker: add io functions for stderr and file/stdio --- make-feed.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'make-feed.lua') diff --git a/make-feed.lua b/make-feed.lua index 9de86eb..639e74f 100755 --- a/make-feed.lua +++ b/make-feed.lua @@ -55,6 +55,17 @@ local function get_iso8601_date(time) return os.date("%Y-%m-%d", time) end +local function output_writer(file) + local is_file, f = pcall(io.open, file, "w") + if is_file then return f end + return io.stdout +end + +local function err(msg) + if type(msg) == "table" then msg = inspect(msg) end + io.stderr:write(msg.."\n") +end + local function get_files(path) local files = {} for file in lfs.dir(path) do @@ -62,8 +73,8 @@ local function get_files(path) local absolute = clean_path(path, file) if file == "." or file == ".." then -- silently skip dir and 1-level-up dir elseif pcall(lfs.dir, absolute) then file = join_tables(files, get_files(absolute)) -- search recursively - elseif extension ~= "lua" then io.stderr:write(absolute .. ": not a lua file, skipping\n") - elseif not valid_namespace(name) then io.stderr:write(absolute .. ": invalid namespace, skipping\n") + elseif extension ~= "lua" then err(absolute .. ": not a lua file, skipping") + elseif not valid_namespace(name) then err(absolute .. ": invalid namespace, skipping") else table.insert(files, absolute) end end return files -- cgit v1.2.3-70-g09d2