diff options
| author | ruki <[email protected]> | 2024-04-23 22:48:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-04-23 22:48:44 +0800 |
| commit | 458ca5e8a1dd6b073e8f5102ae0b105cfd40e0f4 (patch) | |
| tree | 55ea354ec1c4423f96fa63004982c3bdf2c2492b | |
| parent | 316c9cdee35d47e57219412d7ad39326966626c0 (diff) | |
show list with json
| -rw-r--r-- | xmake/plugins/show/showlist.lua | 16 | ||||
| -rw-r--r-- | xmake/plugins/show/xmake.lua | 5 |
2 files changed, 17 insertions, 4 deletions
diff --git a/xmake/plugins/show/showlist.lua b/xmake/plugins/show/showlist.lua index 923228e42..4e9c29c1e 100644 --- a/xmake/plugins/show/showlist.lua +++ b/xmake/plugins/show/showlist.lua @@ -21,9 +21,9 @@ -- imports import("core.base.option") import("core.base.text") +import("core.base.json") --- show values -function main(values) +function _show_text(values) local tbl = {align = 'l', sep = " "} local row = {} for _, value in ipairs(values) do @@ -38,3 +38,15 @@ function main(values) end print(text.table(tbl)) end + +function _show_json(values) + print(json.encode(json.mark_as_array(values))) +end + +function main(values) + if option.get("json") then + _show_json(values) + else + _show_text(values) + end +end diff --git a/xmake/plugins/show/xmake.lua b/xmake/plugins/show/xmake.lua index f652ed620..bae15471c 100644 --- a/xmake/plugins/show/xmake.lua +++ b/xmake/plugins/show/xmake.lua @@ -25,11 +25,12 @@ task("show") usage = "xmake show [options] [arguments]", description = "Show the given project information.", options = { - {'l', "list", "kv", nil, "Show the values list of the given name.", + {'l', "list", "kv", nil, "Show the values list of the given name.", values = function (complete, opt) return import("list").lists() end}, - {'t', "target", "kv", nil, "Show the information of the given target.", + {nil, "json", "k", false, "Show information with json format."}, + {'t', "target", "kv", nil, "Show the information of the given target.", values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end} |
