Class: VagrantShellCommander::OptionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-shell-commander/option_manager.rb

Overview

Option parser

Instance Method Summary collapse

Instance Method Details

#executeHash

Main parsing method

Returns:

  • (Hash)

    The keys are :parser for the object returned by OptionParser and :values for the actual option values



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-shell-commander/option_manager.rb', line 9

def execute
  options = {}
  block = lambda do |parser|
    parser.banner = "Usage: vagrant sh --cmd 'COMMAND' --dir [DIR] [MACHINE]"

    parser.separator ''

    parser.on('--dir [DIR]', '--change-working-dir [DIR]', 
              'Directory to execute the command') do |dir|
      options[:dir] = dir
    end

    parser.on("--cmd 'COMMAND'", "--command 'COMMAND'", 
              'Command to execute') do |cmd|
      options[:cmd] = cmd
    end
  end

  {parser: OptionParser.new(&block), values: options}
end