Sha256: ca7798288f301e6300ded1c2fedf37b34661aec57d3f84eb9767dc50809bf020

Contents?: true

Size: 1.85 KB

Versions: 15

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

module Karafka
  # Karafka framework Cli
  # If you want to add/modify command that belongs to CLI, please review all commands
  # available in cli/ directory inside Karafka source code.
  #
  # @note Whole Cli is built using Thor
  # @see https://github.com/erikhuda/thor
  class Cli < Thor
    package_name 'Karafka'

    default_task :missingno

    class << self
      # Loads all Cli commands into Thor framework
      # This method should be executed before we run Karafka::Cli.start, otherwise we won't
      # have any Cli commands available
      def prepare
        cli_commands.each do |action|
          action.bind_to(self)
        end
      end

      # When there is a CLI crash, exit
      # @return [true]
      def exit_on_failure?
        true
      end

      private

      # @return [Array<Class>] Array with Cli action classes that can be used as commands
      def cli_commands
        constants
          .map! { |object| const_get(object) }
          .keep_if do |object|
            object.instance_of?(Class) && (object < Cli::Base)
          end
      end
    end
  end
end

# This is kinda trick - since we don't have a autoload and other magic stuff
# like Rails does, so instead this method allows us to replace currently running
# console with a new one via Kernel.exec. It will start console with new code loaded
# Yes, we know that it is not turbo fast, however it is turbo convenient and small
#
# Also - the KARAFKA_CONSOLE is used to detect that we're executing the irb session
# so this method is only available when the Karafka console is running
#
# We skip this because this should exist and be only valid in the console
# :nocov:
if ENV['KARAFKA_CONSOLE']
  # Reloads Karafka irb console session
  def reload!
    Karafka.logger.info "Reloading...\n"
    Kernel.exec Karafka::Cli::Console.command
  end
end
# :nocov:

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
karafka-1.4.15 lib/karafka/cli.rb
karafka-1.4.14 lib/karafka/cli.rb
karafka-1.4.13 lib/karafka/cli.rb
karafka-1.4.12 lib/karafka/cli.rb
karafka-1.4.11 lib/karafka/cli.rb
karafka-1.4.10 lib/karafka/cli.rb
karafka-1.4.9 lib/karafka/cli.rb
karafka-1.4.8 lib/karafka/cli.rb
karafka-1.4.7 lib/karafka/cli.rb
karafka-1.4.6 lib/karafka/cli.rb
karafka-1.4.5 lib/karafka/cli.rb
karafka-1.4.4 lib/karafka/cli.rb
karafka-1.4.3 lib/karafka/cli.rb
karafka-1.4.2 lib/karafka/cli.rb
karafka-1.4.1 lib/karafka/cli.rb