Here's one idea (called from within the clojure.tools.deps repo itself):
% clj -e "(require 'clojure.tools.cli.api)(->> (clojure.tools.cli.api/tree {:format :tree}) :children count prn)"
20
Didn't see a way to attach a patch, but here's one for completeness (though the change is pretty straightforward and simple).
From 7cc05b1913af8ee9982852fd618b775a1c339b0e Mon Sep 17 00:00:00 2001
From: Michael Glaesemann <grzm@seespotcode.net>
Date: Wed, 6 Apr 2022 07:28:28 -0500
Subject: [PATCH] Add :tree format option to cli.api/tree to return tree as
data.
----
src/main/clojure/clojure/tools/cli/api.clj | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git src/main/clojure/clojure/tools/cli/api.clj src/main/clojure/clojure/tools/cli/api.clj
index 931df53..96d8835 100644
--- src/main/clojure/clojure/tools/cli/api.clj
+++ src/main/clojure/clojure/tools/cli/api.clj
@@ -114,7 +114,7 @@
)
(defn tree
- "Print deps tree for the current project's deps.edn built from either the
+ "Return deps tree for the current project's deps.edn built from either the
a basis, or if provided, the trace file.
This program accepts the same basis-modifying arguments from the `basis` program.
@@ -122,7 +122,7 @@
Sources are merged in the order - :root, :user, :project, :extra.
By default, :format will :print to the console in a human friendly tree. Use
- :edn mode to print the tree to edn.
+ :edn mode to print the tree to edn. Use :tree mode to return the tree as data.
In print mode, deps are printed with prefix of either . (included) or X (excluded).
A reason code for inclusion/exclusion may be added at the end of the line.
@@ -138,7 +138,7 @@
:file Path to trace.edn file (from clj -Strace) to use in computing the tree
Output mode:
- :format :print (default) or :edn
+ :format :print (default), :edn (pretty-printed edn), or :tree (data)
Print output mode modifiers:
:indent Indent spacing (default = 2)
@@ -157,6 +157,7 @@
(case format
:print (tree/print-tree tree opts)
:edn (pprint/pprint tree)
+ :tree tree
(throw (ex-info (str "Unknown format " format) {}))))
(catch Throwable t
(printerrln "Error generating tree:" (.getMessage t))
--
2.32.0 (Apple Git-132)