From 565d92b4910d45dbee96eae721770007b8260694 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Mon, 18 May 2026 14:29:46 +0200 Subject: [PATCH] add command tree --- README.md | 62 +++++++++++++++++++++++++++++++------------------- commandtree.sh | 31 +++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 23 deletions(-) create mode 100755 commandtree.sh diff --git a/README.md b/README.md index 0747d4c..d552de7 100644 --- a/README.md +++ b/README.md @@ -6,30 +6,46 @@ Elasticsearch CLI ## Usage +Command tree + ```console -NAME: - esctl - manage elasticsearch from cli - -USAGE: - esctl [global options] [command [command options]] - -VERSION: - v0.0.4 - -COMMANDS: - search, / search within an index - index, i manage indicies - snapshot, snap manage snapshots - cluster, c manage cluster[s] - node, snap manage nodes - help, h Shows a list of commands or help for one command - -GLOBAL OPTIONS: - --debug, -d enable debugging [$ES_DEBUG] - --config string, -c string config file [$ES_CONFIG] - --cluster string, -C string cluster alias to work with - --help, -h show help - --version, -v print the version + ccr + follower + add + delete + pause + renew + resume + show + unfollow + info + pause + resume + status + cluster + list + settings + list + set + status + doc + add + help + index + allocation + close + create + delete + list + show + node + list + show + repl + search + snapshot + list + show ``` Configure `esctl` with environment variables: diff --git a/commandtree.sh b/commandtree.sh new file mode 100755 index 0000000..fb8748b --- /dev/null +++ b/commandtree.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +getcommands() { + local command + command="$*" + + if ! test "$command" = "help"; then + ./esctl $command -h | sed -e '/^COMMANDS:/,/^$/!d;//d' -e 's/^ //' -e 's/[, ].*//' | sort + fi +} + +printcommands() { + local indent basecommand commands command + indent="$1" + basecommand="$2" + commands="$3" + + for command in $commands; do + echo "$indent" "$command" + + commands=$(getcommands $basecommand $command) + + if test -n "$commands"; then + printcommands "${indent} " "$basecommand $command" "$commands" + fi + done +} + + +commands=$(getcommands "") +printcommands "" "" "$commands"