Sha256: f7b881779e0547df3c8738fd98d891f98e84a9ef8ff5d3a5997cce7594856543

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require "core"

module SublimeTextKit
  module CLI
    # The main Command Line Interface (CLI) object.
    class Shell
      include Actions::Import[
        :specification,
        :logger,
        :config,
        :metadata,
        :session,
        :snippets,
        :update
      ]

      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 => 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_metadata: Symbol => kind then metadata.call kind
          in action_session: true then session.call
          in action_snippets: true then snippets.call configuration.snippets_format
          in action_update: true then update.call
          in action_version: true then logger.info { specification.labeled_version }
          else usage
        end
      end

      def usage = logger.any { parser.to_s }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sublime_text_kit-14.1.0 lib/sublime_text_kit/cli/shell.rb