summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjkeiser <jkeiser@opscode.com>2012-12-23 15:37:33 -0800
committerJohn Keiser <jkeiser@opscode.com>2013-06-07 13:12:13 -0700
commit46f93b08adc69725f867852bdd730224eb97cb97 (patch)
tree5ba3c06f85593b9e4752aa0392c18a7a0c9a77f2
parentaacbb12ceed58c5bda6586e79a637d459457f8e3 (diff)
downloadchef-46f93b08adc69725f867852bdd730224eb97cb97.tar.gz
Use knife "ui.output" instead of puts
-rw-r--r--lib/chef/chef_fs/file_system.rb50
-rw-r--r--lib/chef/knife/delete.rb4
-rw-r--r--lib/chef/knife/deps.rb8
-rw-r--r--lib/chef/knife/diff.rb2
-rw-r--r--lib/chef/knife/download.rb2
-rw-r--r--lib/chef/knife/list.rb29
-rw-r--r--lib/chef/knife/raw.rb2
-rw-r--r--lib/chef/knife/show.rb6
-rw-r--r--lib/chef/knife/upload.rb2
9 files changed, 52 insertions, 53 deletions
diff --git a/lib/chef/chef_fs/file_system.rb b/lib/chef/chef_fs/file_system.rb
index 1805869e32..9ce4a23254 100644
--- a/lib/chef/chef_fs/file_system.rb
+++ b/lib/chef/chef_fs/file_system.rb
@@ -113,15 +113,15 @@ class Chef
# puts message
# end
#
- def self.copy_to(pattern, src_root, dest_root, recurse_depth, options)
+ def self.copy_to(pattern, src_root, dest_root, recurse_depth, options, ui)
found_result = false
list_pairs(pattern, src_root, dest_root) do |src, dest|
found_result = true
- new_dest_parent = get_or_create_parent(dest, options)
- copy_entries(src, dest, new_dest_parent, recurse_depth, options)
+ new_dest_parent = get_or_create_parent(dest, options, ui)
+ copy_entries(src, dest, new_dest_parent, recurse_depth, options, ui)
end
if !found_result && pattern.exact_path
- puts "#{pattern}: No such file or directory on remote or local"
+ ui.error "#{pattern}: No such file or directory on remote or local"
end
end
@@ -216,7 +216,7 @@ class Chef
private
# Copy two entries (could be files or dirs)
- def self.copy_entries(src_entry, dest_entry, new_dest_parent, recurse_depth, options)
+ def self.copy_entries(src_entry, dest_entry, new_dest_parent, recurse_depth, options, ui)
# A NOTE about this algorithm:
# There are cases where this algorithm does too many network requests.
# knife upload with a specific filename will first check if the file
@@ -233,10 +233,10 @@ class Chef
# If we would not have uploaded it, we will not purge it.
if src_entry.parent.can_have_child?(dest_entry.name, dest_entry.dir?)
if options[:dry_run]
- puts "Would delete #{dest_entry.path_for_printing}"
+ ui.output "Would delete #{dest_entry.path_for_printing}"
else
dest_entry.delete(true)
- puts "Deleted extra entry #{dest_entry.path_for_printing} (purge is on)"
+ ui.output "Deleted extra entry #{dest_entry.path_for_printing} (purge is on)"
end
else
Chef::Log.info("Not deleting extra entry #{dest_entry.path_for_printing} (purge is off)")
@@ -248,35 +248,35 @@ class Chef
# If the entry can do a copy directly from filesystem, do that.
if new_dest_parent.respond_to?(:create_child_from)
if options[:dry_run]
- puts "Would create #{dest_entry.path_for_printing}"
+ ui.output "Would create #{dest_entry.path_for_printing}"
else
new_dest_parent.create_child_from(src_entry)
- puts "Created #{dest_entry.path_for_printing}"
+ ui.output "Created #{dest_entry.path_for_printing}"
end
return
end
if src_entry.dir?
if options[:dry_run]
- puts "Would create #{dest_entry.path_for_printing}"
+ ui.output "Would create #{dest_entry.path_for_printing}"
new_dest_dir = new_dest_parent.child(src_entry.name)
else
new_dest_dir = new_dest_parent.create_child(src_entry.name, nil)
- puts "Created #{dest_entry.path_for_printing}/"
+ ui.output "Created #{dest_entry.path_for_printing}/"
end
# Directory creation is recursive.
if recurse_depth != 0
src_entry.children.each do |src_child|
new_dest_child = new_dest_dir.child(src_child.name)
- copy_entries(src_child, new_dest_child, new_dest_dir, recurse_depth ? recurse_depth - 1 : recurse_depth, options)
+ copy_entries(src_child, new_dest_child, new_dest_dir, recurse_depth ? recurse_depth - 1 : recurse_depth, options, ui)
end
end
else
if options[:dry_run]
- puts "Would create #{dest_entry.path_for_printing}"
+ ui.output "Would create #{dest_entry.path_for_printing}"
else
new_dest_parent.create_child(src_entry.name, src_entry.read)
- puts "Created #{dest_entry.path_for_printing}"
+ ui.output "Created #{dest_entry.path_for_printing}"
end
end
end
@@ -288,10 +288,10 @@ class Chef
if dest_entry.respond_to?(:copy_from)
if options[:force] || compare(src_entry, dest_entry)[0] == false
if options[:dry_run]
- puts "Would update #{dest_entry.path_for_printing}"
+ ui.output "Would update #{dest_entry.path_for_printing}"
else
dest_entry.copy_from(src_entry)
- puts "Updated #{dest_entry.path_for_printing}"
+ ui.output "Updated #{dest_entry.path_for_printing}"
end
end
return
@@ -303,17 +303,17 @@ class Chef
# If both are directories, recurse into their children
if recurse_depth != 0
child_pairs(src_entry, dest_entry).each do |src_child, dest_child|
- copy_entries(src_child, dest_child, dest_entry, recurse_depth ? recurse_depth - 1 : recurse_depth, options)
+ copy_entries(src_child, dest_child, dest_entry, recurse_depth ? recurse_depth - 1 : recurse_depth, options, ui)
end
end
else
# If they are different types.
- Chef::Log.error("File #{dest_entry.path_for_printing} is a directory while file #{dest_entry.path_for_printing} is a regular file\n")
+ ui.error("File #{dest_entry.path_for_printing} is a directory while file #{dest_entry.path_for_printing} is a regular file\n")
return
end
else
if dest_entry.dir?
- Chef::Log.error("File #{dest_entry.path_for_printing} is a directory while file #{dest_entry.path_for_printing} is a regular file\n")
+ ui.error("File #{dest_entry.path_for_printing} is a directory while file #{dest_entry.path_for_printing} is a regular file\n")
return
else
@@ -327,11 +327,11 @@ class Chef
end
if should_copy
if options[:dry_run]
- puts "Would update #{dest_entry.path_for_printing}"
+ ui.output "Would update #{dest_entry.path_for_printing}"
else
src_value = src_entry.read if src_value.nil?
dest_entry.write(src_value)
- puts "Updated #{dest_entry.path_for_printing}"
+ ui.output "Updated #{dest_entry.path_for_printing}"
end
end
end
@@ -339,15 +339,15 @@ class Chef
end
end
- def self.get_or_create_parent(entry, options)
+ def self.get_or_create_parent(entry, options, ui)
parent = entry.parent
if parent && !parent.exists?
- parent_parent = get_or_create_parent(entry.parent, options)
+ parent_parent = get_or_create_parent(entry.parent, options, ui)
if options[:dry_run]
- puts "Would create #{parent.path_for_printing}"
+ ui.output "Would create #{parent.path_for_printing}"
else
parent = parent_parent.create_child(parent.name, true)
- puts "Created #{parent.path_for_printing}"
+ ui.output "Created #{parent.path_for_printing}"
end
end
return parent
diff --git a/lib/chef/knife/delete.rb b/lib/chef/knife/delete.rb
index 1ab36c4ec6..95fdea969c 100644
--- a/lib/chef/knife/delete.rb
+++ b/lib/chef/knife/delete.rb
@@ -65,9 +65,9 @@ class Chef
end
end
if deleted_any
- puts "Deleted #{format_path(results[0].path)}"
+ output("Deleted #{format_path(results[0].path)}")
else
- STDERR.puts "#{format_path(results[0].path)}: No such file or directory"
+ ui.error "#{format_path(results[0].path)}: No such file or directory"
end
end
end
diff --git a/lib/chef/knife/deps.rb b/lib/chef/knife/deps.rb
index 489a166566..9de457b574 100644
--- a/lib/chef/knife/deps.rb
+++ b/lib/chef/knife/deps.rb
@@ -23,7 +23,7 @@ class Chef
def run
if config[:tree] && config[:recurse]
- STDERR.puts "--recurse requires --tree"
+ ui.error "--recurse requires --tree"
exit(1)
end
config[:recurse] = true if config[:recurse].nil?
@@ -54,7 +54,7 @@ class Chef
def print_dependencies_tree(entry, dependencies, printed = {}, depth = 0)
dependencies[entry.path] = get_dependencies(entry) if !dependencies[entry.path]
- puts "#{' '*depth}#{format_path(entry.path)}"
+ output "#{' '*depth}#{format_path(entry.path)}"
if !printed[entry.path] && (config[:recurse] || depth <= 1)
printed[entry.path] = true
dependencies[entry.path].each do |child|
@@ -68,11 +68,11 @@ class Chef
begin
object = entry.chef_object
rescue Chef::ChefFS::FileSystem::NotFoundError
- STDERR.puts "#{result.path_for_printing}: No such file or directory"
+ ui.error "#{result.path_for_printing}: No such file or directory"
return []
end
if !object
- STDERR.puts "ERROR: #{entry} is not a Chef object!"
+ ui.error "#{entry} is not a Chef object!"
return []
end
diff --git a/lib/chef/knife/diff.rb b/lib/chef/knife/diff.rb
index 57d3bf3f0c..b2d8868892 100644
--- a/lib/chef/knife/diff.rb
+++ b/lib/chef/knife/diff.rb
@@ -36,7 +36,7 @@ class Chef
# Get the matches (recursively)
patterns.each do |pattern|
Chef::ChefFS::CommandLine.diff(pattern, chef_fs, local_fs, config[:recurse] ? nil : 1, output_mode) do |diff|
- puts diff
+ output diff
end
end
end
diff --git a/lib/chef/knife/download.rb b/lib/chef/knife/download.rb
index dc2588b6b5..4133b503b6 100644
--- a/lib/chef/knife/download.rb
+++ b/lib/chef/knife/download.rb
@@ -41,7 +41,7 @@ class Chef
end
pattern_args.each do |pattern|
- Chef::ChefFS::FileSystem.copy_to(pattern, chef_fs, local_fs, config[:recurse] ? nil : 1, config)
+ Chef::ChefFS::FileSystem.copy_to(pattern, chef_fs, local_fs, config[:recurse] ? nil : 1, config, ui)
end
end
end
diff --git a/lib/chef/knife/list.rb b/lib/chef/knife/list.rb
index cbc08278f7..3dc363800f 100644
--- a/lib/chef/knife/list.rb
+++ b/lib/chef/knife/list.rb
@@ -34,7 +34,7 @@ class Chef
elsif result.exists?
results << result
elsif pattern.exact_path
- STDERR.puts "#{format_path(result.path)}: No such file or directory"
+ ui.error "#{format_path(result.path)}: No such file or directory"
end
end
end
@@ -49,8 +49,8 @@ class Chef
print_result_paths results
dir_results.each do |result, children|
- puts ""
- puts "#{format_path(result.path)}:"
+ output ""
+ output "#{format_path(result.path)}:"
print_results(children.map { |result| result.name }.sort, "")
end
end
@@ -59,7 +59,7 @@ class Chef
begin
children = result.children.sort_by { |child| child.name }
rescue Chef::ChefFS::FileSystem::NotFoundError
- STDERR.puts "#{format_path(result.path)}: No such file or directory"
+ ui.error "#{format_path(result.path)}: No such file or directory"
return []
end
@@ -91,21 +91,20 @@ class Chef
print_space = results.map { |result| result.length }.max + 2
# TODO: tput cols is not cross platform
- columns = $stdout.isatty ? Integer(`tput cols`) : 0
- current_column = 0
+ columns = stdout.isatty ? Integer(`tput cols`) : 0
+ current_line = ''
results.each do |result|
- if current_column != 0 && current_column + print_space > columns
- puts ""
- current_column = 0
+ if current_line.length > 0 && current_line.length + print_space > columns
+ output current_line
+ current_line = ''
end
- if current_column == 0
- print indent
- current_column += indent.length
+ if current_line.length == 0
+ current_line << indent
end
- print result + (' ' * (print_space - result.length))
- current_column += print_space
+ current_line << result
+ current_line << (' ' * (print_space - result.length))
end
- puts ""
+ output current_line if current_line.length > 0
end
end
end
diff --git a/lib/chef/knife/raw.rb b/lib/chef/knife/raw.rb
index ad5d5f33ef..8ee189fbe8 100644
--- a/lib/chef/knife/raw.rb
+++ b/lib/chef/knife/raw.rb
@@ -39,7 +39,7 @@ class Chef
data = IO.read(config[:input])
end
chef_rest = Chef::REST.new(Chef::Config[:chef_server_url])
- puts api_request(chef_rest, config[:method].to_sym, chef_rest.create_url(name_args[0]), {}, data)
+ output api_request(chef_rest, config[:method].to_sym, chef_rest.create_url(name_args[0]), {}, data)
end
ACCEPT_ENCODING = "Accept-Encoding".freeze
diff --git a/lib/chef/knife/show.rb b/lib/chef/knife/show.rb
index 16d4eb2dab..e0dd17974d 100644
--- a/lib/chef/knife/show.rb
+++ b/lib/chef/knife/show.rb
@@ -18,14 +18,14 @@ class Chef
pattern_args.each do |pattern|
Chef::ChefFS::FileSystem.list(config[:local] ? local_fs : chef_fs, pattern) do |result|
if result.dir?
- STDERR.puts "#{result.path_for_printing}: is a directory" if pattern.exact_path
+ ui.error "#{result.path_for_printing}: is a directory" if pattern.exact_path
else
begin
value = result.read
- puts "#{result.path_for_printing}:"
+ output "#{result.path_for_printing}:"
output(format_for_display(value))
rescue Chef::ChefFS::FileSystem::NotFoundError
- STDERR.puts "#{result.path_for_printing}: No such file or directory"
+ ui.error "#{result.path_for_printing}: No such file or directory"
end
end
end
diff --git a/lib/chef/knife/upload.rb b/lib/chef/knife/upload.rb
index bb1e365798..cca88e84a8 100644
--- a/lib/chef/knife/upload.rb
+++ b/lib/chef/knife/upload.rb
@@ -41,7 +41,7 @@ class Chef
end
pattern_args.each do |pattern|
- Chef::ChefFS::FileSystem.copy_to(pattern, local_fs, chef_fs, config[:recurse] ? nil : 1, config)
+ Chef::ChefFS::FileSystem.copy_to(pattern, local_fs, chef_fs, config[:recurse] ? nil : 1, config, ui)
end
end
end