aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md6
-rw-r--r--docs/configuration.md8
-rw-r--r--docs/guides/federation/getting-started.md6
-rw-r--r--share/bash-completion/completions/continuum-party241
4 files changed, 260 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7757bf6..b0cb8da 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,12 @@ it from the release before ([`docs/operations.md`](docs/operations.md),
## Unreleased
+* Bash completion for `continuum-party`, with the proposals, parties, places and
+ federations it finds
+ ([`share/bash-completion/completions/continuum-party`](share/bash-completion/completions/continuum-party);
+ [`docs/configuration.md`](docs/configuration.md),
+ [The party's client](docs/configuration.md#the-partys-client)).
+
* `continuum-party found` writes a federation's first version from its parties' keys,
node lists and rules
([`docs/guides/federation/getting-started.md`](docs/guides/federation/getting-started.md);
diff --git a/docs/configuration.md b/docs/configuration.md
index 1b7bd44..56c3347 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -278,3 +278,11 @@ continuum-party vote 8d02 yes # krebs, the only one
[Keys in an ssh-agent](guides/federation/keys.md#keys-in-an-ssh-agent)).
`node` and `token` are secrets: never logged, however they are given.
+
+[`share/bash-completion/completions/continuum-party`](../share/bash-completion/completions/continuum-party)
+completes the client's commands and options in bash: the federations by name, the
+revisions' features, and from the node it works with (the options given before the
+command), the proposals by hash, the parties and the places holding a value. Installed
+where bash-completion looks (`/usr/share/bash-completion/completions/`, or
+`~/.local/share/bash-completion/completions/`), it is read when first needed; else
+`source` it.
diff --git a/docs/guides/federation/getting-started.md b/docs/guides/federation/getting-started.md
index dc0eb25..6a0aec8 100644
--- a/docs/guides/federation/getting-started.md
+++ b/docs/guides/federation/getting-started.md
@@ -13,7 +13,11 @@ cargo build --release --features mycelium,federation
```
That builds the node, `continuum`, and the party's client, `continuum-party`, in
-`target/release/`. Any transport does ([`transports.md`](../../transports.md)).
+`target/release/`. Any transport does ([`transports.md`](../../transports.md)). Bash
+completes the client's commands, proposals and parties with
+`share/bash-completion/completions/continuum-party`
+([`configuration.md`](../../configuration.md),
+[The party's client](../../configuration.md#the-partys-client)).
## A key for each party
diff --git a/share/bash-completion/completions/continuum-party b/share/bash-completion/completions/continuum-party
new file mode 100644
index 0000000..e79eee2
--- /dev/null
+++ b/share/bash-completion/completions/continuum-party
@@ -0,0 +1,241 @@
+# bash completion for continuum-party, a party's client of a federation -*- shell-script -*-
+#
+# Completes its commands and options, and from the node it works with (the options given
+# before the command: --node, --federation, --config and the rest) the proposals on the
+# current version by hash, the parties, the places holding a value; the federations in
+# ~/.config/continuum/federations; and the revisions' features it knows.
+
+# The client, with the options given before the command, its errors left out.
+_continuum_party_asking()
+{
+ "${_continuum_party_client[@]}" "$@" 2>/dev/null
+}
+
+# The proposals on the current version, by hash.
+_continuum_party_proposals()
+{
+ _continuum_party_asking proposals | sed -n 's/^\([0-9a-f]\{64\}\): .*/\1/p'
+}
+
+# The parties of the current version.
+_continuum_party_parties()
+{
+ _continuum_party_asking status |
+ sed -n 's/^version .* passing a change (\(.*\))$/\1/p' | tr -d ','
+}
+
+# The places holding a value.
+_continuum_party_places()
+{
+ _continuum_party_asking values | cut -d' ' -f1
+}
+
+# The features of the revisions the client knows, as `--version` names them.
+_continuum_party_features()
+{
+ "${_continuum_party_client[0]}" --version 2>/dev/null |
+ grep -o '([a-z0-9-]*)' | tr -d '()'
+}
+
+# The federations, by their directories' names.
+_continuum_party_federations()
+{
+ local dir=${XDG_CONFIG_HOME:-$HOME/.config}/continuum/federations entry
+ [[ -d $dir ]] || return
+ for entry in "$dir"/*/; do
+ [[ -d $entry ]] || continue
+ entry=${entry%/}
+ printf '%s\n' "${entry##*/}"
+ done
+}
+
+# Files, or directories to find them in.
+_continuum_party_files()
+{
+ if declare -F _filedir >/dev/null; then
+ _filedir
+ else
+ COMPREPLY=($(compgen -f -- "$cur"))
+ fi
+}
+
+_continuum_party_words()
+{
+ COMPREPLY=($(compgen -W "$1" -- "$cur"))
+}
+
+_continuum_party()
+{
+ local cur prev words cword
+ if declare -F _init_completion >/dev/null; then
+ _init_completion -n =: || return
+ else
+ words=("${COMP_WORDS[@]}")
+ cword=$COMP_CWORD
+ cur=${words[cword]}
+ prev=${words[cword - 1]}
+ fi
+
+ local global_options='--node --token --key --record --federation --config --unset
+ --help --version'
+ local commands='init write keys nodes next propose vote again found root fork check
+ judge proposals show status values twice help'
+ local intents='admit remove give take keys nodes checkpoint revision'
+
+ # The command, the intent of `propose` and `fork`, and the arguments after them that
+ # are no options, as far as the word completed.
+ local i command= intent= word
+ local -a positional=()
+ _continuum_party_client=("${words[0]}")
+ for ((i = 1; i < cword; i++)); do
+ word=${words[i]}
+ if [[ -z $command ]]; then
+ case $word in
+ --node | --token | --key | --record | --federation | --config | --unset)
+ _continuum_party_client+=("$word" "${words[i + 1]}")
+ ((i++))
+ ;;
+ -*) _continuum_party_client+=("$word") ;;
+ *) command=$word ;;
+ esac
+ continue
+ fi
+ case $word in
+ --keys | --nodes | --at | --founder | --rule | --revision | --root | --add | \
+ --remove | --set)
+ # Options taking values: those up to the next option are theirs.
+ while ((i + 1 < cword)) && [[ ${words[i + 1]} != -* ]]; do
+ ((i++))
+ case $word in
+ --keys | --nodes | --at | --add | --remove | --set) ;;
+ *) break ;;
+ esac
+ done
+ ;;
+ -*) ;;
+ *)
+ if [[ -z $intent && ${#positional[@]} -eq 0 ]] &&
+ [[ $command == propose || $command == fork ]] &&
+ [[ " $intents proposal " == *" $word "* ]]; then
+ intent=$word
+ else
+ positional+=("$word")
+ fi
+ ;;
+ esac
+ done
+
+ # A value of the option before.
+ case $prev in
+ --federation)
+ _continuum_party_words "$(_continuum_party_federations)"
+ return
+ ;;
+ --key | --record | --config | --root | --keys)
+ _continuum_party_files
+ return
+ ;;
+ --revision)
+ _continuum_party_words "$(_continuum_party_features)"
+ return
+ ;;
+ --node | --token | --unset | --nodes | --founder | --rule | --at | --add | --remove | \
+ --set)
+ return
+ ;;
+ esac
+
+ if [[ -z $command ]]; then
+ if [[ $cur == -* ]]; then
+ _continuum_party_words "$global_options"
+ else
+ _continuum_party_words "$commands"
+ fi
+ return
+ fi
+
+ local n=${#positional[@]}
+ case $command in
+ propose | fork)
+ local own
+ if [[ $command == propose ]]; then
+ own='--yes --print'
+ else
+ own='--at --founder'
+ fi
+ if [[ -z $intent ]]; then
+ if [[ $cur == -* ]]; then
+ [[ $command == propose ]] && _continuum_party_words "$own"
+ elif ((n == 0)); then
+ local offered=$intents
+ [[ $command == fork ]] && offered="${intents/checkpoint/} proposal"
+ _continuum_party_words "$offered"
+ local -a named=("${COMPREPLY[@]}")
+ _continuum_party_files
+ COMPREPLY+=("${named[@]}")
+ fi
+ return
+ fi
+ case $intent in
+ admit) own+=' --keys --nodes' ;;
+ esac
+ if [[ $cur == -* ]]; then
+ _continuum_party_words "$own"
+ return
+ fi
+ case $intent:$n in
+ remove:0 | give:1 | keys:0 | nodes:0)
+ local parties
+ parties=$(_continuum_party_parties)
+ [[ $intent == give ]] && parties+=' {party}'
+ _continuum_party_words "$parties"
+ ;;
+ keys:*) _continuum_party_files ;;
+ revision:0) _continuum_party_words "$(_continuum_party_features)" ;;
+ proposal:0) _continuum_party_words "$(_continuum_party_proposals)" ;;
+ esac
+ ;;
+ vote)
+ if [[ $cur == -* ]]; then
+ _continuum_party_words '--through'
+ elif ((n == 0)); then
+ _continuum_party_words "$(_continuum_party_proposals)"
+ elif ((n == 1)); then
+ _continuum_party_words 'yes no'
+ fi
+ ;;
+ show)
+ ((n == 0)) && _continuum_party_words "$(_continuum_party_proposals)"
+ ;;
+ keys | nodes)
+ if [[ $cur == -* ]]; then
+ _continuum_party_words '--list --add --remove --set --force'
+ fi
+ ;;
+ write | values)
+ if [[ $cur == -* ]]; then
+ [[ $command == values ]] && _continuum_party_words '--json'
+ elif ((n == 0)); then
+ _continuum_party_words "$(_continuum_party_places)"
+ fi
+ ;;
+ init)
+ [[ $cur == -* ]] && _continuum_party_words '--root'
+ ;;
+ next)
+ [[ $cur == -* ]] && _continuum_party_words '--revision'
+ ;;
+ found)
+ [[ $cur == -* ]] && _continuum_party_words '--nodes --rule --revision'
+ ;;
+ root | check | twice)
+ _continuum_party_files
+ ;;
+ help)
+ ((n == 0)) && _continuum_party_words "$commands"
+ ;;
+ esac
+} &&
+ complete -F _continuum_party continuum-party
+
+# ex: filetype=sh