Class: EverydayCliUtils::SpecialOptionDef
- Defined in:
- lib/everyday-cli-utils/option.rb
Instance Attribute Summary collapse
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
-
#state ⇒ Object
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(order, exit_on_action, names, print_on_exit_str, settings, action_block, pre_parse_block = nil) ⇒ SpecialOptionDef
constructor
A new instance of SpecialOptionDef.
- #run(options_list) ⇒ Object
- #run_pre_parse(options_list) ⇒ Object
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
#names ⇒ Object (readonly)
Returns the value of attribute names.
180 181 182 |
# File 'lib/everyday-cli-utils/option.rb', line 180 def names @names end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
180 181 182 |
# File 'lib/everyday-cli-utils/option.rb', line 180 def order @order end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
180 181 182 |
# File 'lib/everyday-cli-utils/option.rb', line 180 def settings @settings end |
#state ⇒ Object
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, , 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) .[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() if @state @action_block.call(self, ) 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() @pre_parse_block.call(self, ) unless @pre_parse_block.nil? end |