Skip to content

Commit

Permalink
feat(commands): license resolution via trigrams
Browse files Browse the repository at this point in the history
  • Loading branch information
devnote-dev committed Oct 13, 2023
1 parent e556edf commit 89e6596
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/commands/licenses.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/geode.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require "file_utils"
require "ini"
require "license"
require "lua"
require "trigram"
require "yaml"

require "./commands/*"
Expand Down

0 comments on commit 89e6596

Please sign in to comment.