Sha256: 48db47b319d672438739afd31d327f7f36c4fa4fe874828d7c471bbe4882b917

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require "hanami/console/context"

require_relative "../application"

module Hanami
  module CLI
    module Commands
      module Monolith
        # @api public
        class Console < Application
          REPLS = {
            "pry" => -> (*args) {
              begin
                require "hanami/cli/repl/pry"
                Repl::Pry.new(*args)
              rescue LoadError; end # rubocop:disable Lint/SuppressedException
            },
            "irb" => -> (*args) {
              require "hanami/cli/repl/irb"
              Repl::Irb.new(*args)
            },
          }.freeze

          desc "Application REPL"

          option :repl, required: false, desc: "REPL gem that should be used ('pry' or 'irb')"

          # @api private
          def call(repl: nil, **opts)
            engine = resolve_engine(repl, opts)
            engine.start
          end

          private

          def resolve_engine(repl, opts)
            if repl
              REPLS.fetch(repl).(application, opts)
            else
              REPLS.map { |(_, loader)| loader.(application, opts) }.compact.first
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hanami-cli-2.0.0.alpha8.1 lib/hanami/cli/commands/monolith/console.rb
hanami-cli-2.0.0.alpha8 lib/hanami/cli/commands/monolith/console.rb
hanami-cli-2.0.0.alpha7 lib/hanami/cli/commands/monolith/console.rb
hanami-cli-2.0.0.alpha6.1 lib/hanami/cli/commands/monolith/console.rb
hanami-cli-2.0.0.alpha6 lib/hanami/cli/commands/monolith/console.rb
hanami-cli-2.0.0.alpha4 lib/hanami/cli/commands/monolith/console.rb