Sha256: 9b41ac3bf8cb9492233968728206b44ccd764573f9ab713adf080d2535f5e58e

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module EacCli
  module Runner
    module InstanceMethods
      PARSER_ERROR_EXIT_CODE = 1

      def run_run
        parsed
        run_callbacks(:run) { run }
      rescue ::EacCli::Parser::Error => e
        run_parser_error(e)
      rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
        # Do nothing
      end

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

      def runner_context
        return @runner_context if @runner_context

        raise 'Context was required, but was not set yet'
      end

      def runner_context=(new_runner_context)
        @runner_context = new_runner_context
        @parsed = nil
      end

      def parsed
        @parsed ||= ::EacCli::Parser.new(self.class.runner_definition, runner_context.argv).parsed
      end

      def program_name
        runner_context.if_present(&:program_name) || $PROGRAM_NAME
      end

      def respond_to_missing?(method, include_all = false)
        runner_context.parent.if_present(false) { |v| v.respond_to?(method, include_all) } ||
          super
      end

      def method_missing(method, *args, &block)
        return super if runner_context.parent.blank? || !runner_context.parent.respond_to?(method)

        runner_context.parent.send(method, *args, &block)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eac_cli-0.27.0 lib/eac_cli/runner/instance_methods.rb