diff options
Diffstat (limited to 'lib/chef/knife/environment_compare.rb')
-rw-r--r-- | lib/chef/knife/environment_compare.rb | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/lib/chef/knife/environment_compare.rb b/lib/chef/knife/environment_compare.rb index 1a3389e2c8..8a2ef853d3 100644 --- a/lib/chef/knife/environment_compare.rb +++ b/lib/chef/knife/environment_compare.rb @@ -15,37 +15,37 @@ # See the License for the specific language governing permissions and # limitations under the License. # - + require "chef/knife" - + class Chef class Knife class EnvironmentCompare < Knife - + deps do require "chef/environment" end - + banner "knife environment compare [ENVIRONMENT..] (options)" option :all, :short => "-a", :long => "--all", :description => "Show all cookbooks", - :boolean => true + :boolean => true option :mismatch, :short => "-m", :long => "--mismatch", :description => "Only show mismatching versions", :boolean => true - + def run # Get the commandline environments or all if none are provided. - environments = environment_list + environments = environment_list # Get a list of all cookbooks that have constraints and their environment. - constraints = constraint_list(environments) + constraints = constraint_list(environments) # Get the total list of cookbooks that have constraints cookbooks = cookbook_list(constraints) @@ -55,7 +55,7 @@ class Chef ui.error "Cannot find any environment cookbook constraints" exit 1 end - + # Get all cookbooks so we can compare them all cookbooks = rest.get("/cookbooks?num_versions=1") if config[:all] @@ -77,11 +77,11 @@ class Chef else environments = Chef::Environment.list end - end + end def constraint_list(environments) constraints = {} - environments.each do |env,url| + environments.each do |env, url| # Because you cannot modify the default environment I filter it out here. unless env == "_default" envdata = Chef::Environment.load(env) @@ -91,22 +91,22 @@ class Chef end constraints end - + def cookbook_list(constraints) result = {} constraints.each { |env, cb| result.merge!(cb) } result - end + end def matrix_output(cookbooks, constraints) rows = [ "" ] environments = [] - constraints.each { |e,v| environments << e.to_s } + constraints.each { |e, v| environments << e.to_s } columns = environments.count + 1 environments.each { |env| rows << ui.color(env, :bold) } - cookbooks.each do |c,v| + cookbooks.each do |c, v| total = [] - environments.each { |n| total << constraints[n][c]} + environments.each { |n| total << constraints[n][c] } if total.uniq.count == 1 next if config[:mismatch] color = :white @@ -116,7 +116,7 @@ class Chef rows << ui.color(c, :bold) environments.each do |e| tag = constraints[e][c] || "latest" - rows << ui.color(tag, color) + rows << ui.color(tag, color) end end ui.list(rows, :uneven_columns_across, columns) |