26
27
28
29
30
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
86
87
88
|
# File 'lib/epdiff.rb', line 26
def execute(*args)
tmpdir = Dir.mktmpdir
diff_path = "diff"
unzip_path = nil
opts = OptionParser.new do |opts|
opts.banner = "Usage: epdiff [options] [filename] [filename]\n"
opts.on('-t','--tmpdir DIR', 'Set tepmorary directory') do |dir|
tmpdir = dir
end
opts.on('--diff-command PATH', 'Specify diff command path') do |path|
diff_path = path
end
opts.on('--unzip-command PATH', 'Specify unzip command path') do |path|
unzip_path = path
end
opts.on('-h', '--help', 'Show this help message') do
puts opts
exit
end
opts.on('-v', '--version', 'Show version number') do
puts Epdiff::VERSION
exit
end
end
begin
opts.parse!(args)
if args.size != 2
puts opts
exit
end
file1, file2 = *args
FileUtils.mkdir_p(tmpdir+"/file1")
FileUtils.mkdir_p(tmpdir+"/file2")
if unzip_path
%x("#{unzip_path}" "#{file1}" -d "#{tmpdir}/file1")
%x("#{unzip_path}" "#{file2}" -d "#{tmpdir}/file2")
else
unzip(file1, "#{tmpdir}/file1")
unzip(file2, "#{tmpdir}/file2")
end
IO.popen("'#{diff_path}' -r -u '#{tmpdir}/file1' '#{tmpdir}/file2'") do |io|
print io.read.gsub(/#{Regexp.escape(tmpdir)}/, "")
end
rescue => e
warn e
puts opts
end
end
|