Class: Rubino::Commands::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/commands/command.rb

Overview

Represents a custom slash command loaded from a Markdown file. Supports $ARGUMENTS, $1-$9 positional params, @file refs.

Shell injection via !‘command` is opt-in and disabled by default. Enable it by setting commands.shell_injection_enabled: true in your configuration — only do so in trusted, controlled environments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ Command

Returns a new instance of Command.



16
17
18
19
20
21
# File 'lib/rubino/commands/command.rb', line 16

def initialize(path:)
  @path     = path
  @metadata = {}
  @template = nil
  parse!
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



14
15
16
# File 'lib/rubino/commands/command.rb', line 14

def agent
  @agent
end

#descriptionObject (readonly)

Returns the value of attribute description.



14
15
16
# File 'lib/rubino/commands/command.rb', line 14

def description
  @description
end

#modelObject (readonly)

Returns the value of attribute model.



14
15
16
# File 'lib/rubino/commands/command.rb', line 14

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/rubino/commands/command.rb', line 14

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/rubino/commands/command.rb', line 14

def path
  @path
end

Instance Method Details

#render(arguments = "") ⇒ Object

Renders the command prompt with given arguments.



24
25
26
27
28
29
30
31
32
# File 'lib/rubino/commands/command.rb', line 24

def render(arguments = "")
  prompt = template.dup

  substitute_arguments!(prompt, arguments)
  process_shell_injections!(prompt)
  process_file_references!(prompt)

  prompt.strip
end

#templateObject

Returns the raw template content.



35
36
37
# File 'lib/rubino/commands/command.rb', line 35

def template
  @template ||= load_template
end