From 6f5306ddaae3a14be5f385fa6f97546d6df9de4e Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 14 Jan 2020 18:06:16 -0300 Subject: fs: be verbose about builtin fs functions as well --- src/luarocks/fs.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index 672d8991..54891eac 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua @@ -18,11 +18,15 @@ local unpack = table.unpack or unpack math.randomseed(os.time()) +local fs_is_verbose = false + do local old_popen, old_execute -- patch io.popen and os.execute to display commands in verbose mode function fs.verbose() + fs_is_verbose = true + if old_popen or old_execute then return end old_popen = io.popen io.popen = function(one, two) @@ -52,7 +56,17 @@ do local function load_fns(fs_table, inits) for name, fn in pairs(fs_table) do if name ~= "init" and not fs[name] then - fs[name] = fn + fs[name] = function(...) + if fs_is_verbose then + local args = { ... } + for i, arg in ipairs(args) do + local pok, v = pcall(string.format, "%q", arg) + args[i] = pok and v or tostring(arg) + end + print("fs." .. name .. "(" .. table.concat(args, ", ") .. ")") + end + return fn(...) + end end end if fs_table.init then -- cgit v1.2.3-55-g6feb