Module: Clamp::Option::Declaration

Includes:
Attribute::Declaration
Included in:
Command
Defined in:
lib/clamp/option/declaration.rb

Overview

Option declaration methods.

Instance Method Summary collapse

Instance Method Details

#declared_optionsObject



27
28
29
# File 'lib/clamp/option/declaration.rb', line 27

def declared_options
  @declared_options ||= []
end

#find_option(switch) ⇒ Object



23
24
25
# File 'lib/clamp/option/declaration.rb', line 23

def find_option(switch)
  recognised_options.find { |o| o.handles?(switch) }
end

#option(switches, type, description, opts = {}, &block) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/clamp/option/declaration.rb', line 15

def option(switches, type, description, opts = {}, &block)
  Option::Definition.new(switches, type, description, opts).tap do |option|
    block ||= option.default_conversion_block
    define_accessors_for(option, &block)
    declared_options << option
  end
end

#recognised_optionsObject



31
32
33
34
35
36
37
# File 'lib/clamp/option/declaration.rb', line 31

def recognised_options
  unless @implicit_options_declared ||= false
    declare_implicit_help_option
    @implicit_options_declared = true
  end
  effective_options
end