Sha256: 048db465a913a9c23cb5eef8b7fa08e5a3d15c21682e5327cd4689cc8aaa16fc

Contents?: true

Size: 839 Bytes

Versions: 3

Compression:

Stored size: 839 Bytes

Contents

# frozen_string_literal: true

require "core"
require "optparse"

module Milestoner
  module CLI
    # Assembles and parses all Command Line Interface (CLI) options.
    class Parser
      include Import[:configuration]

      CLIENT = OptionParser.new nil, 40, "  "
      SECTIONS = [Parsers::Core].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

3 entries across 3 versions & 1 rubygems

Version Path
milestoner-15.3.0 lib/milestoner/cli/parser.rb
milestoner-15.2.2 lib/milestoner/cli/parser.rb
milestoner-15.2.1 lib/milestoner/cli/parser.rb