From effe66976ef2b48d51bca3584964bd7159a4f21f Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 13 Mar 2024 10:47:20 -0300 Subject: tweaks to --verbose output * Make output more informative for bug reports: * print `luarocks config` output at the top * Make output a bit more compact: * shorter output for os.execute * do not output fs.current_dir() --- src/luarocks/cmd.lua | 6 ++++++ src/luarocks/cmd/config.lua | 31 ++++--------------------------- src/luarocks/config.lua | 36 ++++++++++++++++++++++++++++++++++++ src/luarocks/fs.lua | 38 +++++++++++++++++++++++--------------- 4 files changed, 69 insertions(+), 42 deletions(-) create mode 100644 src/luarocks/config.lua (limited to 'src') diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 09468208..7e0abe59 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -3,6 +3,7 @@ local cmd = {} local manif = require("luarocks.manif") +local config = require("luarocks.config") local util = require("luarocks.util") local path = require("luarocks.path") local cfg = require("luarocks.core.cfg") @@ -679,6 +680,11 @@ function cmd.run_command(description, commands, external_namespace, ...) if args.verbose then cfg.verbose = true + print(("-"):rep(79)) + print("Current configuration:") + print(("-"):rep(79)) + print(config.to_string(cfg)) + print(("-"):rep(79)) fs.verbose() end diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua index 26d60f09..9c1911d6 100644 --- a/src/luarocks/cmd/config.lua +++ b/src/luarocks/cmd/config.lua @@ -3,6 +3,7 @@ local config_cmd = {} local persist = require("luarocks.persist") +local config = require("luarocks.config") local cfg = require("luarocks.core.cfg") local util = require("luarocks.util") local deps = require("luarocks.deps") @@ -82,28 +83,6 @@ local function config_file(conf) end end -local cfg_skip = { - errorcodes = true, - flags = true, - platforms = true, - root_dir = true, - upload_servers = true, -} - -local function should_skip(k, v) - return type(v) == "function" or cfg_skip[k] -end - -local function cleanup(tbl) - local copy = {} - for k, v in pairs(tbl) do - if not should_skip(k, v) then - copy[k] = v - end - end - return copy -end - local function traverse_varstring(var, tbl, fn, missing_parent) local k, r = var:match("^%[([0-9]+)%]%.(.*)$") if k then @@ -147,7 +126,7 @@ local function print_entry(var, tbl, is_json) end local val = t[k] - if not should_skip(var, val) then + if not config.should_skip(var, val) then if is_json then return print_json(val) elseif type(val) == "string" then @@ -402,12 +381,10 @@ function config_cmd.command(args) end end - local cleancfg = cleanup(cfg) - if args.json then - return print_json(cleancfg) + return print_json(config.get_config_for_display(cfg)) else - print(persist.save_from_table_to_string(cleancfg)) + print(config.to_string(cfg)) return true end end diff --git a/src/luarocks/config.lua b/src/luarocks/config.lua new file mode 100644 index 00000000..019b3885 --- /dev/null +++ b/src/luarocks/config.lua @@ -0,0 +1,36 @@ +local config = {} + +local persist = require("luarocks.persist") + +local cfg_skip = { + errorcodes = true, + flags = true, + platforms = true, + root_dir = true, + upload_servers = true, +} + +function config.should_skip(k, v) + return type(v) == "function" or cfg_skip[k] +end + +local function cleanup(tbl) + local copy = {} + for k, v in pairs(tbl) do + if not config.should_skip(k, v) then + copy[k] = v + end + end + return copy +end + +function config.get_config_for_display(cfg) + return cleanup(cfg) +end + +function config.to_string(cfg) + local cleancfg = config.get_config_for_display(cfg) + return persist.save_from_table_to_string(cleancfg) +end + +return config diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index ecfc5a28..a8156a21 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua @@ -14,7 +14,6 @@ package.loaded["luarocks.fs"] = fs local cfg = require("luarocks.core.cfg") local pack = table.pack or function(...) return { n = select("#", ...), ... } end -local unpack = table.unpack or unpack math.randomseed(os.time()) @@ -43,32 +42,41 @@ do os.execute = function(cmd) -- redact api keys if present print("\nos.execute: ", (cmd:gsub("(/api/[^/]+/)([^/]+)/", function(cap, key) return cap.."/" end)) ) - local code = pack(old_execute(cmd)) - print("Results: "..tostring(code.n)) - for i = 1,code.n do - print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) + local a, b, c = old_execute(cmd) + if type(a) == "boolean" then + print((a and ".........." or "##########") .. ": " .. tostring(c) .. (b == "exit" and "" or " (" .. tostring(b) .. ")")) + elseif type(a) == "number" then + print(((a == 0) and ".........." or "##########") .. ": " .. tostring(a)) end - return unpack(code, 1, code.n) + return a, b, c end -- luacheck: pop end end do + local skip_verbose_wrap = { + ["current_dir"] = true, + } + 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] = function(...) - if fs_is_verbose then - local args = pack(...) - for i=1, args.n do - local arg = args[i] - local pok, v = pcall(string.format, "%q", arg) - args[i] = pok and v or tostring(arg) + if skip_verbose_wrap[name] then + fs[name] = fn + else + fs[name] = function(...) + if fs_is_verbose then + local args = pack(...) + for i=1, args.n do + local arg = args[i] + local pok, v = pcall(string.format, "%q", arg) + args[i] = pok and v or tostring(arg) + end + print("fs." .. name .. "(" .. table.concat(args, ", ") .. ")") end - print("fs." .. name .. "(" .. table.concat(args, ", ") .. ")") + return fn(...) end - return fn(...) end end end -- cgit v1.2.3-55-g6feb