summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-04-30 10:17:30 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-04-30 10:17:30 -0700
commit5cdb1a0e85e42433369cbb14715648d071d6a283 (patch)
tree33e8e1cdea02bc99f6fd1717953eb46188e0639c
parent33d86aa1217877f6eae000edd7b45741c9a754c3 (diff)
downloadchef-5cdb1a0e85e42433369cbb14715648d071d6a283.tar.gz
Refactor for simplicity, make the resource a stream
so that it is guaranteed to stick together or at least not get anything else appended to it
-rw-r--r--lib/chef/formatters/base.rb44
-rw-r--r--lib/chef/formatters/doc.rb8
2 files changed, 28 insertions, 24 deletions
diff --git a/lib/chef/formatters/base.rb b/lib/chef/formatters/base.rb
index 612aab3085..5e7e7d7c46 100644
--- a/lib/chef/formatters/base.rb
+++ b/lib/chef/formatters/base.rb
@@ -57,7 +57,7 @@ class Chef
end
# == Outputter
- # Handles basic printing tasks like colorizing.
+ # Handles basic printing tasks like colorizing and indenting.
# --
# TODO: Duplicates functionality from knife, upfactor.
class Outputter
@@ -66,7 +66,7 @@ class Chef
attr_reader :err
attr_accessor :indent
attr_reader :line_started
- attr_accessor :sticky_tag
+ attr_accessor :stream
def initialize(out, err)
@out, @err = out, err
@@ -85,35 +85,31 @@ class Chef
# but will not terminate the line (future print and puts statements
# will start off where this print left off).
def color(string, *colors)
- print(string, :colors => colors)
+ print(string, from_args(colors))
+ end
+
+ # Print the start of a new line. This will terminate any existing lines and
+ # cause indentation but will not move to the next line yet (future 'print'
+ # and 'puts' statements will stay on this line).
+ def start_line(string, *colors)
+ print(string, from_args(colors, :start_line => true))
end
# Print a line. This will continue from the last start_line or print,
# or start a new line and indent if necessary.
def puts(string, *colors)
- print(string, :end_line => true, :colors => colors)
+ print(string, from_args(colors, :end_line => true))
end
# Print an entire line from start to end. This will terminate any existing
# lines and cause indentation.
def puts_line(string, *colors)
- print(string, :start_line => true, :end_line => true, :colors => colors)
- end
-
- # Print the start of a new line. This will terminate any existing lines and
- # cause indentation but will not move to the next line yet (future 'print'
- # and 'puts' statements will stay on this line).
- def start_line(string, *colors)
- print(string, :start_line => true, :colors => colors)
+ print(string, from_args(colors, :start_line => true, :end_line => true))
end
- # Print a line, with possible options.
+ # Print a string. Without any further options, this will
def print(string, *colors)
- if colors.size == 1 && colors[0].kind_of?(Hash)
- options = colors[0]
- else
- options = { :colors => colors }
- end
+ options = from_args(colors)
# If we aren't printing to the same stream, or if start_line is true,
# move to the next line.
@@ -129,7 +125,7 @@ class Chef
printed_anything = false
string.lines.each do |line|
printed_anything = true
- print_line_with_options(line, options)
+ print_line(line, options)
end
if options[:end_line]
@@ -146,7 +142,15 @@ class Chef
private
- def print_line_with_options(line, options)
+ def from_args(colors, merge_options = {})
+ if colors.size == 1 && colors[0].kind_of?(Hash)
+ merge_options.merge(colors[0])
+ else
+ merge_options.merge({ :colors => colors })
+ end
+ end
+
+ def print_line(line, options)
# Start the line with indent if it is not started
if !@line_started
@out.print ' ' * indent
diff --git a/lib/chef/formatters/doc.rb b/lib/chef/formatters/doc.rb
index c8b61cc433..4a08b9d095 100644
--- a/lib/chef/formatters/doc.rb
+++ b/lib/chef/formatters/doc.rb
@@ -166,7 +166,7 @@ class Chef
indent
end
# TODO: info about notifies
- start_line "* #{resource} action #{action}"
+ start_line "* #{resource} action #{action}", :stream => resource
indent
end
@@ -183,7 +183,7 @@ class Chef
# Called when a resource action has been skipped b/c of a conditional
def resource_skipped(resource, action, conditional)
# TODO: more info about conditional
- puts " (skipped due to #{conditional.short_description})"
+ puts " (skipped due to #{conditional.short_description})", :stream => resource
unindent
end
@@ -194,12 +194,12 @@ class Chef
# Called when a resource has no converge actions, e.g., it was already correct.
def resource_up_to_date(resource, action)
@up_to_date_resources+= 1
- puts " (up to date)"
+ puts " (up to date)", :stream => resource
unindent
end
def resource_bypassed(resource, action, provider)
- puts " (Skipped: whyrun not supported by provider #{provider.class.name})"
+ puts " (Skipped: whyrun not supported by provider #{provider.class.name})", :stream => resource
unindent
end