Class: ConventionalModels::OptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/conventional_models/option_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ OptionParser

Returns a new instance of OptionParser.



11
12
13
14
15
16
17
18
# File 'lib/conventional_models/option_parser.rb', line 11

def initialize(arguments)
  @arguments = arguments
  
  @options = Options.new

  @parsed_options = true
  parse
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/conventional_models/option_parser.rb', line 9

def options
  @options
end

Instance Method Details

#parseObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/conventional_models/option_parser.rb', line 24

def parse
  opts = ::OptionParser.new
  opts.on('-v', '--version')    { @options.output_version = true }
  opts.on('-h', '--help')       { @options.output_help = true }
  opts.on('-s', '--skip-configure')    { @options.skip_configure = true }  
  opts.on('-c', '--config FILE')      { |file| @options.config = file }
  opts.on('-e', '--environment ENV')      { |env| @options.environment = env }
  opts.on('-V', '--verbose')      { |env| @options.verbose = true }
  
  opts.parse!(@arguments) rescue @parsed_options = false
end

#parsed_options?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/conventional_models/option_parser.rb', line 20

def parsed_options?
  @parsed_options
end