Module: BruteCLI::REPL::Commands

Defined in:
lib/brute_cli/repl/commands.rb

Overview

Registry of slash commands available in the REPL.

Each command maps to a method name on the REPL instance. Reline’s completion_proc uses names to offer autocomplete suggestions when the user types “/” at the start of a line.

Defined Under Namespace

Classes: Entry

Constant Summary collapse

REGISTRY =
[
  Entry.new(name: "/menu",     description: "Open main menu",          method_name: :cmd_menu),
  Entry.new(name: "/model",    description: "Change model",            method_name: :cmd_model),
  Entry.new(name: "/provider", description: "Change provider",         method_name: :cmd_provider),
  Entry.new(name: "/help",     description: "Show available commands", method_name: :cmd_help),
  Entry.new(name: "/compact",  description: "Compact conversation",    method_name: :cmd_compact),
  Entry.new(name: "/exit",     description: "Exit brute",             method_name: :cmd_exit),
].freeze

Class Method Summary collapse

Class Method Details

.find(input) ⇒ Object

Find the matching Entry for the given input, or nil.



37
38
39
40
# File 'lib/brute_cli/repl/commands.rb', line 37

def self.find(input)
  cmd = input.strip.split(/\s+/, 2).first
  REGISTRY.detect { |e| e.name == cmd }
end

.match?(input) ⇒ Boolean

Does this input look like a slash command?

Returns:

  • (Boolean)


32
33
34
# File 'lib/brute_cli/repl/commands.rb', line 32

def self.match?(input)
  input.strip.start_with?("/")
end

.namesObject

All command names, for Reline completion.



27
28
29
# File 'lib/brute_cli/repl/commands.rb', line 27

def self.names
  REGISTRY.map(&:name)
end