Class: EverydayCliUtils::SpecialOptionDef

Inherits:
Object
  • Object
show all
Defined in:
lib/everyday-cli-utils/option.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, exit_on_action, names, print_on_exit_str, settings, action_block, pre_parse_block = nil) ⇒ SpecialOptionDef

Returns a new instance of SpecialOptionDef.



147
148
149
150
151
152
153
154
155
156
# File 'lib/everyday-cli-utils/option.rb', line 147

def initialize(order, exit_on_action, names, print_on_exit_str, settings, action_block, pre_parse_block = nil)
  @order             = order
  @exit_on_action    = exit_on_action
  @names             = names
  @print_on_exit_str = print_on_exit_str
  @settings          = settings
  @action_block      = action_block
  @pre_parse_block   = pre_parse_block
  @state             = false
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



144
145
146
# File 'lib/everyday-cli-utils/option.rb', line 144

def names
  @names
end

#orderObject (readonly)

Returns the value of attribute order.



144
145
146
# File 'lib/everyday-cli-utils/option.rb', line 144

def order
  @order
end

#settingsObject (readonly)

Returns the value of attribute settings.



144
145
146
# File 'lib/everyday-cli-utils/option.rb', line 144

def settings
  @settings
end

#stateObject

Returns the value of attribute state.



145
146
147
# File 'lib/everyday-cli-utils/option.rb', line 145

def state
  @state
end

Class Method Details

.register(order, opts, options, opt_name, names, exit_on_action, print_on_exit_str, settings, default_settings, action_block, pre_parse_block = nil) ⇒ Object



172
173
174
175
176
177
178
# File 'lib/everyday-cli-utils/option.rb', line 172

def self.register(order, opts, options, opt_name, names, exit_on_action, print_on_exit_str, settings, default_settings, action_block, pre_parse_block = nil)
  settings                          = EverydayCliUtils::MapUtil.extend_hash(default_settings, settings)
  opt                               = SpecialOptionDef.new(order, exit_on_action, names, print_on_exit_str, settings, action_block, pre_parse_block)
  options.special_options[opt_name] = opt
  names << settings[:desc] if settings.has_key?(:desc)
  opts.on(*names) { opt.state = true }
end

Instance Method Details

#run(options_list) ⇒ Object



158
159
160
161
162
163
164
165
166
# File 'lib/everyday-cli-utils/option.rb', line 158

def run(options_list)
  if @state
    @action_block.call(self, options_list)
    if @exit_on_action
      puts @print_on_exit_str unless @print_on_exit_str.nil?
      exit 0
    end
  end
end

#run_pre_parse(options_list) ⇒ Object



168
169
170
# File 'lib/everyday-cli-utils/option.rb', line 168

def run_pre_parse(options_list)
  @pre_parse_block.call(self, options_list) unless @pre_parse_block.nil?
end