Add help and a command for module type statistics.
Test: Presubmits (but none, really)
Change-Id: I12ef891cbb7b2ffadaf98a6da8bdc80e7005beee
diff --git a/json_module_graph/directDeps.jq b/json_module_graph/directDeps.jq
index b246671..9c82a8d 100644
--- a/json_module_graph/directDeps.jq
+++ b/json_module_graph/directDeps.jq
@@ -1,3 +1,5 @@
+# CMD: Returns the names of the direct dependencies of the module named $arg
+
include "library";
[.[] | select(.Name == $arg) | .Deps | map(.Name)] | flatten | unique | sort
\ No newline at end of file
diff --git a/json_module_graph/distanceFromLeaves.jq b/json_module_graph/distanceFromLeaves.jq
index 9a488dc..d48fa67 100644
--- a/json_module_graph/distanceFromLeaves.jq
+++ b/json_module_graph/distanceFromLeaves.jq
@@ -1,3 +1,5 @@
+# CMD: Returns the maximum distance from a leaf for each module
+
include "library";
def onlyDeps:
diff --git a/json_module_graph/filterSubtree.jq b/json_module_graph/filterSubtree.jq
index 9d5d6a2..16c9fcc 100644
--- a/json_module_graph/filterSubtree.jq
+++ b/json_module_graph/filterSubtree.jq
@@ -1,3 +1,5 @@
+# CMD: Returns modules defined under the directory $arg
+
include "library";
def isBlueprint($p): .Blueprint | index($p) != null
diff --git a/json_module_graph/fullTransitiveDeps.jq b/json_module_graph/fullTransitiveDeps.jq
index 1f982cf..1a5de21 100644
--- a/json_module_graph/fullTransitiveDeps.jq
+++ b/json_module_graph/fullTransitiveDeps.jq
@@ -1,3 +1,5 @@
+# CMD: Returns the modules in the transitive closure of module $arg
+
include "library";
[((moduleGraphNoVariants | removeSelfEdges) as $m |
diff --git a/json_module_graph/moduleTypeStats.jq b/json_module_graph/moduleTypeStats.jq
new file mode 100644
index 0000000..ef40a25
--- /dev/null
+++ b/json_module_graph/moduleTypeStats.jq
@@ -0,0 +1,15 @@
+# CMD: Returns a summary of the module types present on the input
+
+include "library";
+
+def moduleTypeStats($arg):
+ group_by(.Type) |
+ map({
+ Type: .[0].Type,
+ Count: map(.Name) | unique | length,
+ VariantCount: length,
+ }) |
+ sort_by(.Count)
+ ;
+
+moduleTypeStats($arg)
\ No newline at end of file
diff --git a/json_module_graph/modulesOfType.jq b/json_module_graph/modulesOfType.jq
index 849d76b..a28ffb4 100644
--- a/json_module_graph/modulesOfType.jq
+++ b/json_module_graph/modulesOfType.jq
@@ -1,3 +1,5 @@
+# CMD: Returns the names of modules of type $arg
+
include "library";
def modulesOfType($arg):
diff --git a/json_module_graph/printModule.jq b/json_module_graph/printModule.jq
index 7ef4fcc..194a0bd 100644
--- a/json_module_graph/printModule.jq
+++ b/json_module_graph/printModule.jq
@@ -1,3 +1,5 @@
+# CMD: Prints the module named $arg in a slightly more concise way
+
include "library";
def printModule($mod):
diff --git a/json_module_graph/query.sh b/json_module_graph/query.sh
index c720b5a..5ae4132 100755
--- a/json_module_graph/query.sh
+++ b/json_module_graph/query.sh
@@ -1,13 +1,25 @@
#!/bin/bash -eu
-JQARGS=""
+LIBDIR="$(dirname "$(readlink -f "$0")")"
function print_usage() {
echo "Usage: query.sh [-C] <command> <graph JSON> [argument]" 1>&2
echo " -C: colorized output" 1>&2
+ echo
+ echo "Commands":
+ for jq in "$LIBDIR"/*.jq; do
+ if ! grep -q "^# CMD:" "$jq"; then
+ continue
+ fi
+
+ local CMD="$(echo $(basename "$jq") | sed 's/\..*$//')"
+ echo " $CMD": $(cat "$jq" | grep "^# CMD:" | head -n 1 | sed 's/^# CMD://')
+ done
exit 1
}
+JQARGS=""
+
while getopts "C" arg; do
case "$arg" in
C)
@@ -16,6 +28,7 @@
;;
*)
print_usage
+ ;;
esac
done
@@ -32,6 +45,4 @@
ARG=""
fi
-LIBDIR="$(dirname "$(readlink -f "$0")")"
-
jq $JQARGS -L "$LIBDIR" -f "$LIBDIR/$COMMAND".jq "$GRAPH" --arg arg "$ARG"
diff --git a/json_module_graph/transitiveDeps.jq b/json_module_graph/transitiveDeps.jq
index c9a5e43..d0a55e5 100644
--- a/json_module_graph/transitiveDeps.jq
+++ b/json_module_graph/transitiveDeps.jq
@@ -1,3 +1,5 @@
+# CMD: Returns the names of the transitive dependencies of the module named $arg
+
include "library";
(moduleGraphNoVariants | removeSelfEdges) as $m |
diff --git a/json_module_graph/usedVariations.jq b/json_module_graph/usedVariations.jq
index f610443..7544358 100644
--- a/json_module_graph/usedVariations.jq
+++ b/json_module_graph/usedVariations.jq
@@ -1,3 +1,5 @@
+# CMD: Prints the set of variations and their values used in the input
+
[[.[] | .Variations | select(. != null) | to_entries] |
flatten |
group_by(.key) |
diff --git a/json_module_graph/variantTransitions.jq b/json_module_graph/variantTransitions.jq
index 1f0ddc4..ebf5756 100644
--- a/json_module_graph/variantTransitions.jq
+++ b/json_module_graph/variantTransitions.jq
@@ -1,3 +1,5 @@
+# CMD: Groups outgoing dependency edges by the differences in variants
+
include "library";
# This filters out modules with "interesting" deps