8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/compressit.rb', line 8
def run(arguments)
unless arguments.empty? || !arguments[0].include?('-')
optparser = OptionParser.new do|opts|
opts.banner = "Usage: compressit -command [FILE/DIR]"
opts.on('-h', '--help', 'Display this help') do
puts optparser
exit
end
opts.on('-v', '--version', 'Display current gem version') do
puts "Compressit-#{VERSION}"
end
opts.on('-f', '--file FILE', 'Compress FILE in place') do |file|
prepare(file)
end
opts.on('-F', '--files DIR', 'Compress files from DIR into DIR/compressed') do |dir|
prepare(dir)
end
end
begin optparser.parse!(arguments)
rescue OptionParser::ParseError => error
puts "#{error}"
puts optparser
exit
end
else
puts `compressit -h`
end
end
|