Sha256: 1a9161e1ec70e24293437d4a62b905eef7bbcc1373bee6da4129843679623f75

Contents?: true

Size: 778 Bytes

Versions: 6

Compression:

Stored size: 778 Bytes

Contents

# frozen_string_literal: true

require "optparse"

module Pragmater
  module CLI
    # Assembles and parses all Command Line Interface (CLI) options.
    class Parser
      CLIENT = OptionParser.new nil, 40, "  "
      SECTIONS = [Parsers::Core, Parsers::Flag].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

6 entries across 6 versions & 1 rubygems

Version Path
pragmater-10.3.1 lib/pragmater/cli/parser.rb
pragmater-10.3.0 lib/pragmater/cli/parser.rb
pragmater-10.2.0 lib/pragmater/cli/parser.rb
pragmater-10.1.0 lib/pragmater/cli/parser.rb
pragmater-10.0.1 lib/pragmater/cli/parser.rb
pragmater-10.0.0 lib/pragmater/cli/parser.rb