summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-04-20 22:37:26 +0800
committerruki <[email protected]>2026-04-20 22:37:26 +0800
commitd782aae00f82bd160b0fc5c0cdac1ba27ae8ade1 (patch)
tree17cfef203818daeb5ca86af19677440d4080cb3c
parent35d37f98381d8486f23b7761c90acdba3fc2e9d1 (diff)
add --format
-rw-r--r--tests/plugins/show/test.lua4
-rw-r--r--xmake/actions/require/xmake.lua4
-rw-r--r--xmake/modules/private/action/require/depgraph.lua4
-rw-r--r--xmake/modules/private/xrepo/action/info.lua4
-rw-r--r--xmake/plugins/show/info/basic.lua13
-rw-r--r--xmake/plugins/show/info/depgraph.lua17
-rw-r--r--xmake/plugins/show/info/target.lua19
-rw-r--r--xmake/plugins/show/xmake.lua16
8 files changed, 49 insertions, 32 deletions
diff --git a/tests/plugins/show/test.lua b/tests/plugins/show/test.lua
index 3e360a4d6..dea98c204 100644
--- a/tests/plugins/show/test.lua
+++ b/tests/plugins/show/test.lua
@@ -61,7 +61,7 @@ function test_depgraph_tree(t)
end
function test_depgraph_dot(t)
- local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--dot"})
+ local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--format=dot"})
t:require(outdata:find("digraph {", 1, true))
t:require(outdata:find('"core"', 1, true))
t:require(outdata:find('"ui" -> "core"', 1, true))
@@ -73,7 +73,7 @@ function test_depgraph_dot(t)
end
function test_depgraph_dot_for_single_target(t)
- local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--target=ui", "--dot"})
+ local outdata = os.iorunv("xmake", {"show", "--info=depgraph", "--target=ui", "--format=dot"})
t:require(outdata:find("digraph {", 1, true))
t:require(outdata:find('"core"', 1, true))
t:require(outdata:find('"ui" -> "core"', 1, true))
diff --git a/xmake/actions/require/xmake.lua b/xmake/actions/require/xmake.lua
index 3a0b15802..e1596da52 100644
--- a/xmake/actions/require/xmake.lua
+++ b/xmake/actions/require/xmake.lua
@@ -74,8 +74,8 @@ task("require")
"e.g.",
" $ xmake require --info --format=json zlib",
" $ xmake require --depgraph --format=dot libpng",
- "values: json (for --info/--depgraph), tree/dot (for --depgraph only)",
- values = {"tree", "json", "dot"} }
+ "values: json (for --info/--depgraph), dot (for --depgraph only)",
+ values = {"plain", "json", "dot"} }
, {nil, "check", "k", nil, "Check whether the given package is supported",
"e.g.",
" $ xmake require --check tbox" }
diff --git a/xmake/modules/private/action/require/depgraph.lua b/xmake/modules/private/action/require/depgraph.lua
index ba1fb9ff4..200d9ed3e 100644
--- a/xmake/modules/private/action/require/depgraph.lua
+++ b/xmake/modules/private/action/require/depgraph.lua
@@ -139,7 +139,7 @@ end
-- show the given package dependency graph
--
-- supported output formats (via --format):
--- tree (default): ASCII tree view
+-- plain (default): ASCII tree view
-- json: structured JSON output
-- dot: graphviz DOT format
--
@@ -164,7 +164,7 @@ function main(requires_raw)
local graph = _collect_package_graph(instances)
-- output in the specified format
- local format = option.get("format") or "tree"
+ local format = option.get("format") or "plain"
if format == "json" then
print(json.encode(graph, {pretty = true, orderkeys = true}))
elseif format == "dot" then
diff --git a/xmake/modules/private/xrepo/action/info.lua b/xmake/modules/private/xrepo/action/info.lua
index d7420533d..0a9c1c514 100644
--- a/xmake/modules/private/xrepo/action/info.lua
+++ b/xmake/modules/private/xrepo/action/info.lua
@@ -49,8 +49,8 @@ function menu_options()
"e.g.",
" - xrepo info --format=json zlib",
" - xrepo info --depgraph --format=dot libpng",
- "values: json (for --info/--depgraph), tree/dot (for --depgraph only)",
- values = {"tree", "json", "dot"}},
+ "values: json (for --info/--depgraph), dot (for --depgraph only)",
+ values = {"plain", "json", "dot"}},
{},
{nil, "packages", "vs", nil, "The packages list.",
"e.g.",
diff --git a/xmake/plugins/show/info/basic.lua b/xmake/plugins/show/info/basic.lua
index 4ad14fe98..8a29dc2c0 100644
--- a/xmake/plugins/show/info/basic.lua
+++ b/xmake/plugins/show/info/basic.lua
@@ -128,8 +128,13 @@ function main()
config.load()
+ -- support --format=json, with --json/--pretty backward compatibility
+ local format = option.get("format") or "plain"
+ if format == "plain" and option.get("json") then
+ format = "json"
+ end
local opt = {
- json = option.get("json"),
+ json = format == "json",
pretty = option.get("pretty")
}
local result = opt.json and {} or nil
@@ -138,9 +143,9 @@ function main()
result = _show_project_info(opt, result)
if opt.json then
- local json_opt
- if opt.pretty then
- json_opt = {pretty = true, orderkeys = true}
+ local json_opt = {pretty = true, orderkeys = true}
+ if option.get("json") and not option.get("pretty") then
+ json_opt = nil
end
print(json.encode(result or {}, json_opt))
end
diff --git a/xmake/plugins/show/info/depgraph.lua b/xmake/plugins/show/info/depgraph.lua
index e399a46df..2c73f3abc 100644
--- a/xmake/plugins/show/info/depgraph.lua
+++ b/xmake/plugins/show/info/depgraph.lua
@@ -139,14 +139,19 @@ function main(name)
end
local graph = _collect_target_graph(root_target)
- assert(not (option.get("json") and option.get("dot")), "--json and --dot are mutually exclusive")
- if option.get("json") then
- local json_opt
- if option.get("pretty") then
- json_opt = {pretty = true, orderkeys = true}
+
+ -- support --format=json/dot/plain, with --json/--pretty backward compatibility
+ local format = option.get("format") or "plain"
+ if format == "plain" and option.get("json") then
+ format = "json"
+ end
+ if format == "json" then
+ local json_opt = {pretty = true, orderkeys = true}
+ if option.get("json") and not option.get("pretty") then
+ json_opt = nil
end
print(json.encode(graph, json_opt))
- elseif option.get("dot") then
+ elseif format == "dot" then
_print_dot_graph(graph)
else
_print_target_graph(graph)
diff --git a/xmake/plugins/show/info/target.lua b/xmake/plugins/show/info/target.lua
index bfa88ad92..75f31f9a5 100644
--- a/xmake/plugins/show/info/target.lua
+++ b/xmake/plugins/show/info/target.lua
@@ -363,19 +363,22 @@ function main(name)
-- get target
config.load()
- local opt = {
- json = option.get("json"),
- pretty = option.get("pretty")
- }
+
+ -- support --format=json, with --json/--pretty backward compatibility
+ local format = option.get("format") or "plain"
+ if format == "plain" and option.get("json") then
+ format = "json"
+ end
+
assert(name, "please specify the target name, e.g. xmake show --info=target --target=xxx")
local target = assert(check_targetname(name))
local info = _collect_target_info(target)
- if opt.json then
+ if format == "json" then
info.api_entries = nil
- local json_opt
- if opt.pretty then
- json_opt = {pretty = true, orderkeys = true}
+ local json_opt = {pretty = true, orderkeys = true}
+ if option.get("json") and not option.get("pretty") then
+ json_opt = nil
end
print(json.encode(info or {}, json_opt))
else
diff --git a/xmake/plugins/show/xmake.lua b/xmake/plugins/show/xmake.lua
index 6d040da92..ef3ea0fe2 100644
--- a/xmake/plugins/show/xmake.lua
+++ b/xmake/plugins/show/xmake.lua
@@ -30,16 +30,20 @@ task("show")
return import("list").lists()
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."},
- {nil, "dot", "k", false, "Output dependency graph in graphviz DOT format (only for --info=depgraph)."},
+ {nil, "json", "k", false, "Show information with json format (deprecated, use --format=json)."},
+ {nil, "pretty", "k", false, "Enable pretty formatted output."},
+ {nil, "format", "kv", nil, "Set the output format.",
+ "e.g.",
+ " - xmake show --format=json",
+ " - xmake show --info=depgraph --format=dot",
+ "values: json (for all), dot (for --info=depgraph only)",
+ values = {"plain", "json", "dot"}},
{'i', "info", "kv", nil, "Show the given information.",
"e.g.",
" - xmake show --info=depgraph",
" - xmake show --info=depgraph --target=app",
- " - xmake show --info=depgraph --json --pretty",
- " - xmake show --info=depgraph --dot",
- "values:",
+ " - xmake show --info=depgraph --format=json",
+ " - xmake show --info=depgraph --format=dot",
values = function (complete, opt)
return import("list").infos()
end},