Sha256: ea3c1fe106da9f8a9b1cab92d01cf035a67547d1339f24b404117f8749c7a146

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module VagrantPlugins
  module ShellCommander
    # Option parser
    #
    class OptionManager
      # Main parsing method
      # @return [Hash] The keys are :parser for the object returned by
      #   OptionParser and :values for the actual option values
      #
      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-shell-commander-0.3.2 lib/vagrant-shell-commander/option_manager.rb
vagrant-shell-commander-0.3.1 lib/vagrant-shell-commander/option_manager.rb
vagrant-shell-commander-0.3.0 lib/vagrant-shell-commander/option_manager.rb