diff options
| author | ruki <[email protected]> | 2025-11-14 23:29:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-14 23:29:05 +0800 |
| commit | e4617488a56abbd89c24be114e8f7ae36da289e8 (patch) | |
| tree | 10e8023214ec25aad7065ba3004dc7c3a4bacfb0 /xmake/plugins | |
| parent | 31cab9106eeb43897e641ae80d5557d3b24c35f3 (diff) | |
enable pretty output for xmake show
Diffstat (limited to 'xmake/plugins')
| -rw-r--r-- | xmake/plugins/show/info/basic.lua | 11 | ||||
| -rw-r--r-- | xmake/plugins/show/info/target.lua | 11 | ||||
| -rw-r--r-- | xmake/plugins/show/showlist.lua | 6 | ||||
| -rw-r--r-- | xmake/plugins/show/xmake.lua | 1 |
4 files changed, 24 insertions, 5 deletions
diff --git a/xmake/plugins/show/info/basic.lua b/xmake/plugins/show/info/basic.lua index a08b47d3a..47b0f72e7 100644 --- a/xmake/plugins/show/info/basic.lua +++ b/xmake/plugins/show/info/basic.lua @@ -128,13 +128,20 @@ function main() config.load() - local opt = {json = option.get("json")} + local opt = { + json = option.get("json"), + pretty = option.get("pretty") + } local result = opt.json and {} or nil result = _show_xmake_info(opt, result) result = _show_project_info(opt, result) if opt.json then - print(json.encode(result or {})) + local json_opt + if opt.pretty then + json_opt = {pretty = true} + end + print(json.encode(result or {}, json_opt)) end end diff --git a/xmake/plugins/show/info/target.lua b/xmake/plugins/show/info/target.lua index e4787a8e2..9400ad2fe 100644 --- a/xmake/plugins/show/info/target.lua +++ b/xmake/plugins/show/info/target.lua @@ -360,13 +360,20 @@ function main(name) -- get target config.load() - local opt = {json = option.get("json")} + local opt = { + json = option.get("json"), + pretty = option.get("pretty") + } local target = assert(check_targetname(name)) local info = _collect_target_info(target) if opt.json then info.api_entries = nil - print(json.encode(info or {})) + local json_opt + if opt.pretty then + json_opt = {pretty = true} + end + print(json.encode(info or {}, json_opt)) else _print_target_info(info) end diff --git a/xmake/plugins/show/showlist.lua b/xmake/plugins/show/showlist.lua index 9dadb59c6..e82a3ab52 100644 --- a/xmake/plugins/show/showlist.lua +++ b/xmake/plugins/show/showlist.lua @@ -40,7 +40,11 @@ function _show_text(values) end function _show_json(values) - print(json.encode(values)) + local opt = {} + if option.get("pretty") then + opt.pretty = true + end + print(json.encode(values, opt)) end function main(values) diff --git a/xmake/plugins/show/xmake.lua b/xmake/plugins/show/xmake.lua index 475a771b8..331aeb468 100644 --- a/xmake/plugins/show/xmake.lua +++ b/xmake/plugins/show/xmake.lua @@ -31,6 +31,7 @@ task("show") end}, {'g', "group", "kv", nil, "Filter targets by the given group name."}, {nil, "json", "k", false, "Show information with json format."}, + {nil, "pretty", "k", false, "Enable pretty formatted json output."}, {'t', "target", "kv", nil, "Show the information of the given target.", values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) |
