diff options
author | garret <garret@airmail.cc> | 2022-11-20 06:46:03 +0000 |
---|---|---|
committer | garret <garret@airmail.cc> | 2022-11-20 06:46:03 +0000 |
commit | 20f4d8b86f47e59a8bd392ec2c37e4dd4c7b5e5e (patch) | |
tree | a0179afaa2e71e6b06f900c5c76d105e7c03b376 /make-feed.lua | |
parent | a9d756932b59ad74f4febc84a6f030453564d488 (diff) | |
download | depctrl-feedmaker-20f4d8b86f47e59a8bd392ec2c37e4dd4c7b5e5e.tar.gz depctrl-feedmaker-20f4d8b86f47e59a8bd392ec2c37e4dd4c7b5e5e.tar.bz2 depctrl-feedmaker-20f4d8b86f47e59a8bd392ec2c37e4dd4c7b5e5e.zip |
feedmaker: add io functions for stderr and file/stdio
Diffstat (limited to 'make-feed.lua')
-rwxr-xr-x | make-feed.lua | 15 |
1 files changed, 13 insertions, 2 deletions
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 |