Class: LLM::Repl::Command
- Inherits:
-
Object
- Object
- LLM::Repl::Command
- Defined in:
- lib/llm/repl/command.rb
Overview
The LLM::Repl::Command class is the superclass
of all read-eval-print loop commands. A command has a name, and a
description. This basic version does not implement parameters. A
command is accessible via the / prefix: eg /exit.
Defined Under Namespace
Classes: Exit
Constant Summary collapse
- UNDEFINED =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Object.new
Class Method Summary collapse
-
.find_by(input: nil, name: nil) ⇒ LLM::Repl::Command?
Find a command by a name, or by an input string.
- .inherited(command)
-
.registry ⇒ Array<LLM::Repl::Command]
Array<LLM::Repl::Command].
-
.name(name = UNDEFINED) ⇒ String
Set or get a command name.
-
.description(description = UNDEFINED) ⇒ String
Set or get a command description.
Instance Method Summary collapse
-
#call ⇒ Object
This method should be implemented by subclasses.
Class Method Details
.find_by(input: nil, name: nil) ⇒ LLM::Repl::Command?
The input string must be prefixed with "/" or it won't be matched. The match is made against the string before the first space - so "/exit foo" will match the "exit" command but "/exitnow" will not.
Find a command by a name, or by an input string.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/llm/repl/command.rb', line 29 def self.find_by(input: nil, name: nil) if input return nil unless input[0] == "/" n, = input.split(" ") registry.find { n[1..] == _1.name } elsif name registry.find { name == _1.name } else raise ArgumentError, "provide one of: input, name" end end |
.inherited(command)
This method returns an undefined value.
45 46 47 48 49 |
# File 'lib/llm/repl/command.rb', line 45 def self.inherited(command) LLM.lock(:inherited) do registry << command end end |
.registry ⇒ Array<LLM::Repl::Command]
Returns Array<LLM::Repl::Command].
53 54 55 |
# File 'lib/llm/repl/command.rb', line 53 def self.registry @registry ||= [] end |
Instance Method Details
#call ⇒ Object
This method should be implemented by subclasses.
80 81 82 |
# File 'lib/llm/repl/command.rb', line 80 def call(...) raise NotImplementedError, "#{self.class}#call is not implemented" end |