Sha256: 07ba6cb523c2c7923d35873b7e277c11dab9e72cbc5b1fb84c16824d74da95fe

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require "milestoner"

module Rubysmith
  module CLI
    # The main Command Line Interface (CLI) object.
    class Shell
      ACTIONS = {
        config: Actions::Config.new,
        build: Actions::Build.new,
        publish: Actions::Publish.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, Milestoner::Error => 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_publish: true then publish configuration
          in action_version: true then logger.info Identity::VERSION_LABEL
          else usage
        end
      end

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

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

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

      def usage = logger.unknown(parser.to_s)

      def logger = container[__method__]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubysmith-1.1.1 lib/rubysmith/cli/shell.rb
rubysmith-1.1.0 lib/rubysmith/cli/shell.rb
rubysmith-1.0.0 lib/rubysmith/cli/shell.rb