Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic tab completion #18

Merged
merged 1 commit into from
Oct 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion oc-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function list {

function error_exit() {
echo -e "$@"
exit 1
exit 1
}

function deploy-nexus {
Expand Down Expand Up @@ -248,6 +248,43 @@ rm /tmp/pv.yaml
echo "Volume created in ${__path}"
}

function completion() {
local shell=$1
[[ $shell != "bash" ]] && echo "Only bash supported for now" && return
cat << "EOF"
OPENSHIFT_HOME_DIR=${OPENSHIFT_HOME:-$HOME/.oc}
_oc_cluster_completion() {
local cur prev command commands profiles cluster_args
COMPREPLY=() # Array variable storing the possible completions.
cur=${COMP_WORDS[COMP_CWORD]}
prev="${COMP_WORDS[COMP_CWORD-1]}"
command="${COMP_WORDS[1]}"
commands="up down destroy list status ssh console create-volume create-shared-volume deploy-nexus"

profiles=$(ls -d $OPENSHIFT_HOME_DIR/profiles/*/ | xargs -L1 basename)

boolean_args="--create-machine= --forward-ports= --metrics= --skip-registry-check= --use-existing-config="
cluster_args="--docker-machine= -e --env= --host-config-dir= --host-data-dir= --host-volumes-dir= --image= --public-hostname= --routing-suffix= --server-loglevel= --version= $boolean_args"
#todo complete these args more
[[ "$command" == "up" && $COMP_CWORD -gt 2 ]] && \
COMPREPLY=( $( compgen -W "$cluster_args" -- $cur ) ) && \
return 0

if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
return 0
fi

case "$prev" in
up|destroy)
COMPREPLY=( $( compgen -W "$profiles" -- $cur ) )
;;
esac
}
complete -o nospace -F _oc_cluster_completion oc-cluster
EOF
}

function help {
echo "Valid commands:"
echo "oc-cluster up [profile] [OPTIONS]"
Expand All @@ -260,6 +297,7 @@ function help {
echo "oc-cluster create-volume volumeName [size|10Gi] [path|$HOME/.oc/profiles/<profile>/volumes/<volumeName>]"
echo "oc-cluster create-shared-volume project/volumeName [size|10Gi] [path|$HOME/.oc/volumes/<volumeName>]"
echo "oc-cluster deploy-nexus"
echo "oc-cluster completion bash"
}

# Use -gt 1 to consume two arguments per pass in the loop (e.g. each
Expand Down Expand Up @@ -309,6 +347,10 @@ then
shift
console "$@"
;;
completion)
shift
completion "$@"
;;
-h|help)
help
;;
Expand Down