Sha256: cd7533b476373ec326be011166d72530d27176daf2d1164311637fb5ec03c261

Contents?: true

Size: 889 Bytes

Versions: 11

Compression:

Stored size: 889 Bytes

Contents

# frozen_string_literal: true

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 = []
        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

11 entries across 11 versions & 1 rubygems

Version Path
pennyworth-14.0.0 lib/pennyworth/cli/parser.rb
pennyworth-13.8.0 lib/pennyworth/cli/parser.rb
pennyworth-13.7.0 lib/pennyworth/cli/parser.rb
pennyworth-13.6.0 lib/pennyworth/cli/parser.rb
pennyworth-13.5.0 lib/pennyworth/cli/parser.rb
pennyworth-13.4.0 lib/pennyworth/cli/parser.rb
pennyworth-13.3.0 lib/pennyworth/cli/parser.rb
pennyworth-13.2.0 lib/pennyworth/cli/parser.rb
pennyworth-13.1.0 lib/pennyworth/cli/parser.rb
pennyworth-13.0.1 lib/pennyworth/cli/parser.rb
pennyworth-13.0.0 lib/pennyworth/cli/parser.rb