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.



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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vbuilder/generator/options.rb', line 9

def initialize(args)
    super()

    @orig_args = args.clone

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

        o.on('-v', '--version', 'show ruby gem version') do |ver|
            puts "Version: #{Vbuilder::Version.version}"
            exit
        end

        o.on('-P', '--providers', 'see the list of valid providers') do
            puts "Valid providers:"
            Vbuilder::Helper::Utility.get_provider_list.each do |provider|
                puts "  - #{provider}"
            end

            exit
        end

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

        o.on('-p', '--provider [PROVIDER]', 'specify the provider to use in the building of your Vagrantfile') do |provider|
            unless provider.nil?
                self[:provider] = provider
            else
                self[:invalid_argument] = "please specify a provider"
            end
        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.



7
8
9
# File 'lib/vbuilder/generator/options.rb', line 7

def opts
  @opts
end

#orig_argsObject

Returns the value of attribute orig_args.



7
8
9
# File 'lib/vbuilder/generator/options.rb', line 7

def orig_args
  @orig_args
end

Instance Method Details

#merge(other) ⇒ Object



52
53
54
# File 'lib/vbuilder/generator/options.rb', line 52

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