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

Updated the completion scripts for current command set. #1168

Merged
merged 1 commit into from Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/README.md
Expand Up @@ -10,7 +10,7 @@ Install it yourself as:

$ gem install kontena-cli

To enable tab-completion for bash, add this to your `.bashrc` scripts:
To enable tab-completion for bash, add this to your `.bashrc` scripts (or `.zshrc` for zsh):

```
which kontena > /dev/null && . "$( kontena whoami --bash-completion-path )"
Expand Down
48 changes: 44 additions & 4 deletions cli/lib/kontena/scripts/completer
Expand Up @@ -86,9 +86,33 @@ words = ARGV
words.delete_at(0)

completion = []
completion.push %w(app deploy forgot-password master node grid service container vpn external-registry registry login logout whoami) if words.size < 2
completion.push %w(cloud logout grid app service vault certificate node master vpn registry container etcd external-registry whoami plugin version) if words.size < 2
if words.size > 0
case words[0]
when 'plugin'
completion.clear
sub_commands = %w(list ls search install uninstall)
if words[1]
completion.push(sub_commands) unless sub_commands.include?(words[1])
else
completion.push sub_commands
end
when 'etcd'
completion.clear
sub_commands = %w(get set mkdir mk list ls rm)
if words[1]
completion.push(sub_commands) unless sub_commands.include?(words[1])
else
completion.push sub_commands
end
when 'registry'
completion.clear
sub_commands = %w(create remove rm)
if words[1]
completion.push(sub_commands) unless sub_commands.include?(words[1])
else
completion.push sub_commands
end
when 'grid'
completion.clear
sub_commands = %w(add-user audit-log create current list user remove show use)
Expand All @@ -109,15 +133,31 @@ if words.size > 0
end
when 'master'
completion.clear
sub_commands = %w(list use)
sub_commands = %w(list use users current remove rm config cfg login logout token join audit-log init-cloud)
if words[1] && words[1] == 'use'
completion.push helper.master_names
elsif words[1] && words[1] == 'users'
users_sub_commands = %(invite list role)
completion.push users_sub_commands
elsif words[1] && ['config', 'cfg'].include?(words[1])
config_sub_commands = %(set get dump load import export unset)
completion.push config_sub_commands
elsif words[1] && words[1] == 'token'
token_sub_commands = %(list ls rm remove show current create)
completion.push token_sub_commands
elsif words[1]
completion.push(sub_commands) unless sub_commands.include?(words[1])
else
completion.push sub_commands
end
when 'cloud'
completion.clear
sub_commands = %w(login logout master)
if words[1] && words[1] == 'master'
cloud_master_sub_commands = %(list ls remove rm add show update)
completion.push cloud_master_sub_commands
elsif words[1]
completion.push(sub_commands) unless sub_commands.include?(words[1])
completion.push %w(create)
else
completion.push sub_commands
end
Expand All @@ -134,7 +174,7 @@ if words.size > 0
end
when 'container'
completion.clear
sub_commands = %w(exec)
sub_commands = %w(exec inspect logs)
if words[1]
completion.push(sub_commands) unless sub_commands.include?(words[1])
completion.push helper.containers
Expand Down
12 changes: 11 additions & 1 deletion cli/lib/kontena/scripts/init
Expand Up @@ -2,10 +2,20 @@

_kontena_complete() {
COMPREPLY=()
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
if [ "$ZSH_VERSION" == "" ]; then
local src="${BASH_SOURCE[0]}"
else
local src="${(%):-%x}"
fi
DIR=$( cd "$( dirname "$src" )" && pwd )
local word="${COMP_WORDS[COMP_CWORD]}"
local completions="$(${DIR}/completer ${COMP_WORDS[*]})"
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}

if [ "$ZSH_VERSION" != "" ]; then
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
fi

complete -F _kontena_complete kontena