Class: Harnex::Status

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

Constant Summary collapse

DESCRIPTION_WIDTH =
30
REPO_WIDTH =
20

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Status

Returns a new instance of Status.



35
36
37
38
39
40
41
42
43
44
# File 'lib/harnex/commands/status.rb', line 35

def initialize(argv)
  @argv = argv.dup
  @options = {
    id: nil,
    repo_path: Dir.pwd,
    all: false,
    json: false,
    help: false
  }
end

Class Method Details

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/harnex/commands/status.rb', line 12

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

    Options:
      --id ID      Show a specific session
      --repo PATH  Filter to PATH's repo root (default: current repo)
      --all        List sessions across all repos
      --json       Output JSON instead of a table
      -h, --help   Show this help

    Common patterns:
      #{program_name}
      #{program_name} --all
      #{program_name} --id cx-i-42 --json

    Gotchas:
      By default, status filters to the current repo root.
      Use --all when supervising workers launched from sibling worktrees.
      A prompt-like state is not a completion signal by itself.
  TEXT
end

Instance Method Details

#runObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/harnex/commands/status.rb', line 46

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

  sessions = load_sessions
  if @options[:json]
    puts JSON.generate(sessions)
    return 0
  end

  if sessions.empty?
    if @options[:all]
      puts "No active harnex sessions."
    else
      puts "No active harnex sessions for #{Harnex.resolve_repo_root(@options[:repo_path])}."
    end
    return 0
  end

  puts render_table(sessions)
  0
end