module

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

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.

Source
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.

Source
do_help(command_name : String | Nil = nil)

Override this method to customize help message.

Source
parse_command(expression : String) : Tuple(String, Array(String))

Override this method to customize how command and arguments are parsed from expression.

ameba:disable Metrics/CyclomaticComplexity

Source
run_commands(expression)

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.

Source
run_commands_loop

Prompts and run_commands in loop.

Source
unknown_command(command_name : String, arguments : Array(String))

Override this method to customize message on unknown command.

Source

Macros

command_docs(help_doc = nil)

Returns the command documentations defined by Help annotation, as Hash(String, {summary: String, details: String})

Source
command_names

Returns the command names defined by do_method, as Array(String)

Source