Sha256: 41e2404cc46f23ed996707d89ddaed0ccb6988c64aad5458bf1c5a95f509840b

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require "hanami/cli"
require "snowpack/cli/application/command"
require "snowpack/console/context"

module Snowpack
  module CLI
    module Application
      module Commands
        class Console < Command
          REPL = begin
            require 'pry'
            Pry
          rescue LoadError
            require 'irb'
            IRB
          end

          desc "Open interactive console"

          def call(**)
            measure "#{prompt_prefix} booted in" do
              out.puts "=> starting #{prompt_prefix} console"
              application.boot!
            end

            start_repl
          end

          private

          def start_repl
            context = Snowpack::Console::Context.new(application)
            REPL.start(context, prompt: [proc { default_prompt }, proc { indented_prompt }])
          end

          def default_prompt
            "#{prompt_prefix}> "
          end

          def indented_prompt
            "#{prompt_prefix}* "
          end

          def prompt_prefix
            "#{inflector.underscore(application.config.name)}[#{application.env}]"
          end
        end

        register "console", Console
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
snowpack-1.0.0.alpha7 lib/snowpack/cli/application/commands/console.rb
snowpack-1.0.0.alpha6 lib/snowpack/cli/application/commands/console.rb
snowpack-1.0.0.alpha5 lib/snowpack/cli/application/commands/console.rb
snowpack-1.0.0.alpha4 lib/snowpack/cli/application/commands/console.rb
snowpack-1.0.0.alpha3 lib/snowpack/cli/application/commands/console.rb
snowpack-1.0.0.alpha2 lib/snowpack/cli/application/commands/console.rb