Sha256: 601940600ea23fde7a7e36287f86a9e574ed1ddfc11b2a1db503bc6060b4f487

Contents?: true

Size: 938 Bytes

Versions: 2

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

require "core"
require "optparse"

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

      CLIENT = OptionParser.new nil, 40, "  "

      # Order is important.
      SECTIONS = [Parsers::Core, Rubysmith::CLI::Parsers::Build, Parsers::Build].freeze

      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
gemsmith-19.3.0 lib/gemsmith/cli/parser.rb
gemsmith-19.2.0 lib/gemsmith/cli/parser.rb