1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
require 'optparse'
require 'vagrant/util/install_cli_autocomplete'
module VagrantPlugins
module CommandAutocomplete
module Command
class Install < Vagrant.plugin("2", :command)
def execute
options = {
shells: []
}
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant autocomplete install [-h] [shell name]"
o.separator ""
o.separator "Available shells: #{Vagrant::Util::InstallCLIAutocomplete::SUPPORTED_SHELLS.keys.join(' ')}"
o.separator ""
o.separator "Options:"
o.separator ""
o.on("-b", "--bash", "Install bash autocomplete") do |c|
options[:shells].append("bash")
end
o.on("-z", "--zsh", "Install zsh autocomplete") do |c|
options[:shells].append("zsh")
end
end
# Parse the options
argv = parse_options(opts)
return if !argv
raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp if argv.length > 0
written_paths = Vagrant::Util::InstallCLIAutocomplete.install(options[:shells])
if written_paths && written_paths.length > 0
@env.ui.info(I18n.t("vagrant.autocomplete.installed", paths: written_paths.join("\n- ")))
else
@env.ui.info(I18n.t("vagrant.autocomplete.not_installed"))
end
# Success, exit status 0
0
end
end
end
end
end
|