Class: Vanagon::CLI::Completion
- Inherits:
-
Vanagon::CLI
- Object
- Vanagon::CLI
- Vanagon::CLI::Completion
- 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
Instance Method Details
#options_translate(docopt_options) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/vanagon/cli/completion.rb', line 36 def () translations = { '--shell' => :shell, } return .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. 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() shell = [:shell].downcase.strip completion_file = File.(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 |