Sha256: 3653a2ece4f81d114fbfc268c5ecb4b59d22bf1a3a0599826590644e568ba0e7

Contents?: true

Size: 919 Bytes

Versions: 6

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

require "core"
require "optparse"

module Pennyworth
  module CLI
    # Assembles and parses all Command Line Interface (CLI) options.
    class Parser
      CLIENT = OptionParser.new nil, 40, "  "
      SECTIONS = [Parsers::Core, Parsers::GitHub, Parsers::RubyGems].freeze # Order is important.

      def initialize configuration = Container[:configuration],
                     sections: SECTIONS,
                     client: CLIENT
        @configuration_duplicate = configuration.dup
        @sections = sections
        @client = client
      end

      def call arguments = Core::EMPTY_ARRAY
        sections.each { |parser| parser.call configuration_duplicate, client: }
        client.parse arguments
        configuration_duplicate.freeze
      end

      def to_s = client.to_s

      private

      attr_reader :configuration_duplicate, :client, :sections
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pennyworth-14.3.0 lib/pennyworth/cli/parser.rb
pennyworth-14.2.1 lib/pennyworth/cli/parser.rb
pennyworth-14.2.0 lib/pennyworth/cli/parser.rb
pennyworth-14.1.2 lib/pennyworth/cli/parser.rb
pennyworth-14.1.1 lib/pennyworth/cli/parser.rb
pennyworth-14.1.0 lib/pennyworth/cli/parser.rb