Sha256: 0c2abb603b160cd11e2cc27b5c827886a0160e762a4aec1f1022decd38385737

Contents?: true

Size: 863 Bytes

Versions: 8

Compression:

Stored size: 863 Bytes

Contents

# frozen_string_literal: true

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, **dependencies
        super(**dependencies)
        @sections = sections
        @client = client
        @configuration_duplicate = configuration.dup
      end

      def call arguments = []
        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

8 entries across 8 versions & 1 rubygems

Version Path
pragmater-12.0.0 lib/pragmater/cli/parser.rb
pragmater-11.5.0 lib/pragmater/cli/parser.rb
pragmater-11.4.0 lib/pragmater/cli/parser.rb
pragmater-11.3.0 lib/pragmater/cli/parser.rb
pragmater-11.2.0 lib/pragmater/cli/parser.rb
pragmater-11.1.0 lib/pragmater/cli/parser.rb
pragmater-11.0.1 lib/pragmater/cli/parser.rb
pragmater-11.0.0 lib/pragmater/cli/parser.rb