Class: EZML::Exec::Generic

Inherits:
Object show all
Defined in:
lib/ezml/exec.rb

Overview

An abstract class that encapsulates the executable code for all three executables.

Direct Known Subclasses

EZML

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Generic

Returns a new instance of Generic.

Parameters:

  • args (Array<String>)

    The command-line arguments



12
13
14
15
# File 'lib/ezml/exec.rb', line 12

def initialize(args)
  @args = args
  @options = {:for_engine => {}}
end

Instance Method Details

#parseObject

Parses the command-line arguments and runs the executable. This does not handle exceptions or exit the program.

See Also:



39
40
41
42
43
44
45
46
# File 'lib/ezml/exec.rb', line 39

def parse
  @opts = OptionParser.new(&method(:set_opts))
  @opts.parse!(@args)

  process_result

  @options
end

#parse!Object

Parses the command-line arguments and runs the executable. Calls ‘Kernel#exit` at the end, so it never returns.

See Also:



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ezml/exec.rb', line 21

def parse!
  begin
    parse
  rescue Exception => e
    raise e if @options[:trace] || e.is_a?(SystemExit)

    $stderr.print "#{e.class}: " unless e.class == RuntimeError
    $stderr.puts "#{e.message}"
    $stderr.puts "  Use --trace for backtrace."
    exit 1
  end
  exit 0
end

#to_sString

Returns A description of the executable.

Returns:

  • (String)

    A description of the executable



49
50
51
# File 'lib/ezml/exec.rb', line 49

def to_s
  @opts.to_s
end