Class: JasperCommandLine::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/jasper-command-line/command_line.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CommandLine

Returns a new instance of CommandLine.



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
# File 'lib/jasper-command-line/command_line.rb', line 3

def initialize(*args)
  begin
    options = parse_arguments(args)

    if options[:jasper_file]
      jasper_file = options.delete :jasper_file
      data = options.delete :data
      params = options.delete :params

      if options[:signature]
        if options[:signature][:key_file] && !options[:signature][:password]
          raise ArgumentError.new("Password not supplied for certificate")
        end
      end

      puts JasperCommandLine::Jasper::render_pdf(jasper_file, data, params, options)
    end

    exit 0
  rescue OptionParser::InvalidOption => e
    puts "Error: #{e.message}"
    exit 1
  rescue => e
    puts "Error: #{e.message}"
    exit 2
  end
end