Module: Quickl::Command::Options::ClassMethods

Defined in:
lib/quickl/command/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#option_buildersObject (readonly)

Installed options builders



6
7
8
# File 'lib/quickl/command/options.rb', line 6

def option_builders
  @option_builders
end

Instance Method Details

#build_options(scope = self) ⇒ Object

Builds an OptionParser instance



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/quickl/command/options.rb', line 9

def build_options(scope = self)
  OptionParser.new do |opt|
    opt.program_name = File.basename $0
    if const_defined?(:VERSION)
      opt.version = const_get(:VERSION)
    end
    opt.summary_indent = ' ' * 2
    (option_builders || []).each{|b| 
      scope.instance_exec(opt, &b)
    }
  end
end

#options(builder = nil, &block) ⇒ Object

Without builder nor block, returns built options. Otherwise, adds a new option builder



24
25
26
27
28
29
30
31
# File 'lib/quickl/command/options.rb', line 24

def options(builder = nil, &block)
  if b = (builder || block)
    @option_builders ||= []
    @option_builders << b
  else
    build_options
  end
end

#summarized_optionsObject

Returns summarized options



34
35
36
# File 'lib/quickl/command/options.rb', line 34

def summarized_options
  options.summarize.join.rstrip
end