Class: LLM::Shell::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/shell/commands/help.rb,
lib/llm/shell/commands/utils.rb,
lib/llm/shell/command/extension.rb,
lib/llm/shell/commands/show_chat.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_version.rb,
lib/llm/shell/commands/system_prompt.rb,
lib/llm/shell/command.rb

Defined Under Namespace

Modules: Extension, Utils Classes: ClearScreen, Context, DirImport, FileImport, Help, ShowChat, ShowVersion, SystemPrompt

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectClass, #call (readonly)

Returns the underlying command object

Returns:



18
19
20
# File 'lib/llm/shell/command.rb', line 18

def object
  @object
end

Instance Method Details

#builtin!void

This method returns an undefined value.

Mark this command as builtin command



84
85
86
# File 'lib/llm/shell/command.rb', line 84

def builtin!
  @builtin = true
end

#builtin?Boolean

Returns true if this is a builtin command

Returns:

  • (Boolean)

    Returns true if this is a builtin command



77
78
79
# File 'lib/llm/shell/command.rb', line 77

def builtin?
  @builtin
end

#call(*argv) ⇒ Object

Call the command



64
65
66
67
68
69
70
71
72
# File 'lib/llm/shell/command.rb', line 64

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

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

This method returns an undefined value.

Define the command



56
57
58
# File 'lib/llm/shell/command.rb', line 56

def define(klass = nil, &b)
  @object = klass || b
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)


38
39
40
41
42
43
44
# File 'lib/llm/shell/command.rb', line 38

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

#name(name = nil) ⇒ String

Set or get the command name

Parameters:

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

    The name of the command

Returns:

  • (String)


25
26
27
28
29
30
31
# File 'lib/llm/shell/command.rb', line 25

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

#setup(bot, io) ⇒ void

This method returns an undefined value.

Setup the command context



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

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