Sha256: 05689a77d947a506c73f95e512afbea9df841792991d6f574262fc0f971ec656

Contents?: true

Size: 914 Bytes

Versions: 7

Compression:

Stored size: 914 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, **)
        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

7 entries across 7 versions & 1 rubygems

Version Path
gemsmith-19.8.0 lib/gemsmith/cli/parser.rb
gemsmith-19.7.0 lib/gemsmith/cli/parser.rb
gemsmith-19.6.0 lib/gemsmith/cli/parser.rb
gemsmith-19.5.2 lib/gemsmith/cli/parser.rb
gemsmith-19.5.1 lib/gemsmith/cli/parser.rb
gemsmith-19.5.0 lib/gemsmith/cli/parser.rb
gemsmith-19.4.0 lib/gemsmith/cli/parser.rb