class ForemanMaintain::Cli::Base

Attributes

runner[R]

Public Class Methods

available_tags(collection) click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 67
def self.available_tags(collection)
  collection.inject([]) { |array, item| array.concat(item.tags).uniq }.sort_by(&:to_s)
end
dashize(string) click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 10
def self.dashize(string)
  string.to_s.tr('_', '-')
end
interactive_option() click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 100
def self.interactive_option
  option ['-y', '--assumeyes'], :flag,
         'Automatically answer yes for all questions'

  option ['-w', '--whitelist'], 'whitelist',
         'Comma-separated list of labels of steps to be ignored' 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
label_option() click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 81
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
option(switches, type, description, opts = {}, &block) click to toggle source
Calls superclass method
# File lib/foreman_maintain/cli/base.rb, line 71
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
tags_option() click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 90
def self.tags_option
  option('--tags', 'tags',
         'Limit only for specific set of labels. '                   '(Use list-tags command to see available tags)',
         :multivalued => true) do |tags|
    raise ArgumentError, 'value not specified' if tags.nil? || tags.empty?
    tags.map { |tag| underscorize(tag).to_sym }
  end
end

Public Instance Methods

available_checks() click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 51
def available_checks
  filter = {}
  filter[:tags] = tags if respond_to?(:tags)
  ForemanMaintain.available_checks(filter)
end
available_procedures() click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 57
def available_procedures
  filter = {}
  filter[:tags] = tags if respond_to?(:tags)
  ForemanMaintain.available_procedures(filter)
end
available_tags(collection) click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 63
def available_tags(collection)
  self.class.available_tags(collection)
end
dashize(string) click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 14
def dashize(string)
  self.class.dashize(string)
end
label_string(string) click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 22
def label_string(string)
  HighLine.color("[#{dashize(string)}]", :yellow)
end
print_check_info(check) click to toggle source
reporter() click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 36
def reporter
  @reporter ||= ForemanMaintain::Reporter::CLIReporter.new(STDOUT,
                                                           STDIN,
                                                           :assumeyes => assumeyes?)
end
run_scenario(scenarios) click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 42
def run_scenario(scenarios)
  @runner ||=
    ForemanMaintain::Runner.new(reporter, scenarios,
                                :assumeyes => assumeyes?,
                                :whitelist => whitelist || [],
                                :force => force?)
  runner.run
end
tag_string(string) click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 26
def tag_string(string)
  HighLine.color("[#{dashize(string)}]", :cyan)
end
underscorize(string) click to toggle source
# File lib/foreman_maintain/cli/base.rb, line 18
def underscorize(string)
  string.to_s.tr('-', '_')
end