class Karafka::Cli::Base
end
end
puts ‘I’m doing nothing!
def call
self.desc = ‘Dummy command’
class Dummy < Base
@example Create a dummy command
- implement call method
- specify its desc
In order to define a new command you need to:
independent commands
This base class provides a nicer interface to Thor and allows to easier separate single
Base class for all the command that we want to define
def bind_to(cli_class)
-
cli_class
(Karafka::Cli
) -- Karafka cli_class
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
def call
def call raise NotImplementedError, 'Implement this in a subclass' end
def desc(desc)
-
desc
(String
) -- Description of a given cli command
def desc(desc) @desc ||= desc end
def initialize(cli)
-
cli
(Karafka::Cli
) -- current Karafka Cli instance
def initialize(cli) @cli = cli end
def name
- Example: for Karafka::Cli::Install -
Returns:
-
(String)
- downcased current class name that we use to define name for
def name to_s.split('::').last.downcase end
def option(*option)
-
option
() -- Single option details
Other tags:
- See: https://github.com/erikhuda/thor -
def option(*option) @options ||= [] @options << option end