diff options
author | Patrick Spek <p.spek@tyil.nl> | 2022-04-16 14:27:42 +0200 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2022-04-16 14:27:42 +0200 |
commit | f2f03d6ea4d6d181880a9f9c4f019d24065db4ec (patch) | |
tree | 7fc88e860cee41da90b78df50e5f8723e85eb30b /lib/main.bash | |
parent | d8a2f732b300cdbb892e0878fe87dbb7a0ef6d03 (diff) |
Initial draft for sync subcommand
Diffstat (limited to 'lib/main.bash')
-rw-r--r-- | lib/main.bash | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/main.bash b/lib/main.bash index 8075b59..ce41b92 100644 --- a/lib/main.bash +++ b/lib/main.bash @@ -50,7 +50,7 @@ main() { debug "$BASHTARD_NAME/main" "\$TMPDIR set to $TMPDIR" # Actually perform the subcommand - debug "$BASHTARD_NAME/main" "Running subcommand" + debug "$BASHTARD_NAME/main" "Running subcommand '$subcommand'" subcommand "$@" local subcommand_exit=$? @@ -66,6 +66,10 @@ main() { } usage() { + local playbooks + local playbook_length + local playbook_longest=0 + cat <<EOF Usage: $BASHTARD_NAME -h @@ -73,7 +77,7 @@ Usage: $BASHTARD_NAME bootstrap $BASHTARD_NAME del <playbook> $BASHTARD_NAME ssh <command> - $BASHTARD_NAME sync + $BASHTARD_NAME sync [playbook] $BASHTARD_NAME sysinfo Perform maintenance on your infra. @@ -89,6 +93,32 @@ Commands: Playbooks: EOF + + # Find all playbooks + mapfile -t playbooks < <(find \ + "$BASHTARD_ETCDIR/playbooks.d"/* \ + -maxdepth 0 \ + -type d \ + ) + + # Find longest playbook name + for playbook in "${playbooks[@]}" + do + playbook_length="$(printf "%s" "$(basename "$playbook")" | wc -c)" + + if (( playbook_longest < playbook_length )) + then + playbook_longest=$playbook_length + fi + done + + # Render playbook descriptions + for playbook in "${playbooks[@]}" + do + printf "\t%-${playbook_longest}s %s\n" \ + "$(basename "$playbook")" \ + "$(cat "$playbook/description.txt")" + done } # Discover information about the system. If any bugs are reported and you want |