lib/rsync_cron/cli.rb in rsync_cron-1.0.8 vs lib/rsync_cron/cli.rb in rsync_cron-1.1.0
- old
+ new
@@ -6,35 +6,38 @@
module RsyncCron
class CLI
SHELL = `which crontab`.strip
+ attr_reader :options
+
def initialize(args, io = STDOUT, shell = SHELL)
@args = args
@io = io
@cron = Cron.factory("* 0 * * *")
@shell = shell
+ @options = Options.new
end
def call
parser.parse!(@args)
return @io.puts "specify valid src" unless @src
return @io.puts "specify valid dest" unless @dest
- command = Command.new(src: @src, dest: @dest, log: @log, io: @io)
+ command = Command.new(src: @src, dest: @dest, options: @options, log: @log, io: @io)
return unless command.valid? if @check
crontab = "#{@cron} #{command}"
return @io.puts crontab unless @shell
Installer.new(crontab, @shell).call.tap do |res|
@io.puts "new crontab installed" if res
end
end
private def parser
OptionParser.new do |opts|
- opts.banner = "Usage: rsync_cron --cron=15,30 21 * * * --src=/ --dest=/tmp --log=/var/log/rsync.log"
+ opts.banner = "Usage: rsync_cron --cron='15,30 21' --src=/ --dest=/tmp --log=/var/log/rsync.log --opts=noatime,temp-dir='./temp'"
- opts.on("-cCRON", "--cron=CRON", "The cron string, i.e.: 15 21 * * *") do |cron|
+ opts.on("-cCRON", "--cron=CRON", "The cron string, i.e.: '15 21 * * *'") do |cron|
@cron = Cron.factory(cron)
end
opts.on("-sSRC", "--src=SRC", "The rsync source, i.e. user@src.com:files") do |src|
@src = Host.factory(src)
@@ -44,9 +47,13 @@
@dest = Host.factory(dest)
end
opts.on("-lLOG", "--log=LOG", "log command output to specified file") do |log|
@log = log
+ end
+
+ opts.on("-oOPTS", "--opts=OPTS", "merge specified extra options") do |_opts|
+ @options << _opts
end
opts.on("-p", "--print", "Print crontab command without installing it") do
@shell = nil
end