Class: Harnex::WatchCommand

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ WatchCommand

Returns a new instance of WatchCommand.



358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/harnex/commands/watch.rb', line 358

def initialize(argv)
  @argv = argv.dup
  @options = {
    id: nil,
    repo_path: Dir.pwd,
    until_state: "done",
    max_wait: nil,
    done_marker: nil,
    fail_marker: nil,
    stop_on_terminal: false,
    help: false
  }
end

Class Method Details

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



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/harnex/commands/watch.rb', line 335

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

    Options:
      --id ID              Existing session ID to watch (required)
      --until done         Watch work-level terminal state (default: done)
      --repo PATH          Resolve session using PATH's repo root (default: current repo)
      --max-wait DUR       Wall-clock cap before returning timeout (examples: 900, 15m, 2h)
      --timeout DUR        Alias for --max-wait
      --done-marker PATH   Write a JSON marker when work completes successfully
      --fail-marker PATH   Write a JSON marker when work fails
      --stop-on-terminal   Stop the live session after success/failure (not on timeout)
      -h, --help           Show this help

    `harnex watch` is the safe watcher for existing --tmux or detached
    dispatches. It exits 0 for task_complete/done, non-zero for task_failed
    or failed terminal summaries, and 124 for --max-wait timeouts.

    For launch-and-babysit stall recovery, use `harnex run --watch`.
  TEXT
end

Instance Method Details

#runObject



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/harnex/commands/watch.rb', line 372

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

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

  TerminalWatcher.new(
    id: @options[:id],
    repo_path: @options[:repo_path],
    until_state: @options[:until_state],
    max_wait: @options[:max_wait],
    done_marker: @options[:done_marker],
    fail_marker: @options[:fail_marker],
    stop_on_terminal: @options[:stop_on_terminal]
  ).run
end