Class: RubynCode::CLI::Commands::CustomCommand
- Inherits:
-
Object
- Object
- RubynCode::CLI::Commands::CustomCommand
- 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
-
#description ⇒ String
readonly
One-line description for /help.
-
#name ⇒ String
readonly
Command name without the leading slash.
-
#source ⇒ String?
readonly
Originating file path.
Instance Method Summary collapse
- #aliases ⇒ Object
- #all_names ⇒ Object
- #command_name ⇒ Object
- #execute(args, ctx) ⇒ nil
- #hidden? ⇒ Boolean
-
#initialize(name:, description:, body:, source: nil) ⇒ CustomCommand
constructor
A new instance of CustomCommand.
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
#description ⇒ String (readonly)
Returns one-line description for /help.
16 17 18 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 16 def description @description end |
#name ⇒ String (readonly)
Returns command name without the leading slash.
14 15 16 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 14 def name @name end |
#source ⇒ String? (readonly)
Returns originating file path.
18 19 20 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 18 def source @source end |
Instance Method Details
#aliases ⇒ Object
28 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 28 def aliases = [].freeze |
#all_names ⇒ Object
30 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 30 def all_names = [command_name].freeze |
#command_name ⇒ Object
27 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 27 def command_name = "/#{@name}" |
#execute(args, ctx) ⇒ nil
35 36 37 38 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 35 def execute(args, ctx) ctx.(@template.render(args)) nil end |
#hidden? ⇒ Boolean
29 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 29 def hidden? = false |