Sha256: 1c2ca3e934b18ed654fd667299f9eb71c0210bf64f7b0a9b3f76be0c48274917

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

module Gemsmith
  module CLI
    # The main Command Line Interface (CLI) object.
    class Shell
      ACTIONS = {
        config: Actions::Config.new,
        build: Actions::Build.new,
        install: Actions::Install.new,
        publish: Actions::Publish.new,
        edit: Actions::Edit.new,
        view: Actions::View.new
      }.freeze

      def initialize parser: Parser.new, actions: ACTIONS, container: Container
        @parser = parser
        @actions = actions
        @container = container
      end

      def call arguments = []
        perform parser.call(arguments)
      rescue OptionParser::ParseError => error
        logger.error { error.message }
      end

      private

      attr_reader :parser, :actions, :container

      def perform configuration
        case configuration
          in action_config: Symbol => action then config action
          in action_build: true then build configuration
          in action_install: true then install configuration
          in action_publish: true then publish configuration
          in action_edit: String => gem_name then edit gem_name
          in action_view: String => gem_name then view gem_name
          in action_version: true then logger.info { specification.labeled_version }
          else usage
        end
      end

      def config(action) = actions.fetch(__method__).call(action)

      def build(configuration) = actions.fetch(__method__).call(configuration)

      def install(configuration) = actions.fetch(__method__).call(configuration)

      def publish(configuration) = actions.fetch(__method__).call(configuration)

      def edit(gem_name) = actions.fetch(__method__).call(gem_name)

      def view(gem_name) = actions.fetch(__method__).call(gem_name)

      def usage = logger.unknown { parser.to_s }

      def logger = container[__method__]

      def specification = container[__method__]

      def process = container[__method__]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gemsmith-17.0.1 lib/gemsmith/cli/shell.rb
gemsmith-17.0.0 lib/gemsmith/cli/shell.rb
gemsmith-16.2.0 lib/gemsmith/cli/shell.rb
gemsmith-16.1.0 lib/gemsmith/cli/shell.rb