[latex3-commits] [latex3/l3sys-query] 2e: make glob conversion write to stderr not stdout (cbcd91f)
github at latex-project.org
github at latex-project.org
Mon Mar 11 11:22:23 CET 2024
Repository : https://github.com/latex3/l3sys-query
On branch : 2e
Link : https://github.com/latex3/l3sys-query/commit/cbcd91fd12c9c028f7de8a44ee1b0edd9d786c3b
>---------------------------------------------------------------
commit cbcd91fd12c9c028f7de8a44ee1b0edd9d786c3b
Author: David Carlisle <d.p.carlisle at gmail.com>
Date: Mon Mar 11 09:19:53 2024 +0000
make glob conversion write to stderr not stdout
>---------------------------------------------------------------
cbcd91fd12c9c028f7de8a44ee1b0edd9d786c3b
l3sys-query.lua | 35 ++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/l3sys-query.lua b/l3sys-query.lua
index 55719bd..b401f07 100755
--- a/l3sys-query.lua
+++ b/l3sys-query.lua
@@ -137,7 +137,7 @@ local sort = table.sort
-- Support functions and data
--
--- Remove '...' or :...: around an entire text:
+-- Remove '...' around an entire text:
-- we need this to support restricted shell escape on Windows
local function dequote(text)
if (match(text,"^'") and match(text,"'$")) then
@@ -146,6 +146,13 @@ local function dequote(text)
return text
end
+
+-- A short auxiliary used whever the script bails out
+local function info_and_quit(s)
+ stderr:write("\n" .. s .. "\nTry '" .. script_name .. " --help' for more information.\n")
+ exit(1)
+end
+
-- Convert a file glob into a pattern for use by e.g. string.gub
-- Based on https://github.com/davidm/lua-glob-pattern
-- Simplified substantially: "[...]" syntax not supported as is not
@@ -185,7 +192,7 @@ local function glob_to_pattern(glob,skip_convert)
pattern = pattern .. ".*"
elseif char == "[" then -- ]
-- Ignored
- print("[...] syntax not supported in globs!")
+ info_and_quit("[...] syntax not supported in globs!")
elseif char == "\\" then
i = i + 1
char = sub(glob,i,i)
@@ -201,11 +208,6 @@ local function glob_to_pattern(glob,skip_convert)
return pattern
end
--- A short auxiliary used whever the script bails out
-local function more_info()
- stderr:write("Try '" .. script_name .. " --help' for more information.\n")
- exit(1)
-end
-- Initial data for the command line parser
local cmd = ""
@@ -298,22 +300,19 @@ local function parse_args()
if option_list[optname].type == "boolean" then
if optarg then
local opt = "-" .. (match(a,"^%-%-") and "-" or "") .. opt
- stderr:write("Value not allowed for option " .. opt .. "\n")
- more_info()
+ info_and_quit("Value not allowed for option " .. opt)
end
else
if not optarg then
optarg = arg[i + 1]
if not optarg then
- stderr:write("Missing value for option " .. a .. "\n")
- more_info()
+ info_and_quit("Missing value for option " .. a)
end
i = i + 1
end
end
else
- stderr:write("Unknown option " .. a .. "\n")
- more_info()
+ info_and_quit("Unknown option " .. a)
end
-- Store the result
@@ -533,9 +532,8 @@ elseif not cmd_impl[cmd] then
if cmd == "" then
help()
else
- stderr:write(script_name .. ": '" .. cmd .. "' is not a " .. script_name ..
- " command.\n")
- more_info()
+ info_and_quit(script_name .. ": '" .. cmd .. "' is not a " .. script_name ..
+ " command.")
end
exit(1)
end
@@ -555,9 +553,8 @@ for k,_ in pairs(options) do
t[v] = true
end
if not t[cmd] then
- stderr:write(script_name .. ": Option '" .. k ..
- "' does not apply to '" .. cmd .. "'\n")
- more_info()
+ info_and_quit(script_name .. ": Option '" .. k ..
+ "' does not apply to '" .. cmd .. "'")
end
end
end
More information about the latex3-commits
mailing list.