Sha256: 47785a882510a4bd22f91ee17fa03596298df6e6afa7114072dc939397c20925

Contents?: true

Size: 747 Bytes

Versions: 5

Compression:

Stored size: 747 Bytes

Contents

require "optparse"

<% namespace do %>
  module CLI
    # Assembles and parses all Command Line Interface (CLI) options.
    class Parser
      CLIENT = OptionParser.new nil, 40, "  "

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

      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

5 entries across 5 versions & 1 rubygems

Version Path
gemsmith-17.0.1 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-17.0.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-16.2.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-16.1.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb
gemsmith-16.0.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb