Sha256: 24c3962c365a52fde775c090619bf8cb51c46e7a396855c710c032a354151c29

Contents?: true

Size: 838 Bytes

Versions: 15

Compression:

Stored size: 838 Bytes

Contents

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

15 entries across 15 versions & 1 rubygems

Version Path
gemsmith-19.1.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-19.0.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.9.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.8.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.7.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.6.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.5.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.4.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.3.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.2.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.1.1 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.1.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.0.2 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.0.1 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-18.0.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb