Class: Harbor::CLI::Logs

Inherits:
Object
  • Object
show all
Defined in:
lib/harbor/cli/logs.rb

Instance Method Summary collapse

Constructor Details

#initialize(options, config) ⇒ Logs

Returns a new instance of Logs.



6
7
8
9
10
# File 'lib/harbor/cli/logs.rb', line 6

def initialize(options, config)
  @options = options
  @config = config
  @tools = Harbor::Tools.new(config)
end

Instance Method Details

#logs(project_name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/harbor/cli/logs.rb', line 12

def logs(project_name)
  if @options["follow"]
    # Live tail: exec's kamal directly so stdout streams in real time.
    # Kernel can't deliver a stream through its synchronous call API.
    # The adapter log fetch that the kernel exposes is for bounded
    # retrieval (last N lines). Follow mode is a different surface.
    stream_logs(project_name)
  else
    output = @tools.call(
      "harbor_get_logs",
      {
        "project" => project_name,
        "role" => @options["role"],
        "lines" => @options["lines"],
        "grep" => @options["grep"],
        "destination" => @options["destination"]
      },
      actor: cli_actor,
      origin: :cli
    )
    $stdout.puts output
  end
rescue Harbor::Error => e
  $stderr.puts "#{e.class.name.split('::').last}: #{e.message}"
  exit 1
end