Class: Agent::Sessions::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/sessions/cli.rb

Constant Summary collapse

STATUS_MARKS =
{ pass: "", fail: "", drift: "~", skip: "-" }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(argv, env: ENV, stdout: $stdout, stderr: $stderr, now: Time.now) ⇒ CLI

Returns a new instance of CLI.



11
12
13
14
15
16
17
18
# File 'lib/agent/sessions/cli.rb', line 11

def initialize(argv, env: ENV, stdout: $stdout, stderr: $stderr, now: Time.now)
  @argv = argv.dup
  @env = env
  @stdout = stdout
  @stderr = stderr
  @now = now
  @skipped_agents = []
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/agent/sessions/cli.rb', line 20

def run
  command = @argv.shift
  case command
  when "where" then where
  when "list" then list
  when "du" then du
  when "doctor" then doctor
  when "audit" then audit
  when "version", "--version", "-v" then version
  when nil, "help", "--help", "-h" then help(@stdout, 0)
  else
    @stderr.puts "unknown command: #{command}"
    help(@stderr, 1)
  end
# Catches UnknownAgent for a typo'd agent, the declaration errors an
# adapter raises when it is misconfigured, and — since Task 8 —
# MissingDependency (opencode's sqlite3 gem missing) and UnreadableStore
# (opencode's database present but unreadable), both Agent::Sessions::Error
# subclasses. "Layer 1 never raises for disk state" was true before
# Layer 2 existed; it is not anymore — opencode's Layer 2 raises both
# deliberately (design doc section 9). `list` (Task 10) is the first
# command that walks Layer 2, and it does NOT rely on this rescue for
# that case — collect_sessions catches both per agent so one bad store
# never empties the rest of the listing (decision 11). This broad catch
# still matters for `list`'s own option parsing (a malformed --since is
# an Agent::Sessions::Error) and stays here as the backstop for whichever
# future command calls into Layer 2 without its own per-agent rescue.
rescue Agent::Sessions::Error, Agent::Homedir::Error, OptionParser::ParseError => e
  @stderr.puts e.message
  1
end