class DailyWeeklyMonthly::Cli

Constants

OPTIONS

Public Class Methods

new(args) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 19
def initialize args
  @options = {}
  @command = parse args
  raise "Please supply a command to run" if @command.empty?
  @command = @command.join(" ")
end

Public Instance Methods

call() click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 26
def call
  DailyWeeklyMonthly.start @command, @options
end

Private Instance Methods

parse(args) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 32
def parse args
  args.options do |opts|
    opts.banner = "Usage: daily_weekly_monthly \"database backup command\" [options]"
    parse_all_options(opts)
  end
  args
end
parse_all_options(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 40
def parse_all_options opts
  OPTIONS.each do |option|
    send("parse_#{option}", opts)
  end
  opts.parse!
end
parse_dir(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 101
def parse_dir opts
  opts.on("-d d", "--dir=d", "Backups directory path", String) do |d|
    @options[:backups_dir] = d
  end
end
parse_ext(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 89
def parse_ext opts
  opts.on("-e e", "--ext=e", "Backup file extension", String) do |e|
    @options[:output_extension] = e
  end
end
parse_keep_days(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 77
def parse_keep_days opts
  opts.on("-D n", "--days-to-keep=n", "Daily backups to keep", OptionParser::DecimalInteger) do |n|
    @options[:days_to_keep] = n
  end
end
parse_keep_months(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 47
def parse_keep_months opts
  opts.on("-M n", "--months-to-keep=n", "Monthly backups to keep", OptionParser::DecimalInteger) do |n|
    @options[:months_to_keep] = n
  end
end
parse_keep_weeks(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 71
def parse_keep_weeks opts
  opts.on("-W n", "--weeks-to-keep=n", "Weekly backups to keep", OptionParser::DecimalInteger) do |n|
    @options[:weeks_to_keep] = n
  end
end
parse_month_day(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 83
def parse_month_day opts
  opts.on("-m n", "--month-day=n", "Day of month to run on", OptionParser::DecimalInteger) do |n|
    @options[:day_of_month] = n
  end
end
parse_notify(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 65
def parse_notify opts
  opts.on("-n s", "--notify=s", "Notification email address", String) do |s|
    @options[:notify] = s
  end
end
parse_smtp_port(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 59
def parse_smtp_port opts
  opts.on("-p p", "--smtp-server=p", "SMTP port for notifications", OptionParser::DecimalInteger) do |p|
    @options[:smtp_port] = p
  end
end
parse_smtp_server(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 53
def parse_smtp_server opts
  opts.on("-s s", "--smtp-server=s", "SMTP server for notifications", String) do |s|
    @options[:smtp_server] = s
  end
end
parse_week_day(opts) click to toggle source
# File lib/daily_weekly_monthly/cli.rb, line 95
def parse_week_day opts
  opts.on("-w n", "--week-day=n", "Week day to run on", OptionParser::DecimalInteger) do |n|
    @options[:day_of_week] = n
  end
end