Class: Racker::CLI

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

Overview

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

Constant Summary collapse

STDOUT_TOKEN =
'-'

Instance Method Summary collapse

Methods included from LogSupport

level=, log4r_level_for, logger, #logger

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



16
17
18
# File 'lib/racker/cli.rb', line 16

def initialize(argv)
  @argv = argv
end

Instance Method Details

#execute!Object



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

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

  # Set the logging level specified by the command line
  Racker::LogSupport.level = 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. A single dash can be supplied to
  # indicate that the compiled template should be written to STDOUT. Output
  # to STDOUT assumes the quiet option.
  options[:output] = output = @argv.pop
  logger.debug("Output file set to: #{output}")

  # Output to STDOUT assumes quiet mode
  @options[:quiet] = true if output == STDOUT_TOKEN

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

  # Run through Racker
  logger.debug('Executing the Racker Processor...')
  template = Processor.new(options).execute!

  write(output, template)

  # Thats all folks!
  logger.debug('Processing complete.')
  puts "Processing complete!" unless options[:quiet]
  puts "Packer file generated: #{options[:output]}" unless options[:quiet]

  return 0
end