31
32
33
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/dircat/cat_on_yaml_cli/command_diff.rb', line 31
def exec(main, options, rest)
if rest.length < 2
puts "you must provide two args (catalogs or directory)"
puts "-h to print help"
return false
end
cat_filename1 = rest[0]
cat_filename2 = rest[1]
if File.directory?(cat_filename1)
puts "build first set from directory #{cat_filename1}"
s1 = CatOnYaml.from_dir(cat_filename1)
elsif File.exists?(cat_filename1)
puts "load catalog #{cat_filename1}"
s1 = CatOnYaml.from_file(cat_filename1)
else
puts "#{cat_filename1} is not a catalog file or directory"
return 1
end
if File.directory?(cat_filename2)
puts "build first set from directory #{cat_filename2}"
s2 = CatOnYaml.from_dir(cat_filename2)
elsif File.exists?(cat_filename2)
puts "load catalog #{cat_filename2}"
s2 = CatOnYaml.from_file(cat_filename2)
else
puts "#{cat_filename2} is not a catalog file or directory"
return 1
end
s3 = s1 - s2
if s3.empty?
puts "no difference (first catalog contains all file of second catalog)"
else
puts "differences (file in first catalog not contained in the second catalog)"
case options.format
when "simple"
s3.fmt_simple
when "ruby"
s3.fmt_ruby(".")
else
s3.fmt_simple
end
end
true
end
|