Class: RsyncCron::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rsync_cron/cli.rb

Constant Summary collapse

SHELL =
`which crontab`.strip

Instance Method Summary collapse

Constructor Details

#initialize(args, io = STDOUT, shell = SHELL) ⇒ CLI

Returns a new instance of CLI.



11
12
13
14
15
16
# File 'lib/rsync_cron/cli.rb', line 11

def initialize(args, io = STDOUT, shell = SHELL)
  @args = args
  @io = io
  @cron = Cron.factory("* 0 * * *")
  @shell = shell
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rsync_cron/cli.rb', line 18

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)
  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