Sha256: 765ba077ec8abb2f7dfb26d555a1b92683e9e7c0ec3d2baf95dfb3e64166a83d

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

require "core"
require "refinements/structs"

<% namespace do %>
  module CLI
    module Parsers
      # Handles parsing of Command Line Interface (CLI) core options.
      class Core
        include Import[:specification]

        using Refinements::Structs

        def self.call(...) = new(...).call

        def initialize(configuration = Container[:configuration], client: Parser::CLIENT, **)
          super(**)
          @configuration = configuration
          @client = client
        end

        def call arguments = ::Core::EMPTY_ARRAY
          client.banner = specification.labeled_summary
          client.separator "\nUSAGE:\n"
          collate
          client.parse arguments
          configuration
        end

        private

        attr_reader :configuration, :client

        def collate = private_methods.sort.grep(/add_/).each { |method| __send__ method }

        def add_config
          client.on "-c",
                    "--config ACTION",
                    %i[edit view],
                    "Manage gem configuration: edit or view." do |action|
            configuration.merge! action_config: action
          end
        end

        def add_version
          client.on "-v", "--version", "Show gem version." do
            configuration.merge! action_version: true
          end
        end

        def add_help
          client.on "-h", "--help", "Show this message." do
            configuration.merge! action_help: true
          end
        end
      end
    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/parsers/core.rb.erb
gemsmith-19.7.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parsers/core.rb.erb
gemsmith-19.6.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parsers/core.rb.erb
gemsmith-19.5.2 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parsers/core.rb.erb
gemsmith-19.5.1 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parsers/core.rb.erb
gemsmith-19.5.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parsers/core.rb.erb
gemsmith-19.4.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parsers/core.rb.erb