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.



183
184
185
186
187
188
189
190
191
192
# File 'lib/everyday-cli-utils/option.rb', line 183

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.



180
181
182
# File 'lib/everyday-cli-utils/option.rb', line 180

def names
  @names
end

#orderObject (readonly)

Returns the value of attribute order.



180
181
182
# File 'lib/everyday-cli-utils/option.rb', line 180

def order
  @order
end

#settingsObject (readonly)

Returns the value of attribute settings.



180
181
182
# File 'lib/everyday-cli-utils/option.rb', line 180

def settings
  @settings
end

#stateObject

Returns the value of attribute state.



181
182
183
# File 'lib/everyday-cli-utils/option.rb', line 181

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



209
210
211
212
213
214
215
# File 'lib/everyday-cli-utils/option.rb', line 209

def 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



194
195
196
197
198
199
200
201
202
# File 'lib/everyday-cli-utils/option.rb', line 194

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



204
205
206
# File 'lib/everyday-cli-utils/option.rb', line 204

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