class Matrix::Architect::Commands::Base

Overview

Base class for all commands.

The command reiceve an OptionParser an a Job on its .run method. It should use the parser to define any subcommands or options and the job to register the code that will actually execute after the whole parsing process.

Example:

class HelloWorldCommand < Base
  @flag : String? = nil

  def parse(parser, job)
    parser.on("subcommand", "a subcommand example") do
      parser.on("-f FLAG", "--flag=FLAG", "a flag example") do |flag|
        @flag = flag
      end
      job.exec { subcommand }
    end
  end

  def subcommand
    send_message "Hello world with a subcommand"

    if !@flag.nil?
      send_message "You sent the flag #{@flag}"
    end
  end
end

Direct Known Subclasses

Defined in:

commands/base.cr

Constructors

Class Method Summary

Constructor Detail

def self.new(room_id : String, conn : Connection) #

[View source]

Class Method Detail

def self.run(args, room_id : String, conn : Connection) : Nil #

Creates a new instance of the command and runs it.


[View source]