diff --git a/src/commands/licenses.cr b/src/commands/licenses.cr index 5a9ba18..395a2c9 100644 --- a/src/commands/licenses.cr +++ b/src/commands/licenses.cr @@ -22,12 +22,35 @@ module Geode::Commands return if libs.empty? paths = [] of String - libs.each do |child| paths += find_licenses Path["lib"] / child end - pp paths + trigram = Trigram.new do |t| + License.licenses.each { |l| t.add l.title } + end + licenses = [] of License + + paths.each do |path| + header = File + .read_lines(path) + .find!(&.presence) + .gsub(/^The|Version\s?|\(.*\)/, "") + .strip + + res = trigram.query header + next if res.empty? + + licenses << License.licenses[res[0] - 1] + end + + unless licenses.size == paths.size + warn "Could not resolve licenses for #{paths.size - licenses.size} shards" + end + + licenses.each do |license| + stdout << "• " << license.title << '\n' + end end private def get_libraries : Array(String) diff --git a/src/geode.cr b/src/geode.cr index aa47c88..2b72006 100644 --- a/src/geode.cr +++ b/src/geode.cr @@ -5,6 +5,7 @@ require "file_utils" require "ini" require "license" require "lua" +require "trigram" require "yaml" require "./commands/*"