Sha256: 67182778d1bdfa89ca03391ff750b8ebdaeb5370921cff07ba061323eafde879

Contents?: true

Size: 779 Bytes

Versions: 8

Compression:

Stored size: 779 Bytes

Contents

# frozen_string_literal: true

require "optparse"

module Rubysmith
  module CLI
    # Assembles and parses all Command Line Interface (CLI) options.
    class Parser
      CLIENT = OptionParser.new nil, 40, "  "
      SECTIONS = [Parsers::Core, Parsers::Build].freeze # Order is important.

      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

8 entries across 8 versions & 1 rubygems

Version Path
rubysmith-2.0.2 lib/rubysmith/cli/parser.rb
rubysmith-2.0.1 lib/rubysmith/cli/parser.rb
rubysmith-2.0.0 lib/rubysmith/cli/parser.rb
rubysmith-1.3.0 lib/rubysmith/cli/parser.rb
rubysmith-1.2.0 lib/rubysmith/cli/parser.rb
rubysmith-1.1.1 lib/rubysmith/cli/parser.rb
rubysmith-1.1.0 lib/rubysmith/cli/parser.rb
rubysmith-1.0.0 lib/rubysmith/cli/parser.rb