8
9
10
11
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/ragdoll/cli/commands/list.rb', line 8
def call(options)
client = StandaloneClient.new
puts 'Listing documents'
puts "Options: #{options.to_h}" unless options.to_h.empty?
puts
list_options = {}
list_options[:limit] = options[:limit] if options[:limit]
documents = client.list_documents(**list_options)
if documents.empty?
puts 'No documents found.'
return
end
case options[:format]
when 'json'
puts JSON.pretty_generate(documents)
when 'plain'
documents.each_with_index do |doc, index|
puts "#{index + 1}. #{doc[:title] || 'Untitled'}"
puts " ID: #{doc[:id]}"
puts " Status: #{doc[:status] || 'N/A'}"
puts
end
else
puts "Found #{documents.length} documents:"
puts
puts 'Rank'.ljust(5) + 'Title'.ljust(30) + 'ID'.ljust(10) + 'Status'
puts '-' * 60
documents.each_with_index do |doc, index|
rank = (index + 1).to_s.ljust(5)
title = (doc[:title] || 'Untitled')[0..29].ljust(30)
id = doc[:id].to_s.ljust(10)
status = doc[:status] || 'N/A'
puts "#{rank}#{title}#{id}#{status}"
end
puts
puts 'Use --format=json for complete results or --format=plain for detailed view'
end
end
|