Sha256: 92271e91d41efae61d1513bff62e5b797c562e804423bf26cfd806fa0df0cd83

Contents?: true

Size: 869 Bytes

Versions: 14

Compression:

Stored size: 869 Bytes

Contents

# frozen_string_literal: true

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 = []
        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

14 entries across 14 versions & 1 rubygems

Version Path
rubysmith-4.2.0 lib/rubysmith/cli/parser.rb
rubysmith-4.1.0 lib/rubysmith/cli/parser.rb
rubysmith-4.0.1 lib/rubysmith/cli/parser.rb
rubysmith-4.0.0 lib/rubysmith/cli/parser.rb
rubysmith-3.8.0 lib/rubysmith/cli/parser.rb
rubysmith-3.7.0 lib/rubysmith/cli/parser.rb
rubysmith-3.6.0 lib/rubysmith/cli/parser.rb
rubysmith-3.5.0 lib/rubysmith/cli/parser.rb
rubysmith-3.4.0 lib/rubysmith/cli/parser.rb
rubysmith-3.3.0 lib/rubysmith/cli/parser.rb
rubysmith-3.2.0 lib/rubysmith/cli/parser.rb
rubysmith-3.1.0 lib/rubysmith/cli/parser.rb
rubysmith-3.0.1 lib/rubysmith/cli/parser.rb
rubysmith-3.0.0 lib/rubysmith/cli/parser.rb