class Karafka::Cli::Base
Base
class for all the command that we want to define This base class provides a nicer interface to Thor and allows to easier separate single independent commands In order to define a new command you need to:
- specify its desc - implement call method
@example Create a dummy command
class Dummy < Base self.desc = 'Dummy command' def call puts 'I'm doing nothing! end end
Attributes
We can use it to call other cli methods via this object
Public Class Methods
This method will bind a given Cli
command into Karafka
Cli
This method is a wrapper to way Thor defines its commands @param cli_class [Karafka::Cli] Karafka
cli_class
# File lib/karafka/cli/base.rb, line 54 def bind_to(cli_class) cli_class.desc name, *@desc (@options || []).each { |option| cli_class.option(*option) } context = self cli_class.send :define_method, name do |*args| context.new(self).call(*args) end end
Allows to set description of a given cli command @param args [Array] All the arguments that Thor desc method accepts
# File lib/karafka/cli/base.rb, line 47 def desc(*args) @desc ||= args end
Allows to set options for Thor cli @see github.com/erikhuda/thor @param option Single option details
# File lib/karafka/cli/base.rb, line 40 def option(*option) @options ||= [] @options << option end
Private Class Methods
@return [String] downcased current class name that we use to define name for
given Cli command
@example for Karafka::Cli::Install
name #=> 'install'
# File lib/karafka/cli/base.rb, line 72 def name to_s.split('::').last.downcase end
Public Instance Methods
This method should implement proper cli action
# File lib/karafka/cli/base.rb, line 32 def call raise NotImplementedError, 'Implement this in a subclass' end