# File lib/foreman_maintain/cli/base.rb, line 10 def self.dashize(string) string.to_s.tr('_', '-') end
# File lib/foreman_maintain/cli/base.rb, line 122 def self.delete_duplicate_assumeyes_if_any declared_options.delete_if { |opt| opt.handles?('--assumeyes') } end
# File lib/foreman_maintain/cli/base.rb, line 99 def self.interactive_option delete_duplicate_assumeyes_if_any option ['-y', '--assumeyes'], :flag, 'Automatically answer yes for all questions' do |assume| ForemanMaintain.reporter.assumeyes = assume end option(['-w', '--whitelist'], 'whitelist', 'Comma-separated list of labels of steps to be skipped') do |whitelist| raise ArgumentError, 'value not specified' if whitelist.nil? || whitelist.empty? whitelist.split(',').map(&:strip) end option ['-f', '--force'], :flag, 'Force steps that would be skipped as they were already run' end
# File lib/foreman_maintain/cli/base.rb, line 80 def self.label_option option '--label', 'label', 'Limit only for a specific label. ' '(Use "list" command to see available labels)' do |label| raise ArgumentError, 'value not specified' if label.nil? || label.empty? underscorize(label).to_sym end end
# File lib/foreman_maintain/cli/base.rb, line 70 def self.option(switches, type, description, opts = {}, &block) multivalued = opts.delete(:multivalued) description += ' (comma-separated list)' if multivalued super(switches, type, description, opts) do |value| value = CSVParser.new.parse(value) if multivalued value = instance_exec(value, &block) if block value end end
# File lib/foreman_maintain/cli/base.rb, line 117 def self.service_options option '--exclude', 'EXCLUDE', 'A comma-separated list of services to skip' option '--only', 'ONLY', 'A comma-separated list of services to include' end
# File lib/foreman_maintain/cli/base.rb, line 50 def available_checks filter = {} filter[:tags] = tags if respond_to?(:tags) ForemanMaintain.available_checks(filter) end
# File lib/foreman_maintain/cli/base.rb, line 56 def available_procedures filter = {} filter[:tags] = tags if respond_to?(:tags) ForemanMaintain.available_procedures(filter) end
# File lib/foreman_maintain/cli/base.rb, line 14 def dashize(string) self.class.dashize(string) end
# File lib/foreman_maintain/cli/base.rb, line 22 def label_string(string) HighLine.color("[#{dashize(string)}]", :yellow) end
# File lib/foreman_maintain/cli/base.rb, line 126 def option_wrapper(option) respond_to?(option.to_sym) ? send(option) : false end
# File lib/foreman_maintain/cli/base.rb, line 30 def print_check_info(check) desc = "#{label_string(check.label)} #{check.description}".ljust(80) tags = check.tags.map { |t| tag_string(t) }.join(' ').to_s puts "#{desc} #{tags}".strip end
# File lib/foreman_maintain/cli/base.rb, line 36 def reporter @reporter ||= ForemanMaintain.reporter end
# File lib/foreman_maintain/cli/base.rb, line 40 def run_scenario(scenarios, rescue_scenario = nil) @runner ||= ForemanMaintain::Runner.new(reporter, scenarios, :assumeyes => option_wrapper('assumeyes?'), :whitelist => option_wrapper('whitelist') || [], :force => option_wrapper('force?'), :rescue_scenario => rescue_scenario) runner.run end
# File lib/foreman_maintain/cli/base.rb, line 26 def tag_string(string) HighLine.color("[#{dashize(string)}]", :cyan) end
# File lib/foreman_maintain/cli/base.rb, line 18 def underscorize(string) string.to_s.tr('-', '_') end