Sha256: e9e0f63f14e97bd28deb0c1fc6eac2f3b7316bf0e60cfc88541f4cbc3606892b

Contents?: true

Size: 868 Bytes

Versions: 2

Compression:

Stored size: 868 Bytes

Contents

require "core"
require "optparse"

<% namespace do %>
  module CLI
    # Assembles and parses all Command Line Interface (CLI) options.
    class Parser
      include Import[:configuration]

      CLIENT = OptionParser.new nil, 40, "  "

      # Order is important.
      SECTIONS = [Parsers::Core].freeze

      def initialize sections: SECTIONS, client: CLIENT, **dependencies
        super(**dependencies)

        @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

2 entries across 2 versions & 1 rubygems

Version Path
gemsmith-19.3.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-19.2.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb