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
55
56
57
58
59
|
# File 'lib/fargo/cli/searches.rb', line 23
def results str = nil, opts = {}
str ||= client.searches.last
results = client.search_results(str)
if results.nil?
puts "No search results for: #{str.inspect}!"
return
end
results = results.map{ |r| r.dup }
results.each_with_index{ |r, i|
r[:file] = r[:file].gsub("\\", '/')
r[:file] = File.basename(r[:file]) unless opts[:full]
r[:index] = i
}
max_nick_size = results.map{ |r| r[:nick].size }.max
if opts[:sort] == 'size'
results = results.sort_by{ |r| r[:size] }
elsif !opts[:sort].nil?
puts "Unknown sort value: #{opts[:sort]}"
results = []
end
if opts[:grep]
results = results.select{ |r| r[:file].match opts[:grep] }
end
results.each do |r|
printf "%3d: %#{max_nick_size}s %9s -- %s\n", r[:index],
r[:nick], humanize_bytes(r[:size]), r[:file]
end
true
end
|