Sha256: bccb3441d4c80755dfb6f76a8c4c28e3433f916f1c5aa933c70839f174465b0d

Contents?: true

Size: 817 Bytes

Versions: 5

Compression:

Stored size: 817 Bytes

Contents

# frozen_string_literal: true

require "optparse"

module Gemsmith
  module CLI
    # Assembles and parses all Command Line Interface (CLI) options.
    class Parser
      CLIENT = OptionParser.new nil, 40, "  "

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

      def initialize sections: SECTIONS, client: CLIENT, container: Container
        @sections = sections
        @client = client
        @configuration = container[:configuration].dup
      end

      def call arguments = []
        sections.each { |section| section.call configuration, client: }
        client.parse arguments
        configuration.freeze
      end

      def to_s = client.to_s

      private

      attr_reader :sections, :client, :configuration
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gemsmith-17.0.1 lib/gemsmith/cli/parser.rb
gemsmith-17.0.0 lib/gemsmith/cli/parser.rb
gemsmith-16.2.0 lib/gemsmith/cli/parser.rb
gemsmith-16.1.0 lib/gemsmith/cli/parser.rb
gemsmith-16.0.0 lib/gemsmith/cli/parser.rb