Class: Vanagon::CLI::Completion

Inherits:
Vanagon::CLI show all
Defined in:
lib/vanagon/cli/completion.rb

Constant Summary collapse

DOCUMENTATION =
<<~DOCOPT.freeze
  Usage:
    completion [options]

  Options:
    -h, --help                       Display help
    -s, --shell SHELL                Specify shell for completion script [default: bash]
DOCOPT

Instance Method Summary collapse

Methods inherited from Vanagon::CLI

#options_validate

Instance Method Details

#options_translate(docopt_options) ⇒ Object



36
37
38
39
40
41
# File 'lib/vanagon/cli/completion.rb', line 36

def options_translate(docopt_options)
  translations = {
    '--shell' => :shell,
  }
  return docopt_options.map { |k, v| [translations[k], v] }.to_h
end

#parse(argv) ⇒ Object



16
17
18
19
20
21
# File 'lib/vanagon/cli/completion.rb', line 16

def parse(argv)
  Docopt.docopt(DOCUMENTATION, { argv: argv })
rescue Docopt::Exit => e
  VanagonLogger.error e.message
  exit 1
end

#run(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vanagon/cli/completion.rb', line 23

def run(options)
  shell = options[:shell].downcase.strip
  completion_file = File.expand_path(File.join('..', '..', '..', '..', 'extras', 'completions', "vanagon.#{shell}"), __FILE__)

  if File.exist?(completion_file)
    VanagonLogger.warn completion_file
    exit 0
  else
    VanagonLogger.error "Could not find completion file for '#{shell}': No such file #{completion_file}"
    exit 1
  end
end