Class: RsyncCron::CLI

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

Constant Summary collapse

SHELL =
`which crontab`.strip

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CLI.



13
14
15
16
17
18
19
# File 'lib/rsync_cron/cli.rb', line 13

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rsync_cron/cli.rb', line 21

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