Class: LLM::Shell::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/shell/commands/utils.rb,
lib/llm/shell/command/extension.rb,
lib/llm/shell/commands/dir_import.rb,
lib/llm/shell/commands/file_import.rb,
lib/llm/shell/commands/clear_screen.rb,
lib/llm/shell/commands/show_history.rb,
lib/llm/shell/commands/system_prompt.rb,
lib/llm/shell/command.rb

Defined Under Namespace

Modules: Extension, Utils Classes: ClearScreen, Context, DirImport, FileImport, ShowHistory, SystemPrompt

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectClass, #call (readonly)

Returns the underlying command object

Returns:



11
12
13
# File 'lib/llm/shell/command.rb', line 11

def object
  @object
end

Instance Method Details

#name(name = nil) ⇒ String

Set or get the command name

Parameters:

  • name (String, nil) (defaults to: nil)

    The name of the command

Returns:

  • (String)


18
19
20
21
22
23
24
# File 'lib/llm/shell/command.rb', line 18

def name(name = nil)
  if name
    @name = name
  else
    @name
  end
end

#description(desc = nil) ⇒ String

Set or get the command description

Parameters:

  • desc (String, nil) (defaults to: nil)

    The description of the command

Returns:

  • (String)


31
32
33
34
35
36
37
# File 'lib/llm/shell/command.rb', line 31

def description(desc = nil)
  if desc
    @description = desc
  else
    @description
  end
end

#setup(bot, io) ⇒ void

This method returns an undefined value.

Setup the command context



42
43
44
# File 'lib/llm/shell/command.rb', line 42

def setup(bot, io)
  @context = Context.new(bot, io)
end

#define(klass = nil, &b) ⇒ void Also known as: register

This method returns an undefined value.

Define the command



49
50
51
# File 'lib/llm/shell/command.rb', line 49

def define(klass = nil, &b)
  @object = klass || b
end

#call(*argv) ⇒ Object

Call the command



57
58
59
60
61
62
63
64
65
# File 'lib/llm/shell/command.rb', line 57

def call(*argv)
  if @context.nil?
    raise "context has not been setup"
  elsif Class === @object
    @object.new(@context).call(*argv)
  else
    @context.instance_exec(*argv, &@object)
  end
end