Class: Harnex::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/harnex/commands/events.rb

Constant Summary collapse

POLL_INTERVAL =
0.1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Events

Returns a new instance of Events.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/harnex/commands/events.rb', line 24

def initialize(argv)
  @argv = argv.dup
  @options = {
    id: nil,
    repo_path: Dir.pwd,
    cli: nil,
    follow: true,
    from: nil,
    help: false
  }
  @tail_buffer = +""
end

Class Method Details

.usage(program_name = "harnex events") ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/harnex/commands/events.rb', line 9

def self.usage(program_name = "harnex events")
  <<~TEXT
    Usage: #{program_name} [options]

    Options:
      --id ID         Session ID to inspect (required)
      --repo PATH     Resolve using PATH's repo root (default: current repo)
      --cli CLI       Filter the active session by CLI
      --[no-]follow   Keep streaming appended events (default: true)
      --snapshot      Print current events and exit (alias for --no-follow)
      --from TS       Replay floor (ISO-8601, inclusive)
      -h, --help      Show this help
  TEXT
end

Instance Method Details

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/harnex/commands/events.rb', line 37

def run
  parser.parse!(@argv)
  if @options[:help]
    puts self.class.usage
    return 0
  end

  raise "--id is required for harnex events" unless @options[:id]

  target = resolve_target
  return 1 unless target

  offset = print_snapshot(target.fetch(:path))
  return 0 unless @options[:follow] && target[:live]

  follow(target.fetch(:path), offset)
end