From 8a6ef3bae525e04b4cf5f460edf5a8e49cf8928f Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Mon, 4 Mar 2024 19:25:28 +0100 Subject: [PATCH] less scary jq MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Théophane Hufschmitt <7226587+thufschmitt@users.noreply.github.com> --- tests/functional/help.sh | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/functional/help.sh b/tests/functional/help.sh index 74531c5d0..868f5d2e9 100644 --- a/tests/functional/help.sh +++ b/tests/functional/help.sh @@ -53,24 +53,14 @@ nix-prefetch-url --help function subcommands() { jq -r ' def recurse($prefix): - if .commands then - .commands | to_entries[] | .key as $k | - ($prefix + " " + $k) as $newPrefix | - if .value | has("commands") then - (.value | recurse($newPrefix)) + to_entries[] | + ($prefix + [.key]) as $newPrefix | + (if .value | has("commands") then + ($newPrefix, (.value.commands | recurse($newPrefix))) else $newPrefix - end - else - $prefix - end; - -.args.commands | to_entries[] | .key as $cmd | - if .value | has("commands") then - (.value | recurse($cmd)) - else - $cmd - end + end); +.args.commands | recurse([]) | join(" ") ' }