Class: Racker::CLI

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

Overview

The CLI is a class responsible for handling the command line interface logic.

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



13
14
15
# File 'lib/racker/cli.rb', line 13

def initialize(argv)
  @argv = argv
end

Instance Method Details

#execute!Object



17
18
19
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
# File 'lib/racker/cli.rb', line 17

def execute!
  # Get the global logger
  log = Log4r::Logger['racker']

  # Parse our arguments
  option_parser.parse!(@argv)

  # Set the logging level specified by the command line
  log.level = get_log4r_level(options[:log_level])
  log.info("Log level set to: #{options[:log_level]}")

  # Display the options if a minimum of 1 template and an output file is not provided
  if @argv.length < 2
    puts option_parser 
    Kernel.exit!(1)
  end

  # Set the output file to the last arg
  options[:output] = @argv.pop
  log.debug("Output file set to: #{options[:output]}")

  # Set the input files to the remaining args
  options[:templates] = @argv

  # Run through Racker
  log.debug('Executing the Racker Processor...')
  Processor.new(options).execute!
  log.debug('Processing complete.')

  # Thats all folks!
  puts "Processing complete!" unless options[:quiet]
  puts "Packer file generated: #{options[:output]}" unless options[:quiet]

  return 0
end