Module: EverydayCliUtils::OptionUtil
- Defined in:
- lib/everyday-cli-utils/option.rb
Instance Method Summary collapse
- #apply_options(layer, opts = {}) ⇒ Object
- #banner(banner) ⇒ Object
- #default_options(opts = {}) ⇒ Object
- #default_settings(settings = {}) ⇒ Object
- #defaults_option(file_path, names, settings = {}) ⇒ Object
- #global_defaults_option(file_path, names, settings = {}) ⇒ Object
- #help ⇒ Object
- #help_option(names, settings = {}) ⇒ Object
- #help_str=(str) ⇒ Object
- #option(opt_name, names, settings = {}, &block) ⇒ Object
- #option_list ⇒ Object
- #option_with_param(opt_name, names, settings = {}, &block) ⇒ Object
- #options ⇒ Object
- #opts ⇒ Object
- #parse!(argv = ARGV) ⇒ Object
- #show_defaults_option(names, settings = {}) ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#apply_options(layer, opts = {}) ⇒ Object
355 356 357 358 |
# File 'lib/everyday-cli-utils/option.rb', line 355 def (layer, opts = {}) @options ||= OptionList.new @options.update_all(layer, opts) end |
#banner(banner) ⇒ Object
360 361 362 363 |
# File 'lib/everyday-cli-utils/option.rb', line 360 def () @options ||= OptionList.new @options. = end |
#default_options(opts = {}) ⇒ Object
350 351 352 353 |
# File 'lib/everyday-cli-utils/option.rb', line 350 def (opts = {}) @options ||= OptionList.new @options.set_all(opts) end |
#default_settings(settings = {}) ⇒ Object
345 346 347 348 |
# File 'lib/everyday-cli-utils/option.rb', line 345 def default_settings(settings = {}) @options ||= OptionList.new @options.default_settings = settings end |
#defaults_option(file_path, names, settings = {}) ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/everyday-cli-utils/option.rb', line 303 def defaults_option(file_path, names, settings = {}) @options ||= OptionList.new settings[:file_path] = File.(file_path) @options.register_special(4, :defaults, names, !settings.has_key?(:exit_on_save) || settings[:exit_on_save], 'Defaults set', settings, ->(opt, ) { IO.write(opt.settings[:file_path], .composite(:local, :arg).to_yaml) }, ->(opt, ) { unless opt.settings[:file_path].nil? || !File.exist?(opt.settings[:file_path]) .update_all :local, YAML::load_file(opt.settings[:file_path]) end }) end |
#global_defaults_option(file_path, names, settings = {}) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/everyday-cli-utils/option.rb', line 316 def global_defaults_option(file_path, names, settings = {}) @options ||= OptionList.new settings[:file_path] = File.(file_path) @options.register_special(3, :global_defaults, names, !settings.has_key?(:exit_on_save) || settings[:exit_on_save], 'Global defaults set', settings, ->(opt, ) { IO.write(opt.settings[:file_path], .composite(:global, :arg).to_yaml) }, ->(opt, ) { unless opt.settings[:file_path].nil? || !File.exist?(opt.settings[:file_path]) .update_all :global, YAML::load_file(opt.settings[:file_path]) end }) end |
#help ⇒ Object
377 378 379 380 |
# File 'lib/everyday-cli-utils/option.rb', line 377 def help @options ||= OptionList.new @options.help end |
#help_option(names, settings = {}) ⇒ Object
337 338 339 340 341 342 343 |
# File 'lib/everyday-cli-utils/option.rb', line 337 def help_option(names, settings = {}) @options ||= OptionList.new @options.register_special(1, :help, names, !settings.has_key?(:exit_on_print) || settings[:exit_on_print], nil, settings, ->(_, ) { puts .help }) end |
#help_str=(str) ⇒ Object
387 388 389 |
# File 'lib/everyday-cli-utils/option.rb', line 387 def help_str=(str) @options.help_str = str end |
#option(opt_name, names, settings = {}, &block) ⇒ Object
293 294 295 296 |
# File 'lib/everyday-cli-utils/option.rb', line 293 def option(opt_name, names, settings = {}, &block) @options ||= OptionList.new @options.register(:option, opt_name, names, settings, &block) end |
#option_list ⇒ Object
373 374 375 |
# File 'lib/everyday-cli-utils/option.rb', line 373 def option_list @options end |
#option_with_param(opt_name, names, settings = {}, &block) ⇒ Object
298 299 300 301 |
# File 'lib/everyday-cli-utils/option.rb', line 298 def option_with_param(opt_name, names, settings = {}, &block) @options ||= OptionList.new @options.register(:option_with_param, opt_name, names, settings, &block) end |
#options ⇒ Object
369 370 371 |
# File 'lib/everyday-cli-utils/option.rb', line 369 def @options.composite(:global, :local, :arg) end |
#opts ⇒ Object
365 366 367 |
# File 'lib/everyday-cli-utils/option.rb', line 365 def opts @options.opts end |
#parse!(argv = ARGV) ⇒ Object
391 392 393 394 395 396 |
# File 'lib/everyday-cli-utils/option.rb', line 391 def parse!(argv = ARGV) @options ||= OptionList.new @options.run_special_pre_parse @options.parse!(argv) @options.run_special end |
#show_defaults_option(names, settings = {}) ⇒ Object
329 330 331 332 333 334 335 |
# File 'lib/everyday-cli-utils/option.rb', line 329 def show_defaults_option(names, settings = {}) @options ||= OptionList.new @options.register_special(2, :show_defaults, names, !settings.has_key?(:exit_on_show) || settings[:exit_on_show], nil, settings, ->(_, ) { puts .show_defaults }) end |
#to_s ⇒ Object
382 383 384 385 |
# File 'lib/everyday-cli-utils/option.rb', line 382 def to_s @options ||= OptionList.new @options.to_s end |