Class: SwarmCLI::Commands::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_cli/commands/run.rb

Overview

Run command executes a swarm with the given configuration and prompt.

Supports both YAML (.yml, .yaml) and Ruby DSL (.rb) configuration files.

Usage:

swarm run config.yml -p "Build a REST API"
swarm run config.rb -p "Build a REST API"
echo "Build a REST API" | swarm run config.yml
swarm run config.yml -p "Task" --output-format json

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Run

Returns a new instance of Run.



18
19
20
# File 'lib/swarm_cli/commands/run.rb', line 18

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/swarm_cli/commands/run.rb', line 16

def options
  @options
end

Instance Method Details

#executeObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/swarm_cli/commands/run.rb', line 22

def execute
  # Validate options
  options.validate!

  # Load swarm configuration
  swarm = load_swarm

  # Check if interactive mode (no prompt provided and stdin is a tty)
  if options.interactive_mode?
    run_interactive_mode(swarm)
  else
    run_non_interactive_mode(swarm)
  end
rescue SwarmSDK::ConfigurationError, SwarmSDK::AgentNotFoundError => e
  # Configuration errors - show user-friendly message
  handle_error(e, formatter: create_formatter)
  exit(1)
rescue SwarmCLI::ExecutionError => e
  # CLI-specific errors (e.g., missing prompt)
  handle_error(e, formatter: create_formatter)
  exit(1)
rescue Interrupt
  # User cancelled (Ctrl+C)
  $stderr.puts "\n\nExecution cancelled by user"
  exit(130)
rescue StandardError => e
  # Unexpected errors
  handle_error(e, formatter: create_formatter)
  exit(1)
end