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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jasper-command-line/command_line.rb', line 3

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

    if !options
      puts "Usage:"
      puts ""
      puts "jasper-command-line [options]"
      puts ""
      puts "Options:"
      puts ""
      puts "--jasper /path/to/file     The .jasper file to load (if one doesn't exist, it is"
      puts "                           compiled from the .jrxml file with the same name and"
      puts "                           on the same location)"
      puts "--data-file /path/to/file  The .xml file to load the data from"
      puts "--copies number            The number of copies to generate"
      puts "--locale locale            The locale to use in the report (in the format xx-YY)"
      puts "--param key=value          Adds the parameter with name key with the value value"
      puts "                           (can be defined multiple times)"
      puts ""
      puts "Digital signature options:"
      puts "--sign-key-file /path/to/file  The location of the PKCS12 file to"
      puts "                               digitally sign the PDF with"
      puts "--sign-password password       The password for the PKCS12 file"
      puts "--sign-location location       The location of the signature"
      puts "--sign-reason reason           The reason for signing the PDF"
    else
      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
    end
  rescue ArgumentError => e
    puts "Error: #{e.message}"
  rescue => e
    puts "Error: #{e.message}"
    puts e.backtrace
  end
end