Sha256: 7668c965bb4db9b75a805a590490a64de61991dcf7a9cf8b827ef7230a449b3f

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require "rubysmith/identity"

module Rubysmith
  module CLI
    module Parsers
      # Handles parsing of Command Line Interface (CLI) core options.
      class Core
        def self.call client:, options:
          new(client: client, options: options).call
        end

        def initialize client: CLIENT, options: {}
          @client = client
          @options = options
        end

        def call arguments = []
          client.banner = "#{Identity::LABEL} - #{Identity::SUMMARY}"
          client.separator "\nUSAGE:\n"
          private_methods.grep(/add_/).each(&method(:__send__))
          arguments.empty? ? arguments : client.parse!(arguments)
        end

        private

        attr_reader :client, :options

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

        def add_build
          client.on "-b", "--build NAME [options]", "Build new project." do |value|
            options[:build] = value
          end
        end

        def add_version
          client.on "-v", "--version", "Show gem version." do
            options[:version] = Identity::VERSION_LABEL
          end
        end

        def add_help
          client.on "-h", "--help", "Show this message." do
            options[:help] = true
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubysmith-0.4.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-0.3.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-0.2.0 lib/rubysmith/cli/parsers/core.rb