Class: Vbuilder::Generator::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/vbuilder/generator/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



6
7
8
9
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
35
# File 'lib/vbuilder/generator/options.rb', line 6

def initialize(args)
    super()

    @orig_args = args.clone

    require 'optparse'
    @opts = OptionParser.new do |o|
        o.banner = "Usage: #{File.basename($0)} [options]\ne.g. #{File.basename($0)} --provider aws"

        o.on('-i', '--interactive', 'choose to interactively fill these config attributes out on the CLI') do
            self[:interactive] = true
        end

        o.on('--provider [PROVIDER]', 'specify the provider to use in the building of your Vagrantfile') do |provider|
            self[:provider] = provider
        end

        o.separator ""
    end

    begin
        @opts.parse!(args)
    rescue OptionParser::InvalidOption => e
        self[:invalid_argument] = e.message
    end

    def merge(other)
        self.class.new(@orig_args + other.orig_args)
    end
end

Instance Attribute Details

#optsObject

Returns the value of attribute opts.



4
5
6
# File 'lib/vbuilder/generator/options.rb', line 4

def opts
  @opts
end

#orig_argsObject

Returns the value of attribute orig_args.



4
5
6
# File 'lib/vbuilder/generator/options.rb', line 4

def orig_args
  @orig_args
end

Instance Method Details

#merge(other) ⇒ Object



32
33
34
# File 'lib/vbuilder/generator/options.rb', line 32

def merge(other)
    self.class.new(@orig_args + other.orig_args)
end