bin/image_optim in image_optim-0.6.0 vs bin/image_optim in image_optim-0.7.0

- old
+ new

@@ -8,35 +8,41 @@ options = {} option_parser = OptionParser.new do |op| op.banner = <<-TEXT -#{op.program_name}, version #{ImageOptim.version} +#{op.program_name} v#{ImageOptim.version} Usege: #{op.program_name} [options] image_path … TEXT + op.on('-r', '-R', '--recursive', 'Recurively scan directories for images') do |recursive| + options[:recursive] = recursive + end + + op.separator nil + op.on('--[no-]threads NUMBER', Integer, 'Number of threads or disable (defaults to number of processors)') do |threads| options[:threads] = threads end op.on('--[no-]nice NUMBER', Integer, 'Nice level (defaults to 10)') do |nice| options[:nice] = nice end + op.separator nil + ImageOptim::Worker.klasses.each do |klass| bin = klass.underscored_name.to_sym - op.on("--[no-]#{bin} PATH", "#{bin} path or disable") do |path| - options[bin] = path + op.on("--no-#{bin}", "disable #{bin} worker") do |enable| + options[bin] = enable end end - op.on('-r', '-R', '--recursive', 'Scan directories') do |recursive| - options[:recursive] = recursive - end + op.separator nil op.on('-v', '--verbose', 'Verbose info') do |verbose| options[:verbose] = verbose end @@ -59,28 +65,28 @@ if ARGV.empty? abort "specify image paths to optimize\n\n#{option_parser.help}" else recursive = options.delete(:recursive) - io = begin + image_optim = begin ImageOptim.new(options) - rescue ImageOptim::ConfigurationError, ImageOptim::BinaryNotFoundError => e + rescue ImageOptim::ConfigurationError => e abort e end paths = [] ARGV.each do |arg| if File.file?(arg) - if io.optimizable?(arg) + if image_optim.optimizable?(arg) paths << arg else warn "#{arg} is not an image or there is no optimizer for it" end else if recursive Find.find(arg) do |path| - paths << path if File.file?(path) && io.optimizable?(path) + paths << path if File.file?(path) && image_optim.optimizable?(path) end else warn "#{arg} is not a file" end end @@ -123,10 +129,10 @@ def size_percent(src_size, dst_size) '%5.2f%% %s' % [100 - 100.0 * dst_size / src_size, Space.space(src_size - dst_size)] end - results = io.optimize_images(paths) do |src, dst| + results = image_optim.optimize_images(paths) do |src, dst| if dst src_size, dst_size = src.size, dst.size percent = size_percent(src_size, dst_size) dst.replace(src) ["#{percent} #{src}", src_size, dst_size]