Sha256: ee363aa9df467fbd0221e941d9201d784e61f19152746040df432e0d93d72c4a

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 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, **)
        super(**)
        @parser = parser
      end

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

      private

      attr_reader :parser

      def act_on 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

5 entries across 5 versions & 1 rubygems

Version Path
gemsmith-19.6.0 lib/gemsmith/cli/shell.rb
gemsmith-19.5.2 lib/gemsmith/cli/shell.rb
gemsmith-19.5.1 lib/gemsmith/cli/shell.rb
gemsmith-19.5.0 lib/gemsmith/cli/shell.rb
gemsmith-19.4.0 lib/gemsmith/cli/shell.rb