Class: RubynCode::CLI::Commands::CommandTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/cli/commands/command_template.rb

Overview

Renders a user-defined slash-command body into a prompt, mirroring Claude Code's command templating:

$ARGUMENTS   

Bash substitution runs the user's own command file, so it carries the same trust as user hooks. Output is captured defensively and capped.

Constant Summary collapse

BANG =
/!`([^`]+)`/
POSITIONAL =
/\$([1-9])/
MAX_BASH_OUTPUT =
16 * 1024

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ CommandTemplate

Returns a new instance of CommandTemplate.



22
23
24
# File 'lib/rubyn_code/cli/commands/command_template.rb', line 22

def initialize(body)
  @body = body.to_s
end

Instance Method Details

#render(args = []) ⇒ String

Returns the rendered prompt.

Parameters:

  • (defaults to: [])

    arguments passed after the command name

Returns:

  • the rendered prompt



28
29
30
31
32
# File 'lib/rubyn_code/cli/commands/command_template.rb', line 28

def render(args = [])
  text = substitute_bash(@body)
  text = text.gsub('$ARGUMENTS', args.join(' '))
  text.gsub(POSITIONAL) { args[Regexp.last_match(1).to_i - 1].to_s }
end