Method: Vmreverter::CLI#initialize

Defined in:
lib/vmreverter/cli.rb

#initializeCLI

Returns a new instance of CLI.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vmreverter/cli.rb', line 3

def initialize
  @options = Vmreverter::Options.parse_args
  @logger = Vmreverter::Logger.new(@options)


  if @options[:lockfile]
    if Pathname.new(@options[:lockfile]).exist?
      report_and_raise(@logger, ArgumentError.new("Specified lockfile path '#{@options[:lockfile]}' is locked."), "Lockfile is locked")
    else
      FileUtils.touch(@options[:lockfile])
    end
  end

  if not @options[:config]
    report_and_raise(@logger, ArgumentError.new("Missing config, specify one (-c or --config)!"), "CLI: initialize")
  end

  @logger.debug("Options")
  @options.each do |opt, val|
    if val and val != []
      @logger.debug("\t#{opt.to_s}:")
      if val.kind_of?(Array)
        val.each do |v|
          @logger.debug("\t\t#{v.to_s}")
        end
      else
        @logger.debug("\t\t#{val.to_s}")
      end
    end
  end

  Vmreverter::Configuration.build(@options, @logger)
  @config = Vmreverter::Configuration.instance

end