Class: Iopts
- Inherits:
-
OptionParser
- Object
- OptionParser
- Iopts
- Defined in:
- lib/iopts.rb
Overview
Customized version of ruby’s OptionParser.
Instance Attribute Summary collapse
-
#funnel ⇒ Object
Returns the value of attribute funnel.
Class Method Summary collapse
Instance Method Summary collapse
- #help! ⇒ Object
-
#initialize(*args) ⇒ Iopts
constructor
A new instance of Iopts.
- #on(*args) ⇒ Object
- #program_name ⇒ Object
- #to_s ⇒ Object
- #usage! ⇒ Object
Constructor Details
#initialize(*args) ⇒ Iopts
Returns a new instance of Iopts.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/iopts.rb', line 18 def initialize *args = args.last.kind_of?(Hash) ? args.pop : {} @funnel = [:funnel] || OpenStruct.new @footer = [:footer] @examples = [:examples] width = [:width] || 32 indent = [:indent] || (' ' * 2) super nil, width, indent @banner = [:banner].kind_of?(Hash) ? ([:banner]) : [:banner] end |
Instance Attribute Details
#funnel ⇒ Object
Returns the value of attribute funnel.
8 9 10 |
# File 'lib/iopts.rb', line 8 def funnel @funnel end |
Class Method Details
.section_title(title) ⇒ Object
10 11 12 |
# File 'lib/iopts.rb', line 10 def self.section_title title Paint[title, :bold] end |
.section_title_ref(ref) ⇒ Object
14 15 16 |
# File 'lib/iopts.rb', line 14 def self.section_title_ref ref Paint[ref, :underline] end |
Instance Method Details
#help! ⇒ Object
54 55 56 |
# File 'lib/iopts.rb', line 54 def help! self.on('-h', '--help', 'show this help and exit'){ puts self; exit 0 } end |
#on(*args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/iopts.rb', line 32 def on *args if block_given? super(*args) else sw = make_switch(args) return super(*args) if !sw || sw.empty? || !sw.first.respond_to?(:long) name = sw.first.long.first || sw.first.short.first return super(*args) unless name name = name.sub /^\-+/, '' block = lambda{ |val| fill_funnel name, val } super(*args, &block) end end |
#program_name ⇒ Object
46 47 48 |
# File 'lib/iopts.rb', line 46 def program_name @program_name || File.basename($0) end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/iopts.rb', line 50 def to_s "#{super}#{summary_examples_section}#{@footer}" end |
#usage! ⇒ Object
58 59 60 |
# File 'lib/iopts.rb', line 58 def usage! self.on('-u', '--usage', 'show this help and exit'){ puts self; exit 0 } end |