Sha256: 4cc5ee2611b5588bf12259ac536c7569d3276936d9325a5feffb52d053ae9ffe

Contents?: true

Size: 899 Bytes

Versions: 2

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

require "core"
require "optparse"

module Rubysmith
  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::Build].freeze # Order is important.

      def initialize sections: SECTIONS, client: CLIENT, **dependencies
        super(**dependencies)
        @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

2 entries across 2 versions & 1 rubygems

Version Path
rubysmith-4.4.0 lib/rubysmith/cli/parser.rb
rubysmith-4.3.0 lib/rubysmith/cli/parser.rb