Class: SwarmCLI::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



11
12
13
# File 'lib/swarm_cli/cli.rb', line 11

def initialize(args)
  @args = args
end

Class Method Details

.start(args) ⇒ Object



6
7
8
# File 'lib/swarm_cli/cli.rb', line 6

def start(args)
  new(args).run
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
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
52
# File 'lib/swarm_cli/cli.rb', line 15

def run
  # Handle special cases first
  if @args.empty? || @args.include?("--help") || @args.include?("-h")
    print_help
    exit(0)
  end

  if @args.include?("--version") || @args.include?("-v")
    print_version
    exit(0)
  end

  # Extract command
  command = @args.first

  # Route to command
  case command
  when "run"
    run_command(@args[1..])
  when "mcp"
    mcp_command(@args[1..])
  when "migrate"
    migrate_command(@args[1..])
  else
    # Check if it's an extension command
    if CommandRegistry.registered?(command)
      extension_command(command, @args[1..])
    else
      $stderr.puts "Unknown command: #{command}"
      $stderr.puts
      print_help
      exit(1)
    end
  end
rescue StandardError => e
  $stderr.puts "Fatal error: #{e.message}"
  exit(1)
end