Class: ForemanMaintain::Cli::Base
Direct Known Subclasses
AdvancedCommand, BackupCommand, HealthCommand, MainCommand, OfflineBackupCommand, OnlineBackupCommand, PrebuildBashCompletionCommand, Procedure::AbstractProcedureCommand, Procedure::ByTagCommand, Procedure::RunCommand, ProcedureCommand, RestoreCommand, ServiceCommand, SnapshotBackupCommand, UpgradeCommand
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#check, #detector, #feature, #find_all_scenarios, #find_checks, #find_procedures, #find_scenarios, #procedure
Instance Attribute Details
#runner ⇒ Object
Returns the value of attribute runner.
8
9
10
|
# File 'lib/foreman_maintain/cli/base.rb', line 8
def runner
@runner
end
|
Class Method Details
66
67
68
|
# File 'lib/foreman_maintain/cli/base.rb', line 66
def self.available_tags(collection)
collection.inject([]) { |array, item| array.concat(item.tags).uniq }.sort_by(&:to_s)
end
|
.completion_map ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/foreman_maintain/cli/base.rb', line 70
def self.completion_map
completion = {}
recognised_options.each do |opt|
opt.switches.each do |switch|
completion[switch] = completion_types.fetch(switch, {})
end
end
recognised_subcommands.each do |cmd|
completion[cmd.names.first] = cmd.subcommand_class.completion_map
end
completion[:params] = completion_types[:params] unless completion_types[:params].empty?
completion
end
|
.completion_types ⇒ Object
87
88
89
|
# File 'lib/foreman_maintain/cli/base.rb', line 87
def self.completion_types
@completion_types ||= { :params => [] }
end
|
.dashize(string) ⇒ Object
10
11
12
|
# File 'lib/foreman_maintain/cli/base.rb', line 10
def self.dashize(string)
string.to_s.tr('_', '-')
end
|
.delete_duplicate_assumeyes_if_any ⇒ Object
156
157
158
|
# File 'lib/foreman_maintain/cli/base.rb', line 156
def self.delete_duplicate_assumeyes_if_any
declared_options.delete_if { |opt| opt.handles?('--assumeyes') }
end
|
.interactive_option ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/foreman_maintain/cli/base.rb', line 133
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
|
.label_option ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'lib/foreman_maintain/cli/base.rb', line 114
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) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/foreman_maintain/cli/base.rb', line 91
def self.option(switches, type, description, opts = {}, &block)
multivalued = opts.delete(:multivalued)
completion_type = opts.delete(:completion)
completion_type = { :type => :flag } if completion_type.nil? && type == :flag
completion_type ||= { :type => :value }
[switches].flatten(1).each { |s| completion_types[s] = completion_type }
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
|
.parameter(name, description, opts = {}, &block) ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/foreman_maintain/cli/base.rb', line 105
def self.parameter(name, description, opts = {}, &block)
unless [:subcommand_name, :subcommand_arguments].include?(opts[:attribute_name])
completion_type = opts.delete(:completion)
completion_type ||= { :type => :value }
completion_types[:params] << completion_type
end
super(name, description, opts, &block)
end
|
.service_options ⇒ Object
151
152
153
154
|
# File 'lib/foreman_maintain/cli/base.rb', line 151
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
|
123
124
125
126
127
128
129
130
131
|
# File 'lib/foreman_maintain/cli/base.rb', line 123
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
|
Instance Method Details
#available_checks ⇒ Object
50
51
52
53
54
|
# 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
|
#available_procedures ⇒ Object
56
57
58
59
60
|
# 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
|
62
63
64
|
# File 'lib/foreman_maintain/cli/base.rb', line 62
def available_tags(collection)
self.class.available_tags(collection)
end
|
#dashize(string) ⇒ Object
14
15
16
|
# File 'lib/foreman_maintain/cli/base.rb', line 14
def dashize(string)
self.class.dashize(string)
end
|
#label_string(string) ⇒ Object
22
23
24
|
# File 'lib/foreman_maintain/cli/base.rb', line 22
def label_string(string)
HighLine.color("[#{dashize(string)}]", :yellow)
end
|
#option_wrapper(option) ⇒ Object
160
161
162
|
# File 'lib/foreman_maintain/cli/base.rb', line 160
def option_wrapper(option)
respond_to?(option.to_sym) ? send(option) : false
end
|
#print_check_info(check) ⇒ Object
30
31
32
33
34
|
# 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
|
#reporter ⇒ Object
36
37
38
|
# File 'lib/foreman_maintain/cli/base.rb', line 36
def reporter
@reporter ||= ForemanMaintain.reporter
end
|
#run_scenario(scenarios, rescue_scenario = nil) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# 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
|
#tag_string(string) ⇒ Object
26
27
28
|
# File 'lib/foreman_maintain/cli/base.rb', line 26
def tag_string(string)
HighLine.color("[#{dashize(string)}]", :cyan)
end
|
#underscorize(string) ⇒ Object
18
19
20
|
# File 'lib/foreman_maintain/cli/base.rb', line 18
def underscorize(string)
string.to_s.tr('-', '_')
end
|