Reply::Reader::Commands
Include this module to add the capability to parse and execute commands.
The methods starting with do_ will be treating as commands.
run_commands(expression) will parse expression and execute command if the command match, elsewhere it shows an help message.
ex:
class MyReader < Reply::Reader
include Commands
def do_method(arg1, arg2 = nil)
puts "executing command 'method' with arguments: #{arg1} #{arg2}"
end
end
reader = MyReader.new
reader.read_loop do |expression|
reader.run_commands(expression)
end
See /examples/command_relp.cr for more details.
Constructors
Instance methods
Commands#auto_complete (this method) matches the first command to the
commands defined by the do_methods, and hands off any subsequent
completion requests to #auto_complete_arguments.
Override this method to provide name completion for arguments to a command.
Override this method to customize how command and arguments are parsed from expression.
ameba:disable Metrics/CyclomaticComplexity
Executes a do_method if expression starts with 'method'.
Passes the rest of the expression as arguments to the do_method, separated by spaces
ex:
run_command("method 1 2 3") will run do_method("1", "2", "3")
Shows a help message if arguments mismatch.
Returns the result of executed do_method, if any.
Override this method to customize message on unknown command.
Macros
Returns the command documentations defined by Help annotation, as Hash(String, {summary: String, details: String})