module
Reply::Reader::Commands
Overview
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.
Defined in:
commands.crConstructors
Macro Summary
-
command_docs(help_doc = nil)
Returns the command documentations defined by
Help
annotation, asHash(String, {summary: String, details: String})
-
command_names
Returns the command names defined by do_method, as
Array(String)
Instance Method Summary
-
#auto_complete(name_filter : String, expression_before : String) : Tuple(String, Array(String))
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
. -
#auto_complete_arguments(command_name : String, name_filter : String, expression_before : String) : Tuple(String, Array(String))
Override this method to provide name completion for arguments to a command.
-
#do_help(command_name : String | Nil = nil)
Override this method to customize help message.
-
#parse_command(expression : String) : Tuple(String, Array(String))
Override this method to customize how command and arguments are parsed from expression.
-
#run_commands(expression)
Executes a do_method if expression starts with 'method'.
-
#run_commands_loop
Prompts and
#run_commands
in loop. -
#unknown_command(command_name : String, arguments : Array(String))
Override this method to customize message on unknown command.
Constructor Detail
Macro Detail
Returns the command documentations defined by Help
annotation, as Hash(String, {summary: String, details: String})
Instance Method Detail
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.