Class: Ffsr::Mainclass

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

Overview

main program begins here

Instance Method Summary collapse

Instance Method Details

#ConditionalExit(options) ⇒ Object

ConditionalExit This function exits program if there were command line errors



68
69
70
71
72
73
# File 'lib/ffsr.rb', line 68

def ConditionalExit(options)
  if options[:opterrors] > 0
    pp options
    exit OPTION_ERROR
  end
end

#mainObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ffsr.rb', line 20

def main
  # primary parse of the commandline options
  begin
    options = OptParse.parse(ARGV)
    raise CommandLineErrorHandler.new('No program and/or files are given') if ARGV.size < 2
  rescue CommandLineErrorHandler => e
    e.printMessage
    options[:opterrors] += 1
  end

  ConditionalExit(options)

  program, *files = ARGV

# check existence of the program
  begin
    raise CommandLineErrorHandler.new("The program executable \'#{program}\' does not exist") if File.file?(program) == false
  rescue CommandLineErrorHandler => e
    e.printMessage
    options[:opterrors] += 1
  end

  ConditionalExit(options)

# check if the file is executable
  begin
    raise CommandLineErrorHandler.new("\'#{program}\' is not an executable file") if File.executable?(program) == false
  rescue CommandLineErrorHandler => e
    e.printMessage
    options[:opterrors] += 1
  end

  ConditionalExit(options)

# work here
  files.each do |f|
    puts program + ' ' + f if options[:verbose] != nil && options[:verbose] == true
    r = true
    r = system(program,f) if options[:dryrun] == nil || options[:dryrun] != true
    puts "Synchronization of #{f} did not proceed" if r == nil
    puts "Synchronization of #{f} was not successful" if r == false
  end

  NORMAL_EXIT
end