Class: VagrantPlugins::ShellCommander::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



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
# File 'lib/vagrant-shell-commander/option_manager.rb', line 10

def execute
  options = {}
  block = lambda do |parser|
    parser.banner = "Usage: vagrant sh -c 'COMMAND' -d [DIR] [MACHINE]"
    
    parser.separator ''
    
    parser.on('-d [DIR]', '--directory [DIR]', 
              'Directory to execute the command') do |dir|
      options[:dir] = dir
    end
    
    parser.on('-u [USER]', '--user [USER]', 
              'User to execute the command') do |user|
      options[:user] = user
    end
    
    parser.on("-c 'COMMAND'", "--command 'COMMAND'", 
              'Command to execute, quotes required for multiword') do |cmd|
      options[:cmd] = cmd
    end
  end

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