Class: PromptObjects::CLI::EventsCommand

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

Overview

events command: show recent events from the message bus.

Instance Method Summary collapse

Instance Method Details

#helpObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/prompt_objects/cli/events_command.rb', line 61

def help
  prog = Helpers.program_name
  puts <<~HELP
    Usage: #{prog} events [options] <environment>

    Show recent events from the message bus.

    Arguments:
      environment  Environment name or path

    Options:
      --session ID     Show events for a specific session
      --count N        Number of events to show (default: 50)
      --json           Output as JSON
      --help, -h       Show this help

    Examples:
      #{prog} events my-env
      #{prog} events my-env --session abc-123
      #{prog} events my-env --count 100 --json
  HELP
end

#run(args) ⇒ Object



9
10
11
12
13
14
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
53
54
55
56
57
58
59
# File 'lib/prompt_objects/cli/events_command.rb', line 9

def run(args)
  options = { count: 50, session_id: nil, json: false }
  positional = []
  skip_next = false

  args.each_with_index do |arg, i|
    if skip_next
      skip_next = false
      next
    end

    case arg
    when "--session"
      options[:session_id] = args[i + 1]
      skip_next = true
    when "--count"
      options[:count] = args[i + 1].to_i
      skip_next = true
    when "--json"
      options[:json] = true
    when "--help", "-h"
      help
      exit 0
    else
      positional << arg
    end
  end

  env_name = positional[0]
  unless env_name
    puts "Error: environment name required"
    puts "Run '#{Helpers.program_name} events --help' for usage"
    exit 1
  end

  env_path = Helpers.resolve_environment(env_name)
  unless env_path
    $stderr.puts "Error: environment '#{env_name}' not found"
    exit 1
  end

  # Check for running server
  require "prompt_objects/server"
  server_info = PromptObjects::Server.read_server_file(env_path)

  if server_info
    show_via_http(server_info, options)
  else
    show_standalone(env_path, options)
  end
end