28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/legion/cli/chat/tools/view_events.rb', line 28
def execute(count: 15)
count = count.to_i.clamp(1, 100)
data = api_get("/api/events/recent?count=#{count}")
return "API error: #{data[:error]}" if data[:error]
events = data[:data] || data
events = [events] if events.is_a?(Hash)
return 'No recent events.' if !events.is_a?(Array) || events.empty?
format_events(events)
rescue Errno::ECONNREFUSED
'Legion daemon not running (cannot reach events API).'
rescue StandardError => e
Legion::Logging.warn("ViewEvents#execute failed: #{e.message}") if defined?(Legion::Logging)
"Error fetching events: #{e.message}"
end
|