Class: Ace::Hitl::CLI::Commands::Show

Inherits:
Support::Cli::Command
  • Object
show all
Includes:
Support::Cli::Base
Defined in:
lib/ace/hitl/cli/commands/show.rb

Instance Method Summary collapse

Instance Method Details

#call(ref:, **options) ⇒ Object

Raises:

  • (Ace::Support::Cli::Error)


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
51
52
53
54
55
# File 'lib/ace/hitl/cli/commands/show.rb', line 24

def call(ref:, **options)
  scope = validate_scope(options[:scope])
  manager = Ace::Hitl::Organisms::HitlManager.new
  begin
    resolved = manager.show(ref, scope: scope)
  rescue Ace::Hitl::Organisms::HitlManager::AmbiguousReferenceError => e
    candidates = e.matches.map(&:file_path).join(", ")
    raise Ace::Support::Cli::Error.new(
      "HITL event '#{ref}' is ambiguous across scope '#{scope || "all"}'. Candidates: #{candidates}"
    )
  end
  raise Ace::Support::Cli::Error.new("HITL event '#{ref}' not found") unless resolved
  event = resolved[:event]
  resolved_location = format_resolved_location(resolved)

  if options[:path]
    puts event.file_path
  elsif options[:content]
    puts resolved_location if resolved_location
    puts File.read(event.file_path)
  else
    puts "ID: #{event.id}"
    puts "Title: #{event.title}"
    puts "Status: #{event.status}"
    puts "Kind: #{event.kind}"
    puts "Tags: #{event.tags.join(", ")}"
    puts "Questions: #{event.questions.join(" | ")}"
    puts "Answer: #{event.answer || "(none)"}"
    puts resolved_location if resolved_location
    puts "Path: #{event.file_path}"
  end
end