#!/usr/bin/env ruby require 'tms' require 'optparse' def option_parser @option_parser ||= OptionParser.new do |op| op.banner = <<-BANNER #{op.program_name}, version #{Tms.version} Usege: List: #{op.program_name} [options] Diff: #{op.program_name} [options] id|nXXX [id|nXXX] BANNER op.on('-d', '--directory DIRECTORY', 'Use backup directory') do |backups_dir| Tms::Backup.backups_dir = backups_dir end op.on('-f', '--filter DIRECTORY', 'Show diff starting from directory', ' (can be used multiple times)') do |filter_dir| Tms::Backup.add_filter_dir(filter_dir) end op.on('-i', '--[no-]in-progress', 'Show backups in progress', ' (note: some directories will be', ' empty in unfinished backups)') do |show_in_progress| Tms::Backup.show_in_progress = show_in_progress end op.on('-l', '--[no-]long', 'Show more info about backup in list') do |show_all_columns| Tms::Backup.show_all_columns = show_all_columns end op.on('--[no-]color', 'Use color', ' (true by default if stdout is a tty)') do |colorize| Tms::Backup.colorize = colorize end op.on('--[no-]progress', 'Show progress when counting folder size', ' (true by default if stderr is a tty)') do |show_progress| Tms::Backup.show_progress = show_progress end op.on('--[no-]decimal', 'Use base 10 size') do |use_decimal| Tms::Space.base10 = use_decimal end op.on_tail('-h', '--help', 'Show this message') do puts op.help exit end op.on_tail('--version', 'Show version') do puts Tms.version exit end end end ids, options = ARGV.partition{ |arg| arg =~ /^[\-n]?\d+$/ } begin option_parser.parse!(options) rescue OptionParser::ParseError => e abort "#{e.to_s}\n#{option_parser.help}" end unless options.empty? abort "Unknown arguments: #{options.join(' ')}" end case ids.length when 0 Tms.list when 1..2 Tms.diff(*ids) else abort 'Max two arguments' end