Class: CLI::CommonOptionParser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



21
22
23
# File 'lib/cli.rb', line 21

def options
  @options
end

Instance Method Details

#add_required_argument(*args) ⇒ Object Also known as: add_required_arguments



45
# File 'lib/cli.rb', line 45

def add_required_argument(*args)  [*args].each { |arg| required_arguments << arg } end

#check_required_argumentsObject



53
54
55
56
57
58
# File 'lib/cli.rb', line 53

def check_required_arguments
  _missing_arguments = missing_required_arguments
  unless _missing_arguments.empty?
    abort "Missing Required Arguments: #{_missing_arguments.map { |v| (v.is_a?(Hash) ? v.values.first : v).to_s.sub('_', '-')}.join(', ')}\n#{self.to_s}"
  end
end

#missing_required_argumentsObject



48
49
50
51
# File 'lib/cli.rb', line 48

def missing_required_arguments
  puts "Options #{options}"
  required_arguments.dup.delete_if { |a| options.has_key?(a.is_a?(Hash) ? a.keys.first : a) }
end

#parse_commonObject

def options=(value)

#puts "Setting #{self.class.name}[#{self.object_id}] options => (#{value.class.name}[#{value.object_id}]) #{value}"
@options = value

end

def options

#puts "Getting #{self.class.name}[#{self.object_id}] options. #{@options}"
@options

end



33
34
35
36
37
38
39
40
41
42
# File 'lib/cli.rb', line 33

def parse_common
  #puts "Parsing #{self.class.name}[#{self.object_id}] options. #{@options}"
  parse!(ARGV.dup)

  options_file_path = options[:options_file_path]
  # Make sure that options from the command line override those from the options file
  parse!(ARGV.dup) if options_file_path and load(options_file_path)

  check_required_arguments
end

#required_argumentsObject



44
# File 'lib/cli.rb', line 44

def required_arguments; @required_arguments ||= [ ] end