Class: CLI::CommonOptionParser
- Inherits:
-
OptionParser
- Object
- OptionParser
- CLI::CommonOptionParser
- Defined in:
- lib/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #add_required_argument(*args) ⇒ Object (also: #add_required_arguments)
- #check_required_arguments ⇒ Object
- #missing_required_arguments ⇒ Object
-
#parse_common ⇒ Object
def options=(value) #puts “Setting #self.class.name options => (#value.class.name) #value” @options = value end.
- #required_arguments ⇒ Object
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
21 22 23 |
# File 'lib/cli.rb', line 21 def 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_arguments ⇒ Object
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_arguments ⇒ Object
48 49 50 51 |
# File 'lib/cli.rb', line 48 def missing_required_arguments puts "Options #{options}" required_arguments.dup.delete_if { |a| .has_key?(a.is_a?(Hash) ? a.keys.first : a) } end |
#parse_common ⇒ Object
def options=(value)
#puts "Setting #{self.class.name}[#{self.object_id}] options => (#{value.class.name}[#{value.object_id}]) #{value}"
= value
end
def options
#puts "Getting #{self.class.name}[#{self.object_id}] 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] # Make sure that options from the command line override those from the options file parse!(ARGV.dup) if and load() check_required_arguments end |
#required_arguments ⇒ Object
44 |
# File 'lib/cli.rb', line 44 def required_arguments; @required_arguments ||= [ ] end |