Sha256: d5622523d07764e4187956b2a4472f124da8b4caefdf98739f11b8fabf139a52

Contents?: true

Size: 1.06 KB

Versions: 69

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require 'eac_cli/speaker'
require 'eac_ruby_utils/core_ext'
require 'eac_ruby_utils/speaker'

module EacCli
  module Runner
    class ClassRunner
      PARSER_ERROR_EXIT_CODE = 1

      common_constructor :klass, :context_args

      def create
        r = klass.new
        r.runner_context = ::EacCli::Runner::Context.new(r, *context_args)
        r
      end

      def run
        on_asserted_speaker do
          r = create
          begin
            r.run_run
          rescue ::EacCli::Parser::Error => e
            run_parser_error(r, e)
          end
          r
        end
      end

      def run_parser_error(runner_instance, error)
        $stderr.write("#{runner_instance.program_name}: #{error}\n")
        ::Kernel.exit(PARSER_ERROR_EXIT_CODE)
      end

      private

      def on_asserted_speaker
        if ::EacRubyUtils::Speaker.context.optional_current
          yield
        else
          ::EacRubyUtils::Speaker.context.on(::EacCli::Speaker.new) do
            yield
          end
        end
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 3 rubygems

Version Path
eac_tools-0.45.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.44.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.43.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_cli-0.29.0 lib/eac_cli/runner/class_runner.rb
eac_tools-0.42.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.41.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.40.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.39.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.38.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.37.2 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.37.1 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.37.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.36.1 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.36.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.35.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.34.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.33.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.32.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.31.1 sub/eac_cli/lib/eac_cli/runner/class_runner.rb
eac_tools-0.31.0 sub/eac_cli/lib/eac_cli/runner/class_runner.rb