class Chef::Formatters::Base
Formatters::Base
¶ ↑
Base
class that all formatters should inherit from.
Attributes
Public Class Methods
# File lib/chef/formatters/base.rb, line 66 def self.cli_name(name) Chef::Formatters.register(name, self) end
# File lib/chef/formatters/base.rb, line 74 def initialize(out, err) @output = IndentableOutputStream.new(out, err) end
Public Instance Methods
Delegates to file_load_failed
# File lib/chef/formatters/base.rb, line 190 def attribute_file_load_failed(path, exception) file_load_failed(path, exception) end
Delegates to file_loaded
# File lib/chef/formatters/base.rb, line 185 def attribute_file_loaded(path) file_loaded(path) end
# File lib/chef/formatters/base.rb, line 128 def cookbook_resolution_failed(expanded_run_list, exception) description = ErrorMapper.cookbook_resolution_failed(expanded_run_list, exception) display_error(description) end
# File lib/chef/formatters/base.rb, line 133 def cookbook_sync_failed(cookbooks, exception) description = ErrorMapper.cookbook_sync_failed(cookbooks, exception) display_error(description) end
Delegates to file_load_failed
# File lib/chef/formatters/base.rb, line 200 def definition_file_load_failed(path, exception) file_load_failed(path, exception) end
Delegates to file_loaded
# File lib/chef/formatters/base.rb, line 195 def definition_file_loaded(path) file_loaded(path) end
Log
a deprecation warning object.
@param deprecation [Chef::Deprecated::Base] Deprecation
object to log.
In previous versions, this could be a string. Don't do that anymore.
@param location [Object] Unused, present only for compatibility.
# File lib/chef/formatters/base.rb, line 219 def deprecation(deprecation, _location = nil) Chef::Log.deprecation(deprecation.to_s) unless deprecation.silenced? end
Input: a Formatters::ErrorDescription
object. Outputs error to STDOUT.
# File lib/chef/formatters/base.rb, line 107 def display_error(description) puts("") description.display(output) end
Generic callback for any attribute/library/lwrp/recipe file throwing an exception when loaded. Default behavior is to use CompileErrorInspector to print contextual info about the failure.
# File lib/chef/formatters/base.rb, line 154 def file_load_failed(path, exception) description = ErrorMapper.file_load_failed(path, exception) display_error(description) end
Generic callback for any attribute/library/lwrp/recipe file in a cookbook getting loaded. The per-filetype callbacks for file load are overridden so that they call this instead. This means that a subclass of Formatters::Base
can implement file_loaded
to do the same thing for every kind of file that Chef
loads from a recipe instead of implementing all the per-filetype callbacks.
# File lib/chef/formatters/base.rb, line 149 def file_loaded(path); end
# File lib/chef/formatters/base.rb, line 94 def indent_by(amount) @output.indent += amount if @output.indent < 0 # This is left commented out for now. We need to uncomment it and fix at least one bug in # the formatter, and then leave this line uncommented in the future. # Chef::Log.warn "Internal Formatter Error -- Attempt to indent by negative number of spaces" @output.indent = 0 end @output.indent end
# File lib/chef/formatters/base.rb, line 227 def is_formatter? true end
# File lib/chef/formatters/base.rb, line 223 def is_structured_deprecation?(deprecation) deprecation.is_a?(Chef::Deprecated::Base) end
Delegates to file_load_failed
# File lib/chef/formatters/base.rb, line 170 def library_file_load_failed(path, exception) file_load_failed(path, exception) end
Delegates to file_loaded
# File lib/chef/formatters/base.rb, line 165 def library_file_loaded(path) file_loaded(path) end
Delegates to file_load_failed
# File lib/chef/formatters/base.rb, line 180 def lwrp_file_load_failed(path, exception) file_load_failed(path, exception) end
Delegates to file_loaded
# File lib/chef/formatters/base.rb, line 175 def lwrp_file_loaded(path) file_loaded(path) end
# File lib/chef/formatters/base.rb, line 118 def node_load_failed(node_name, exception, config) description = ErrorMapper.node_load_failed(node_name, exception, config) display_error(description) end
# File lib/chef/formatters/base.rb, line 82 def print(*args) @output.print(*args) end
# File lib/chef/formatters/base.rb, line 78 def puts(*args) @output.puts(*args) end
# File lib/chef/formatters/base.rb, line 86 def puts_line(*args) @output.puts_line(*args) end
Delegates to file_load_failed
# File lib/chef/formatters/base.rb, line 210 def recipe_file_load_failed(path, exception, recipe) file_load_failed(path, exception) end
Delegates to file_loaded
# File lib/chef/formatters/base.rb, line 205 def recipe_file_loaded(path, recipe) file_loaded(path) end
# File lib/chef/formatters/base.rb, line 159 def recipe_not_found(exception) description = ErrorMapper.file_load_failed(nil, exception) display_error(description) end
# File lib/chef/formatters/base.rb, line 112 def registration_failed(node_name, exception, config) # A Formatters::ErrorDescription object description = ErrorMapper.registration_failed(node_name, exception, config) display_error(description) end
# File lib/chef/formatters/base.rb, line 138 def resource_failed(resource, action, exception) description = ErrorMapper.resource_failed(resource, action, exception) display_error(description) unless resource.ignore_failure && resource.ignore_failure.to_s == "quiet" end
# File lib/chef/formatters/base.rb, line 123 def run_list_expand_failed(node, exception) description = ErrorMapper.run_list_expand_failed(node, exception) display_error(description) end
# File lib/chef/formatters/base.rb, line 90 def start_line(*args) @output.start_line(*args) end