module EverydayCliUtils::OptionUtil
Public Instance Methods
apply_options(layer, opts = {})
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 408 def apply_options(layer, opts = {}) @options ||= OptionList.new @options.update_all(layer, opts) end
default_options(opts = {})
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 403 def default_options(opts = {}) @options ||= OptionList.new @options.set_all(opts) end
default_settings(settings = {})
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 398 def default_settings(settings = {}) @options ||= OptionList.new @options.default_settings = settings end
defaults_option(file_path, names, settings = {})
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 347 def defaults_option(file_path, names, settings = {}) defaults_options_helper(file_path, names, settings, 4, :defaults, 'Defaults set', :local) end
defaults_options_helper(file_path, names, settings, order, opt_name, print_on_exit_string, composite_name)
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 355 def defaults_options_helper(file_path, names, settings, order, opt_name, print_on_exit_string, composite_name) @options ||= OptionList.new settings[:file_path] = File.expand_path(file_path) @options.register_special(order, opt_name, names, key_absent_or_true(settings, :exit_on_save), print_on_exit_string, settings, write_defaults_proc(composite_name), read_defaults_proc(composite_name)) end
file_path_nil_or_exists?(file_path)
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 373 def file_path_nil_or_exists?(file_path) file_path.nil? || !File.exist?(file_path) end
global_defaults_option(file_path, names, settings = {})
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 351 def global_defaults_option(file_path, names, settings = {}) defaults_options_helper(file_path, names, settings, 3, :global_defaults, 'Global defaults set', :global) end
help()
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 433 def help @options ||= OptionList.new @options.help end
help_option(names, settings = {})
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 387 def help_option(names, settings = {}) show_info_helper(names, settings, 1, :help, :exit_on_print) { |_, options| puts options.help } end
help_str=(str)
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 443 def help_str=(str) @options ||= OptionList.new @options.help_str = str end
key_absent_or_true(settings, key)
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 377 def key_absent_or_true(settings, key) !settings.has_key?(key) || settings[key] end
option(opt_name, names, settings = {}, &block)
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 337 def option(opt_name, names, settings = {}, &block) @options ||= OptionList.new @options.register(:option, opt_name, names, settings, &block) end
option_list()
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 428 def option_list @options ||= OptionList.new @options end
option_with_param(opt_name, names, settings = {}, &block)
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 342 def option_with_param(opt_name, names, settings = {}, &block) @options ||= OptionList.new @options.register(:option_with_param, opt_name, names, settings, &block) end
options()
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 423 def options @options ||= OptionList.new @options.composite(:global, :local, :arg) end
opts()
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 418 def opts @options ||= OptionList.new @options.opts end
parse!(argv = ARGV)
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 448 def parse!(argv = ARGV) @options ||= OptionList.new @options.run_special_pre_parse @options.parse!(argv) @options.run_special end
read_defaults_proc(composite_name)
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 366 def read_defaults_proc(composite_name) ->(opt, options) { file_path = opt.settings[:file_path] options.update_all composite_name, YAML::load_file(file_path) unless file_path_nil_or_exists?(file_path) } end
show_defaults_option(names, settings = {})
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 381 def show_defaults_option(names, settings = {}) show_info_helper(names, settings, 2, :show_defaults, :exit_on_show) { |_, options| puts options.show_defaults } end
show_info_helper(names, settings, order, opt_name, exit_on_sym, &block)
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 393 def show_info_helper(names, settings, order, opt_name, exit_on_sym, &block) @options ||= OptionList.new @options.register_special(order, opt_name, names, key_absent_or_true(settings, exit_on_sym), nil, settings, block) end
to_s()
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 438 def to_s @options ||= OptionList.new @options.to_s end
write_defaults_proc(composite_name)
click to toggle source
# File lib/everyday-cli-utils/option.rb, line 362 def write_defaults_proc(composite_name) ->(opt, options) { IO.write(opt.settings[:file_path], options.composite(composite_name, :arg).to_yaml) } end