Sha256: 5ed76d8e2e9e306f656217e60f35d1d15133a06af1fdc9dc4b20fb1f50055641

Contents?: true

Size: 870 Bytes

Versions: 3

Compression:

Stored size: 870 Bytes

Contents

# frozen_string_literal: true

require "core"
require "optparse"

module Pragmater
  module CLI
    # Assembles and parses all Command Line Interface (CLI) options.
    class Parser
      include Import[:configuration]

      CLIENT = OptionParser.new nil, 40, "  "
      SECTIONS = [Parsers::Core, Parsers::Flag].freeze # Order matters.

      def initialize(sections: SECTIONS, client: CLIENT, **)
        super(**)
        @sections = sections
        @client = client
        @configuration_duplicate = configuration.dup
      end

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

      def to_s = client.to_s

      private

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pragmater-12.2.0 lib/pragmater/cli/parser.rb
pragmater-12.1.2 lib/pragmater/cli/parser.rb
pragmater-12.1.1 lib/pragmater/cli/parser.rb