Class: Mirah::Commands::Base

Inherits:
Object
  • Object
show all
Includes:
Logging::Logged
Defined in:
lib/mirah/commands/base.rb

Direct Known Subclasses

Compile, Parse, Run

Constant Summary

Constants included from Logging::Logged

Logging::Logged::VLEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging::Logged

#error, #info, #log, #logger, #logger_name, #logging?, #vlog, #warning

Constructor Details

#initialize(args) ⇒ Base

Returns a new instance of Base.



24
25
26
27
28
29
# File 'lib/mirah/commands/base.rb', line 24

def initialize(args)
  @state = Mirah::Util::CompilationState.new
  @state.command = command_name
  @args = args
  @argument_processor = Mirah::Util::ArgumentProcessor.new(@state, @args)
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



31
32
33
# File 'lib/mirah/commands/base.rb', line 31

def args
  @args
end

#argument_processorObject

Returns the value of attribute argument_processor.



31
32
33
# File 'lib/mirah/commands/base.rb', line 31

def argument_processor
  @argument_processor
end

#stateObject

Returns the value of attribute state.



31
32
33
# File 'lib/mirah/commands/base.rb', line 31

def state
  @state
end

Instance Method Details

#execute_baseObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mirah/commands/base.rb', line 33

def execute_base
  argument_processor.process
  if argument_processor.exit?
    exit argument_processor.exit_status_code
  end
  # because MirahCommand is a JRuby Java class, SystemExit bubbles through and makes noise
  # so we use a catch/throw to early exit instead
  # see util/process_errors.rb
  status = catch(:exit) do
    begin
      yield
    rescue Mirah::InternalCompilerError => ice
      Mirah.print_error(ice.message, ice.position) if ice.node
      raise ice.cause || ice
    rescue Mirah::MirahError => ex
      Mirah.print_error(ex.message, ex.position)
      log "{0}\n{1}", [ex.message, ex.backtrace.join("\n")]
      throw :exit, 1
    end
    0
  end
  exit status if status > 0
  true
end