diff options
| author | ruki <[email protected]> | 2020-01-17 22:15:32 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-01-17 22:15:32 +0800 |
| commit | a859e101ee88ec25fd948a08d2a02e7621241e7f (patch) | |
| tree | b6558e583ac20627222139a28f2c9c87c3af3c19 /xmake/core/base/utils.lua | |
| parent | ffce1ede94e7873e7ab248b05d468e84f6c205d0 (diff) | |
| parent | dc25ac7a87256a0470f523017ee790b29e9b6f2d (diff) | |
Merge pull request #667 from OpportunityLiu/options
Improve to parse command line options
Diffstat (limited to 'xmake/core/base/utils.lua')
| -rw-r--r-- | xmake/core/base/utils.lua | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index d85d1ecd9..dda5077d3 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -28,8 +28,9 @@ local string = require("base/string") local log = require("base/log") local io = require("base/io") local dump = require("base/dump") +local text = require("base/text") --- dump value +-- dump values function utils.dump(...) if option.get("quiet") then return ... @@ -42,32 +43,23 @@ function utils.dump(...) local info = debug.getinfo(2) local line = info.currentline if not line or line < 0 then line = info.linedefined end - io.write(string.format("dump form %s %s:%s\n", info.name or "<anonymous>", info.source, line)) + io.write(string.format("dump from %s %s:%s\n", info.name or "<anonymous>", info.source, line)) end local values = table.pack(...) if values.n == 0 then return end - local indent = nil - local values_count = values.n - values.n = nil - -- use last input as indent if it is a string - if values_count > 1 and type(values[values_count]) == "string" then - indent = values[values_count] - values[values_count] = nil - values_count = values_count - 1 - end - if values_count == 1 then - dump(values[1], indent or "", diagnosis) + if values.n == 1 then + dump(values[1], "", diagnosis) else - for i = 1, values_count do - dump(values[i], indent or string.format("%2d: ", i), diagnosis) + for i = 1, values.n do + dump(values[i], string.format("%2d: ", i), diagnosis) end end - return table.unpack(values, 1, values_count) + return table.unpack(values, 1, values.n) end -- print string with newline @@ -327,5 +319,13 @@ function utils.confirm(opt) return confirm end +function utils.table(data, opt) + utils.printf(text.table(data, opt)) +end + +function utils.vtable(data, opt) + utils.vprintf(text.table(data, opt)) +end + -- return module return utils |
