Class: Ace::Support::Nav::Organisms::CommandDelegator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/nav/organisms/command_delegator.rb

Overview

Handles command delegation for cmd-type protocols Executes external commands based on protocol configuration templates

Instance Method Summary collapse

Constructor Details

#initialize(config_loader: nil) ⇒ CommandDelegator

Returns a new instance of CommandDelegator.



13
14
15
# File 'lib/ace/support/nav/organisms/command_delegator.rb', line 13

def initialize(config_loader: nil)
  @config_loader = config_loader || Molecules::ConfigLoader.new
end

Instance Method Details

#delegate(uri_string, options = {}) ⇒ Integer

Delegate a URI to an external command

Parameters:

  • uri_string (String)

    The URI to delegate (e.g., “task://083”)

  • options (Hash) (defaults to: {})

    Options from CLI (e.g., true, content: true)

Returns:

  • (Integer)

    Exit code from the delegated command



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ace/support/nav/organisms/command_delegator.rb', line 21

def delegate(uri_string, options = {})
  # Parse the URI to extract protocol and reference
  protocol, reference = parse_uri(uri_string)

  # Load protocol configuration
  protocol_config = @config_loader.load_protocol_config(protocol)

  # Verify this is a cmd-type protocol
  unless protocol_config["type"] == "cmd"
    raise ArgumentError, "Protocol #{protocol} is not a cmd-type protocol"
  end

  # Get command template
  command_template = protocol_config["command_template"]
  unless command_template
    raise ArgumentError, "Protocol #{protocol} missing command_template"
  end

  # Build the command
  command_parts = build_command(command_template, reference, options, protocol_config)

  # Execute the command
  execute_command(command_parts)
end