diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2024-03-13 10:47:20 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-03-13 15:31:33 +0000 |
| commit | effe66976ef2b48d51bca3584964bd7159a4f21f (patch) | |
| tree | 153e6124464fa7330f6b6a4043e578e6e8aa4972 /src | |
| parent | e3f067c6675a5a5d3a09b624c1783562f42719e1 (diff) | |
| download | luarocks-effe66976ef2b48d51bca3584964bd7159a4f21f.tar.gz luarocks-effe66976ef2b48d51bca3584964bd7159a4f21f.tar.bz2 luarocks-effe66976ef2b48d51bca3584964bd7159a4f21f.zip | |
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()
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/cmd/config.lua | 31 | ||||
| -rw-r--r-- | src/luarocks/config.lua | 36 | ||||
| -rw-r--r-- | src/luarocks/fs.lua | 38 |
4 files changed, 69 insertions, 42 deletions
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 @@ | |||
| 3 | local cmd = {} | 3 | local cmd = {} |
| 4 | 4 | ||
| 5 | local manif = require("luarocks.manif") | 5 | local manif = require("luarocks.manif") |
| 6 | local config = require("luarocks.config") | ||
| 6 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
| 7 | local path = require("luarocks.path") | 8 | local path = require("luarocks.path") |
| 8 | local cfg = require("luarocks.core.cfg") | 9 | local cfg = require("luarocks.core.cfg") |
| @@ -679,6 +680,11 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 679 | 680 | ||
| 680 | if args.verbose then | 681 | if args.verbose then |
| 681 | cfg.verbose = true | 682 | cfg.verbose = true |
| 683 | print(("-"):rep(79)) | ||
| 684 | print("Current configuration:") | ||
| 685 | print(("-"):rep(79)) | ||
| 686 | print(config.to_string(cfg)) | ||
| 687 | print(("-"):rep(79)) | ||
| 682 | fs.verbose() | 688 | fs.verbose() |
| 683 | end | 689 | end |
| 684 | 690 | ||
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 @@ | |||
| 3 | local config_cmd = {} | 3 | local config_cmd = {} |
| 4 | 4 | ||
| 5 | local persist = require("luarocks.persist") | 5 | local persist = require("luarocks.persist") |
| 6 | local config = require("luarocks.config") | ||
| 6 | local cfg = require("luarocks.core.cfg") | 7 | local cfg = require("luarocks.core.cfg") |
| 7 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
| 8 | local deps = require("luarocks.deps") | 9 | local deps = require("luarocks.deps") |
| @@ -82,28 +83,6 @@ local function config_file(conf) | |||
| 82 | end | 83 | end |
| 83 | end | 84 | end |
| 84 | 85 | ||
| 85 | local cfg_skip = { | ||
| 86 | errorcodes = true, | ||
| 87 | flags = true, | ||
| 88 | platforms = true, | ||
| 89 | root_dir = true, | ||
| 90 | upload_servers = true, | ||
| 91 | } | ||
| 92 | |||
| 93 | local function should_skip(k, v) | ||
| 94 | return type(v) == "function" or cfg_skip[k] | ||
| 95 | end | ||
| 96 | |||
| 97 | local function cleanup(tbl) | ||
| 98 | local copy = {} | ||
| 99 | for k, v in pairs(tbl) do | ||
| 100 | if not should_skip(k, v) then | ||
| 101 | copy[k] = v | ||
| 102 | end | ||
| 103 | end | ||
| 104 | return copy | ||
| 105 | end | ||
| 106 | |||
| 107 | local function traverse_varstring(var, tbl, fn, missing_parent) | 86 | local function traverse_varstring(var, tbl, fn, missing_parent) |
| 108 | local k, r = var:match("^%[([0-9]+)%]%.(.*)$") | 87 | local k, r = var:match("^%[([0-9]+)%]%.(.*)$") |
| 109 | if k then | 88 | if k then |
| @@ -147,7 +126,7 @@ local function print_entry(var, tbl, is_json) | |||
| 147 | end | 126 | end |
| 148 | local val = t[k] | 127 | local val = t[k] |
| 149 | 128 | ||
| 150 | if not should_skip(var, val) then | 129 | if not config.should_skip(var, val) then |
| 151 | if is_json then | 130 | if is_json then |
| 152 | return print_json(val) | 131 | return print_json(val) |
| 153 | elseif type(val) == "string" then | 132 | elseif type(val) == "string" then |
| @@ -402,12 +381,10 @@ function config_cmd.command(args) | |||
| 402 | end | 381 | end |
| 403 | end | 382 | end |
| 404 | 383 | ||
| 405 | local cleancfg = cleanup(cfg) | ||
| 406 | |||
| 407 | if args.json then | 384 | if args.json then |
| 408 | return print_json(cleancfg) | 385 | return print_json(config.get_config_for_display(cfg)) |
| 409 | else | 386 | else |
| 410 | print(persist.save_from_table_to_string(cleancfg)) | 387 | print(config.to_string(cfg)) |
| 411 | return true | 388 | return true |
| 412 | end | 389 | end |
| 413 | end | 390 | 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 @@ | |||
| 1 | local config = {} | ||
| 2 | |||
| 3 | local persist = require("luarocks.persist") | ||
| 4 | |||
| 5 | local cfg_skip = { | ||
| 6 | errorcodes = true, | ||
| 7 | flags = true, | ||
| 8 | platforms = true, | ||
| 9 | root_dir = true, | ||
| 10 | upload_servers = true, | ||
| 11 | } | ||
| 12 | |||
| 13 | function config.should_skip(k, v) | ||
| 14 | return type(v) == "function" or cfg_skip[k] | ||
| 15 | end | ||
| 16 | |||
| 17 | local function cleanup(tbl) | ||
| 18 | local copy = {} | ||
| 19 | for k, v in pairs(tbl) do | ||
| 20 | if not config.should_skip(k, v) then | ||
| 21 | copy[k] = v | ||
| 22 | end | ||
| 23 | end | ||
| 24 | return copy | ||
| 25 | end | ||
| 26 | |||
| 27 | function config.get_config_for_display(cfg) | ||
| 28 | return cleanup(cfg) | ||
| 29 | end | ||
| 30 | |||
| 31 | function config.to_string(cfg) | ||
| 32 | local cleancfg = config.get_config_for_display(cfg) | ||
| 33 | return persist.save_from_table_to_string(cleancfg) | ||
| 34 | end | ||
| 35 | |||
| 36 | 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 | |||
| 14 | local cfg = require("luarocks.core.cfg") | 14 | local cfg = require("luarocks.core.cfg") |
| 15 | 15 | ||
| 16 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end | 16 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end |
| 17 | local unpack = table.unpack or unpack | ||
| 18 | 17 | ||
| 19 | math.randomseed(os.time()) | 18 | math.randomseed(os.time()) |
| 20 | 19 | ||
| @@ -43,32 +42,41 @@ do | |||
| 43 | os.execute = function(cmd) | 42 | os.execute = function(cmd) |
| 44 | -- redact api keys if present | 43 | -- redact api keys if present |
| 45 | print("\nos.execute: ", (cmd:gsub("(/api/[^/]+/)([^/]+)/", function(cap, key) return cap.."<redacted>/" end)) ) | 44 | print("\nos.execute: ", (cmd:gsub("(/api/[^/]+/)([^/]+)/", function(cap, key) return cap.."<redacted>/" end)) ) |
| 46 | local code = pack(old_execute(cmd)) | 45 | local a, b, c = old_execute(cmd) |
| 47 | print("Results: "..tostring(code.n)) | 46 | if type(a) == "boolean" then |
| 48 | for i = 1,code.n do | 47 | print((a and ".........." or "##########") .. ": " .. tostring(c) .. (b == "exit" and "" or " (" .. tostring(b) .. ")")) |
| 49 | print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) | 48 | elseif type(a) == "number" then |
| 49 | print(((a == 0) and ".........." or "##########") .. ": " .. tostring(a)) | ||
| 50 | end | 50 | end |
| 51 | return unpack(code, 1, code.n) | 51 | return a, b, c |
| 52 | end | 52 | end |
| 53 | -- luacheck: pop | 53 | -- luacheck: pop |
| 54 | end | 54 | end |
| 55 | end | 55 | end |
| 56 | 56 | ||
| 57 | do | 57 | do |
| 58 | local skip_verbose_wrap = { | ||
| 59 | ["current_dir"] = true, | ||
| 60 | } | ||
| 61 | |||
| 58 | local function load_fns(fs_table, inits) | 62 | local function load_fns(fs_table, inits) |
| 59 | for name, fn in pairs(fs_table) do | 63 | for name, fn in pairs(fs_table) do |
| 60 | if name ~= "init" and not fs[name] then | 64 | if name ~= "init" and not fs[name] then |
| 61 | fs[name] = function(...) | 65 | if skip_verbose_wrap[name] then |
| 62 | if fs_is_verbose then | 66 | fs[name] = fn |
| 63 | local args = pack(...) | 67 | else |
| 64 | for i=1, args.n do | 68 | fs[name] = function(...) |
| 65 | local arg = args[i] | 69 | if fs_is_verbose then |
| 66 | local pok, v = pcall(string.format, "%q", arg) | 70 | local args = pack(...) |
| 67 | args[i] = pok and v or tostring(arg) | 71 | for i=1, args.n do |
| 72 | local arg = args[i] | ||
| 73 | local pok, v = pcall(string.format, "%q", arg) | ||
| 74 | args[i] = pok and v or tostring(arg) | ||
| 75 | end | ||
| 76 | print("fs." .. name .. "(" .. table.concat(args, ", ") .. ")") | ||
| 68 | end | 77 | end |
| 69 | print("fs." .. name .. "(" .. table.concat(args, ", ") .. ")") | 78 | return fn(...) |
| 70 | end | 79 | end |
| 71 | return fn(...) | ||
| 72 | end | 80 | end |
| 73 | end | 81 | end |
| 74 | end | 82 | end |
