Sha256: 919de740650932fe7aa2dc3dc2e929d4f09194d9e665554e7f41641ececd1da9

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require "hanami/console/context"

require_relative "../app/command"

module Hanami
  module CLI
    module Commands
      module App
        # @since 2.0.0
        # @api private
        class Console < App::Command
          # @since 2.0.0
          # @api private
          ENGINES = {
            "pry" => -> (*args) {
              begin
                Repl::Pry.new(*args)
              rescue LoadError # rubocop:disable Lint/SuppressedException
              end
            },
            "irb" => -> (*args) {
              Repl::Irb.new(*args)
            },
          }.freeze
          private_constant :ENGINES

          # @since 2.0.0
          # @api private
          DEFAULT_ENGINE = "irb"
          private_constant :DEFAULT_ENGINE

          desc "Start app console (REPL)"

          option :engine, required: false, desc: "Console engine", values: ENGINES.keys

          # @since 2.0.0
          # @api private
          def call(engine: nil, **opts)
            console_engine = resolve_engine(engine, opts)

            if console_engine.nil?
              err.puts "`#{engine}' is not bundled. Please run `bundle add #{engine}' and retry."
              exit(1)
            end

            console_engine.start
          end

          private

          def resolve_engine(engine, opts)
            ENGINES.fetch(engine, ENGINES[DEFAULT_ENGINE]).call(app, opts)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-cli-2.2.1 lib/hanami/cli/commands/app/console.rb
hanami-cli-2.2.0 lib/hanami/cli/commands/app/console.rb
hanami-cli-2.2.0.rc1 lib/hanami/cli/commands/app/console.rb