lib/badger/cli.rb in badgerbadgerbadger-0.3.1 vs lib/badger/cli.rb in badgerbadgerbadger-0.4.0

- old
+ new

@@ -13,25 +13,32 @@ * Coveralls * Gemnasium -Extra badges: currently only one extra badge is supported, a link to the MIT license from here: https://github.com/remy/mit-license, e.g. +If a gemspec is found, the following badges will also be generated: - [![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org) + * [License] badge, linking to the appropriate license + * [Gem version] badge, linking to rubygems.org -If a gemspec is found, the following badges will also be generated: +If a license file is found, a license badge will be generated. Currently supported licenses are: - * [License: MIT] badge (presuming an MIT license is specified, linked as above) + * MIT - * [Gem version] badge, linking to rubygems.org + * Apache + * GPL-2 + + * GPL-3 + +The supported license details are in https://github.com/pikesley/badger/blob/master/config/licenses.yaml, if you're using a different license, send a PR! And if your gemspec license conflicts with your LICENSE file, you should probably fix that. + + LONGDESC option :not, desc: 'Exclude these services (comma-separated list)' option :only, desc: 'Generate for *only* these services (comma-separated list)' - option :also, desc: 'Include this extra service (currently only \'mit\')' def badge dir = '.' begin @g = Git.open(dir) rescue ArgumentError @@ -53,9 +60,20 @@ spec_file = (Dir.entries dir).select { |i| /gemspec/.match i }[0] if spec_file lines = File.open(File.join(dir, spec_file), 'r').readlines @badger.gemspec lines + end + + license_file = (Dir.entries dir).select { |i| /LICENSE/i.match i }[0] + + if license_file + words = File.open(File.join(dir, license_file), 'r').read + @badger.licenses.each_pair do |k, v| + if /#{v['regex']}/im.match words + @badger.license k + end + end end puts @badger.to_s end \ No newline at end of file