Class: Puppet::Application::FaceBase
Constant Summary
DOCPATTERN
Constants included
from Util
Util::ALNUM, Util::ALPHA, Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::ESCAPED, Util::HEX, Util::HttpProxy, Util::PUPPET_STACK_INSERTION_FRAME, Util::RESERVED, Util::RFC_3986_URI_REGEX, Util::UNRESERVED, Util::UNSAFE
Constants included
from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Instance Attribute Summary collapse
#command_line, #options
Instance Method Summary
collapse
[], #app_defaults, available_application_names, banner, clear!, clear?, clear_everything_for_tests, #configure_indirector_routes, controlled_run, #deprecate, #deprecated?, environment_mode, exit, find, get_environment_mode, #handle_logdest_arg, #handlearg, #help, #initialize, #initialize_app_defaults, interrupted?, #log_runtime_environment, #name, option, option_parser_commands, restart!, restart_requested?, #run, #run_command, run_mode, #set_log_level, #setup_logs, stop!, stop_requested?, #summary, try_load_class
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask
#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Instance Attribute Details
32
33
34
|
# File 'lib/puppet/application/face_base.rb', line 32
def action
@action
end
|
#arguments ⇒ Object
32
33
34
|
# File 'lib/puppet/application/face_base.rb', line 32
def arguments
@arguments
end
|
32
33
34
|
# File 'lib/puppet/application/face_base.rb', line 32
def face
@face
end
|
#render_as ⇒ Object
31
32
33
|
# File 'lib/puppet/application/face_base.rb', line 31
def render_as
@render_as
end
|
32
33
34
|
# File 'lib/puppet/application/face_base.rb', line 32
def type
@type
end
|
Instance Method Details
#find_application_argument(item) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/puppet/application/face_base.rb', line 170
def find_application_argument(item)
self.class.option_parser_commands.each do |options, _function|
options.each do |option|
next unless option =~ /^-/
pattern = /^#{option.sub('[no-]', '').sub(/[ =].*$/, '')}(?:[ =].*)?$/
next unless pattern.match(item)
return {
:argument => option =~ /[ =]/,
:optional => option =~ /[ =]\[/
}
end
end
nil end
|
#find_global_settings_argument(item) ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/puppet/application/face_base.rb', line 157
def find_global_settings_argument(item)
Puppet.settings.each do |_name, object|
object.optparse_args.each do |arg|
next unless arg =~ /^-/
pattern = /^#{arg.sub('[no-]', '').sub(/[ =].*$/, '')}(?:[ =].*)?$/
pattern.match item and return object
end
end
nil end
|
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/puppet/application/face_base.rb', line 211
def main
status = false
unless @action
puts Puppet::Face[:help, :current].help(@face.name)
raise _("%{face} does not respond to action %{arg}") % { face: face, arg: arguments.first }
end
if (arity = @action.positional_arg_count) > 0
unless (count = arguments.length) == arity then
raise ArgumentError, n_("puppet %{face} %{action} takes %{arg_count} argument, but you gave %{given_count}", "puppet %{face} %{action} takes %{arg_count} arguments, but you gave %{given_count}", arity - 1) % { face: @face.name, action: @action.name, arg_count: arity - 1, given_count: count - 1 }
end
end
if @face.deprecated?
Puppet.deprecation_warning(_("'puppet %{face}' is deprecated and will be removed in a future release") % { face: @face.name })
end
result = @face.send(@action.name, *arguments)
puts render(result, arguments) unless result.nil?
status = true
rescue SystemExit => detail
status = detail.status
rescue => detail
Puppet.log_exception(detail)
Puppet.err _("Try 'puppet help %{face} %{action}' for usage") % { face: @face.name, action: @action.name }
ensure
exit status
end
|
#parse_options ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/puppet/application/face_base.rb', line 63
def parse_options
@type = Puppet::Util::ConstantInflector.constant2file(self.class.name.to_s.sub(/.+:/, '')).to_sym
@face = Puppet::Face[@type, :current]
action_name = nil
index = -1
until action_name or (index += 1) >= command_line.args.length
item = command_line.args[index]
if item =~ /^-/
option = @face.options.find do |name|
item =~ /^-+#{name.to_s.gsub(/[-_]/, '[-_]')}(?:[ =].*)?$/
end
if option
option = @face.get_option(option)
if option.takes_argument? and !item.index('=')
index += 1 unless
option.optional_argument? and command_line.args[index + 1] =~ /^-/
end
else
option = find_global_settings_argument(item)
if option
unless Puppet.settings.boolean? option.name
index += 1 unless item =~ /^--#{option.name}=/
end
else
option = find_application_argument(item)
if option
index += 1 if option[:argument] and !(option[:optional])
else
raise OptionParser::InvalidOption, item.sub(/=.*$/, '')
end
end
end
else
action_name = item.to_sym
@action = Puppet::Face.find_action(@face.name, action_name)
@face = @action.face if @action
end
end
if @action.nil?
@action = @face.get_default_action()
if @action
@is_default_action = true
else
begin
super
rescue OptionParser::InvalidOption
end
face = @face.name
action = action_name.nil? ? 'default' : "'#{action_name}'"
msg = _("'%{face}' has no %{action} action. See `puppet help %{face}`.") % { face: face, action: action }
Puppet.err(msg)
Puppet::Util::Log.force_flushqueue()
exit false
end
end
@action.options.each do |o|
o = @action.get_option(o) self.class.option(*o.optparse) end
super
end
|
55
56
57
58
59
60
61
|
# File 'lib/puppet/application/face_base.rb', line 55
def preinit
super
Signal.trap(:INT) do
$stderr.puts _("Cancelling Face")
exit(0)
end
end
|
#render(result, args_and_options) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/puppet/application/face_base.rb', line 39
def render(result, args_and_options)
hook = action.when_rendering(render_as.name)
if hook
if hook.arity > 1
result = hook.call(result, *args_and_options)
else
result = hook.call(result)
end
end
render_as.render(result)
end
|
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/puppet/application/face_base.rb', line 187
def setup
Puppet::Util::Log.newdestination :console
@arguments = command_line.args
@arguments.delete_at(0) unless @is_default_action
@arguments << options
self.render_as ||= @action.render_as || :console
end
|