Sha256: ca53f9bba9f3b813c7a2a081263ad27c8ce069a10d6ec1cbba5780c9260d4dde

Contents?: true

Size: 980 Bytes

Versions: 6

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

require 'eac_cli/parser/error'
require 'eac_ruby_utils/core_ext'

module EacCli
  class Parser
    class ParseResult
      common_constructor :definition, :argv

      def result
        result_or_error = parse(definition)
        return result_or_error unless result_or_error.is_a?(::Exception)

        definition.alternatives.each do |alternative|
          alt_result_or_error = parse(alternative)
          return alt_result_or_error unless alt_result_or_error.is_a?(::Exception)
        end

        raise result_or_error
      end

      private

      def parse(definition)
        ::EacCli::Parser::Collector.to_data(definition) do |collector|
          ::EacCli::Parser::PositionalCollection.new(
            definition,
            ::EacCli::Parser::OptionsCollection.new(definition, argv, collector).arguments,
            collector
          )
        end
      rescue ::EacCli::Parser::Error => e
        e
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
ehbrs-tools-0.16.1 vendor/eac_cli/lib/eac_cli/parser/parse_result.rb
eac_cli-0.11.1 lib/eac_cli/parser/parse_result.rb
avm-tools-0.76.1 vendor/eac_cli/lib/eac_cli/parser/parse_result.rb
eac_cli-0.11.0 lib/eac_cli/parser/parse_result.rb
eac_cli-0.10.0 lib/eac_cli/parser/parse_result.rb
ehbrs-tools-0.16.0 vendor/eac_cli/lib/eac_cli/parser/parse_result.rb