Sha256: 0de8d0ceef7f9b26b7eb18a90b0d27179f292bfce630d509fa185967ca9408bc

Contents?: true

Size: 844 Bytes

Versions: 7

Compression:

Stored size: 844 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, **)
        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

7 entries across 7 versions & 1 rubygems

Version Path
gemsmith-19.8.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-19.7.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-19.6.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-19.5.2 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-19.5.1 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-19.5.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-19.4.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb