module Clamp::Option::Declaration

Public Instance Methods

declared_options() click to toggle source
# File lib/clamp/option/declaration.rb, line 23
def declared_options
  @declared_options ||= []
end
find_option(switch) click to toggle source
# File lib/clamp/option/declaration.rb, line 19
def find_option(switch)
  recognised_options.find { |o| o.handles?(switch) }
end
option(switches, type, description, opts = {}, &block) click to toggle source
# File lib/clamp/option/declaration.rb, line 11
def option(switches, type, description, opts = {}, &block)
  Option::Definition.new(switches, type, description, opts).tap do |option|
    declared_options << option
    block ||= option.default_conversion_block
    define_accessors_for(option, &block)
  end
end
recognised_options() click to toggle source
# File lib/clamp/option/declaration.rb, line 27
def recognised_options
  declare_implicit_options
  effective_options
end

Private Instance Methods

declare_implicit_options() click to toggle source
# File lib/clamp/option/declaration.rb, line 34
def declare_implicit_options
  return nil if defined?(@implicit_options_declared)
  unless effective_options.find { |o| o.handles?("--help") }
    help_switches = ["--help"]
    help_switches.unshift("-h") unless effective_options.find { |o| o.handles?("-h") }
    option help_switches, :flag, "print help" do
      request_help
    end
  end
  @implicit_options_declared = true
end
effective_options() click to toggle source
# File lib/clamp/option/declaration.rb, line 46
def effective_options
  ancestors.inject([]) do |options, ancestor|
    if ancestor.kind_of?(Clamp::Option::Declaration)
      options + ancestor.declared_options
    else
      options
    end
  end
end