Class: Agent::SessionContext::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/session_context/cli.rb,
lib/agent/session_context/cli/options.rb

Defined Under Namespace

Classes: Options

Constant Summary collapse

FORMATS =
%w[text markdown json jsonl].freeze

Instance Method Summary collapse

Constructor Details

#initialize(argv, env: ENV, stdout: $stdout, stderr: $stderr, now: Time.now, resolver: SessionResolver.new(env: env), builder: Builder.new(now: now), backend_factory: Summarizers, config_loader: Config) ⇒ CLI

Returns a new instance of CLI.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/agent/session_context/cli.rb', line 10

def initialize(
  argv,
  env: ENV,
  stdout: $stdout,
  stderr: $stderr,
  now: Time.now,
  resolver: SessionResolver.new(env: env),
  builder: Builder.new(now: now),
  backend_factory: Summarizers,
  config_loader: Config
)
  @argv = argv.dup
  @env = env
  @stdout = stdout
  @stderr = stderr
  @resolver = resolver
  @builder = builder
  @backend_factory = backend_factory
  @config_loader = config_loader
  @current_format = :text
end

Instance Method Details

#run ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/agent/session_context/cli.rb', line 32

def run
  case (command = @argv.shift)
  when "show" then show
  when "prompts" then prompts
  # Named loop_command, not loop: Kernel#loop is an instance method
  # available everywhere, and a method named `loop` on this CLI object
  # would shadow it for the rest of this instance.
  when "loop" then loop_command
  when "summarize" then summarize
  when "version", "--version", "-v" then version(@argv)
  when nil then help([], @stdout, 0)
  when "help", "--help", "-h" then help(@argv, @stdout, 0)
  else
    @stderr.puts "unknown command: #{safe_text(command)}"
    1
  end
rescue Agent::SessionContext::Error, OptionParser::ParseError => e
  emit_error(e)
  1
end