Module: Kontena::Plugin::Shell::Completer
- Defined in:
- lib/kontena/plugin/shell/completer.rb
Defined Under Namespace
Classes: Helper
Class Method Summary collapse
Class Method Details
.complete(words) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/kontena/plugin/shell/completer.rb', line 87 def self.complete(words) while words.first == 'kontena' || words.first == 'complete' words.shift end helper = Helper.new completion = [] case words[0] when NilClass, '' completion.concat %w(cloud logout grid app service stack vault certificate node master vpn registry container etcd external-registry whoami plugin version) when 'plugin' 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' 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' 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' sub_commands = %w(add-user audit-log create current list user remove show use) if words[1] completion.push(sub_commands) unless sub_commands.include?(words[1]) completion.push helper.grids else completion.push sub_commands end when 'node' sub_commands = %w(list show remove) if words[1] completion.push(sub_commands) unless sub_commands.include?(words[1]) completion.push helper.nodes else completion.push sub_commands end when 'master' sub_commands = %w(list use user 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] == 'user' 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' 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]) else completion.push sub_commands end when 'service' sub_commands = %w(containers create delete deploy list logs restart scale show start stats stop update monitor env secret link unlink) if words[1] completion.push(sub_commands) unless sub_commands.include?(words[1]) completion.push helper.services else completion.push sub_commands end when 'container' sub_commands = %w(exec inspect logs) if words[1] completion.push(sub_commands) unless sub_commands.include?(words[1]) completion.push helper.containers else completion.push sub_commands end when 'vpn' completion.push %w(config create delete) when 'external-registry' completion.push %w(add list delete) when 'app' sub_commands = %w(init build config deploy start stop remove rm ps list logs monitor show) if words[1] completion.push(sub_commands) unless sub_commands.include?(words[1]) completion.push helper.yml_services else completion.push sub_commands end when 'stack' sub_commands = %w(build install upgrade deploy start stop remove rm ls list logs monitor show registry) if words[1] if words[1] == 'registry' registry_sub_commands = %(push pull search show rm) completion.push registry_sub_commands elsif %w(install).include?(words[1]) completion.push helper.yml_files elsif words[1] == 'upgrade' && words[3] completion.push helper.yml_files else completion.push(sub_commands) unless sub_commands.include?(words[1]) completion.push helper.stacks end else completion.push sub_commands end else end completion.flatten.flat_map { |item| item.split(/\s+/) } end |