Class: Dontbugme::CLI

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

Instance Method Summary collapse

Instance Method Details

#diff(trace_id_a, trace_id_b) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dontbugme/cli.rb', line 35

def diff(trace_id_a, trace_id_b)
  ensure_loaded
  trace_a = store.find_trace(trace_id_a)
  trace_b = store.find_trace(trace_id_b)
  if trace_a.nil?
    puts "Trace not found: #{trace_id_a}"
    exit 1
  end
  if trace_b.nil?
    puts "Trace not found: #{trace_id_b}"
    exit 1
  end
  puts Formatters::Diff.format(trace_a, trace_b)
end

#listObject



9
10
11
12
13
# File 'lib/dontbugme/cli.rb', line 9

def list
  ensure_loaded
  traces = store.search(limit: options[:limit])
  display_list(traces)
end

#searchObject



80
81
82
83
84
85
86
87
88
# File 'lib/dontbugme/cli.rb', line 80

def search
  ensure_loaded
  filters = { limit: options[:limit] }
  filters[:status] = options[:status] if options[:status]
  filters[:kind] = options[:kind] if options[:kind]
  filters[:identifier] = options[:identifier] || options[:class]
  traces = store.search(filters)
  display_list(traces)
end

#show(trace_id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dontbugme/cli.rb', line 19

def show(trace_id)
  ensure_loaded
  trace = store.find_trace(trace_id)
  if trace.nil?
    puts "Trace not found: #{trace_id}"
    exit 1
  end

  if options[:json]
    puts Formatters::Json.format(trace)
  else
    puts Formatters::Timeline.format(trace, only: options[:only], slow: options[:slow])
  end
end

#trace(trace_id) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dontbugme/cli.rb', line 52

def trace(trace_id)
  ensure_loaded
  root = store.find_trace(trace_id)
  if root.nil?
    puts "Trace not found: #{trace_id}"
    exit 1
  end

  if options[:follow]
    cid = root.correlation_id || root.[:correlation_id]
    if cid.nil? || cid.to_s.empty?
      puts "No correlation ID for trace #{trace_id}. Showing single trace."
      puts Formatters::Timeline.format(root)
      return
    end
    traces = store.search(correlation_id: cid, limit: 100)
    puts format_correlation_tree(traces, root)
  else
    puts Formatters::Timeline.format(root)
  end
end