Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Use table printer in upload report
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsdeleo committed Sep 24, 2014
1 parent 134fbe8 commit 7c4f55c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/chef-dk/policyfile/reports/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# limitations under the License.
#

require 'chef-dk/policyfile/reports/table_printer'

module ChefDK
module Policyfile
module Reports
Expand All @@ -35,20 +37,23 @@ def initialize(reused_cbs: [], uploaded_cbs: [], ui: nil)

def show
reused_cbs.each do |cb_with_lock|
ui.msg("Using #{describe_lock(cb_with_lock.lock, justify_name_width, justify_version_width)}")
lock = cb_with_lock.lock
table.print_row("Using", lock.name, lock.version, "(#{lock.identifier[0,8]})")
end

uploaded_cbs.each do |cb_with_lock|
ui.msg("Uploaded #{describe_lock(cb_with_lock.lock, justify_name_width, justify_version_width)}")
lock = cb_with_lock.lock
table.print_row("Uploaded", lock.name, lock.version, "(#{lock.identifier[0,8]})")
end
end

def justify_name_width
@justify_name_width ||= cookbook_names.map {|e| e.size }.max
end

def justify_version_width
@justify_version_width ||= cookbook_version_numbers.map {|e| e.size }.max
def table
@table ||= TablePrinter.new(ui) do |t|
t.column(%w[ Using Uploaded ])
t.column(cookbook_names)
t.column(cookbook_version_numbers)
t.column
end
end

def cookbook_names
Expand All @@ -59,10 +64,6 @@ def cookbook_version_numbers
(reused_cbs + uploaded_cbs).map { |e| e.lock.version }
end

def describe_lock(lock, justify_name_width, justify_version_width)
"#{lock.name.ljust(justify_name_width)} #{lock.version.ljust(justify_version_width)} (#{lock.identifier[0,8]})"
end

end
end
end
Expand Down

0 comments on commit 7c4f55c

Please sign in to comment.