Class: Moonwalkair::Generator::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/moonwalkair/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
36
37
38
39
# File 'lib/moonwalkair/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)} air-app"
    
    o.on('-f', '--directory [DIRECTORY]', 'specify the directory to generate into') do |directory|
      self[:directory] = directory
    end
          
    o.on('-d', '--description [DESCRIPTION]', 'specify a description of the project') do |description|
      self[:description] = description
    end
    
    o.on('-n', '--user-name [USER_NAME]', "the user's name, ie that is credited in the LICENSE") do |user_name|
      self[:user_name] = user_name
    end

    o.on('-e','--user-email [USER_EMAIL]', "the user's email, ie that is credited in the README") do |user_email|
      self[:user_email] = user_email
    end
              
  end

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

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



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

def opts
  @opts
end

#orig_argsObject (readonly)

Returns the value of attribute orig_args.



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

def orig_args
  @orig_args
end

Instance Method Details

#merge(other) ⇒ Object



41
42
43
# File 'lib/moonwalkair/generator/options.rb', line 41

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