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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/licensee/commands/detect.rb', line 14
def detect(_path = nil)
Licensee.confidence_threshold = options[:confidence]
if options[:json]
say project.to_h.to_json
exit !project.licenses.empty?
end
rows = []
rows << if project.license
['License:', project.license.spdx_id]
elsif !project.licenses.empty?
['Licenses:', project.licenses.map(&:spdx_id)]
else
['License:', set_color('None', :red)]
end
unless project.matched_files.empty?
rows << ['Matched files:', project.matched_files.map(&:filename).join(', ')]
end
print_table rows
project.matched_files.each do |matched_file|
rows = []
say "#{matched_file.filename}:"
MATCHED_FILE_METHODS.each do |method|
next unless matched_file.respond_to? method
value = matched_file.public_send method
next if value.nil?
rows << [humanize(method, :method), humanize(value, method)]
end
print_table rows, indent: 2
next unless matched_file.is_a? Licensee::ProjectFiles::LicenseFile
next if matched_file.confidence == 100
licenses = licenses_by_similarity(matched_file)
next if licenses.empty?
say ' Closest non-matching licenses:'
rows = licenses[0...3].map do |license, similarity|
spdx_id = license.meta['spdx-id']
percent = Licensee::ContentHelper.format_percent(similarity)
["#{spdx_id} similarity:", percent]
end
print_table rows, indent: 4
end
if project.license_file && (options[:license] || options[:diff])
license = options[:license] || closest_license_key(project.license_file)
if license
invoke(:diff, nil,
license: license, license_to_diff: project.license_file)
end
end
exit !project.licenses.empty?
end
|