Class: KnifeRunlistCompare::RunlistCompare

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/runlist-compare.rb

Instance Method Summary collapse

Instance Method Details

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chef/knife/runlist-compare.rb', line 34

def run

  if @name_args.length != 2
    ui.error "You must specify two run_lists to compare"
    ui.msg opt_parser
    exit 1
  end


  runlist1 = Chef::RunList.new
  @name_args.first.split(",").each{|r|runlist1.add(r)}

  runlist2 = Chef::RunList.new
  @name_args.last.split(",").each{|r|runlist2.add(r)}

  exp_runlist_1 = runlist1.expand(config[:environment],config[:data_source]).recipes
  exp_runlist_2 = runlist2.expand(config[:environment],config[:data_source]).recipes

  ui.info "run_list #{@name_args.first} expands to the following recipes:"
  ui.info exp_runlist_1.inspect

  ui.info "\nrun_list #{@name_args.last} expands to the following recipes:"
  ui.info exp_runlist_2.inspect

  ui.info "\nThe following is the diff of the expanded recipe lists:"
  Diffy::Diff.default_format = :color

  runlist_diff = Diffy::Diff.new(exp_runlist_1.join("\n"), exp_runlist_2.join("\n"),:diff=>"-U #{config[:context_lines]}")
  puts runlist_diff

end