Sha256: 560238b3eace906c78280be675ca4bd57b7a5668333fbece585fc5946aae13a3

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require "core"

module Gemsmith
  module CLI
    # The main Command Line Interface (CLI) object.
    class Shell
      include Actions::Import[
        :config,
        :build,
        :install,
        :publish,
        :edit,
        :view,
        :specification,
        :logger
      ]

      def initialize parser: Parser.new, **dependencies
        super(**dependencies)
        @parser = parser
      end

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

      private

      attr_reader :parser

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gemsmith-19.3.0 lib/gemsmith/cli/shell.rb
gemsmith-19.2.0 lib/gemsmith/cli/shell.rb