Class: RubynCode::CLI::Commands::CustomCommand

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

Overview

A slash command defined by a user markdown file (loaded by CustomLoader). Unlike the built-in commands — which are registered as classes — this is a ready instance: the Registry dispatches it directly.

Executing it renders the template (argument / bash substitution) and sends the result to the agent as a normal prompt.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description:, body:, source: nil) ⇒ CustomCommand

Returns a new instance of CustomCommand.



20
21
22
23
24
25
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 20

def initialize(name:, description:, body:, source: nil)
  @name = name
  @description = description
  @template = CommandTemplate.new(body)
  @source = source
end

Instance Attribute Details

#descriptionString (readonly)

Returns one-line description for /help.

Returns:

  • (String)

    one-line description for /help



16
17
18
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 16

def description
  @description
end

#nameString (readonly)

Returns command name without the leading slash.

Returns:

  • (String)

    command name without the leading slash



14
15
16
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 14

def name
  @name
end

#sourceString? (readonly)

Returns originating file path.

Returns:

  • (String, nil)

    originating file path



18
19
20
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 18

def source
  @source
end

Instance Method Details

#aliasesObject



28
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 28

def aliases = [].freeze

#all_namesObject



30
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 30

def all_names = [command_name].freeze

#command_nameObject



27
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 27

def command_name = "/#{@name}"

#execute(args, ctx) ⇒ nil

Parameters:

Returns:

  • (nil)


35
36
37
38
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 35

def execute(args, ctx)
  ctx.send_message(@template.render(args))
  nil
end

#hidden?Boolean

Returns:

  • (Boolean)


29
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 29

def hidden? = false