Sha256: cd8cbd7389a65a564b168b035ea434dc55b3d836c4c5a8b166792bc807e6c101

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require "core"

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

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

      def call arguments = Core::EMPTY_ARRAY
        act_on parser.call(arguments)
      rescue OptionParser::ParseError, Error => 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_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 kernel.puts specification.labeled_version
          else usage
        end
      end

      def usage = kernel.puts parser.to_s
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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