gem-license 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 816046036a98b7c44fd1c211886443bf60f92c7726245b81878ca20db36cd934
4
- data.tar.gz: 1f4116b96839c2223cb2204cd58739967d990deaa7979757ad1d57cc69d24be4
3
+ metadata.gz: 0f287b4ff8ad851be08bf6470638c8ed27e2513fe6437e16ac95ed9abd40a722
4
+ data.tar.gz: ab1f84d65a0050a76541d3aa227c0d0f6471251876dac8e17d5d19c5923b74c0
5
5
  SHA512:
6
- metadata.gz: a9072fa5c7ff0c084662598811629f4df2771f606b29392fed8050056e5b67c39a60f6502109a40190730323c0bb27da3b66b04a6c1c106b0939e335adff90f4
7
- data.tar.gz: d8b9bb473167363dbaa484fd8c9b280a2757c1753b23cdcfbe0928c75cd350f3b3c906e535c60668b4bf4ddf4a31485eaaff7c5c8413e88c2ff1de1cf897d70f
6
+ metadata.gz: df9f71bd7567d0e3d4967c759ddd350d8c660283ad4b6fd2d4e26e214f60d9465997ba9de8c88082b598e5350d1342c32aa966d15e64d87f72e99b37d31b7768
7
+ data.tar.gz: c9e2bb3ec419a29a532fdd044d9e56bb8fd5d2740fc990e10bd4b5f0a67ff8ed6d4de80ccf50411d744ccf1b28d71b35dc38b652955816f52d370dead32b2e85
data/.editorconfig ADDED
@@ -0,0 +1,8 @@
1
+ root = true
2
+
3
+ [*.rb,Gemfile,*.gemspec,Rakefile]
4
+ indent_size = 2
5
+ indent_style = space
6
+ end_of_line = lf
7
+ insert_final_newline = true
8
+ charset = utf-8
data/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2019-05-22
11
+
12
+ - Initial implementation
13
+
14
+ ## [0.2.0] - 2019-05-22
15
+
16
+ ### Added
17
+
18
+ - Usage information
19
+ - Handler for no matches against given input
20
+
21
+ ## [0.3.0] - 2019-5-23
22
+
23
+ ### Added
24
+
25
+ - Suggestions when an identifier does not match in the license list
26
+ - -l/--list for viewing all available licenses
27
+ - -o/--output for specifying an output path
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) <year> <copyright holders>
3
+ Copyright (c) 2019 Matt Carey
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
data/README.md CHANGED
@@ -14,10 +14,16 @@ gem install gem-license
14
14
  gem license mit
15
15
 
16
16
  # output to stdout
17
- gem license gpl-3.0
17
+ gem license gpl-3.0 -s
18
18
 
19
19
  # create a LICENSE.md
20
- gem license apl-1.0
20
+ gem license apl-1.0 -m
21
+
22
+ # specify output path
23
+ gem license mit -o MIT.license
24
+
25
+ # view a list of all available licenses
26
+ gem license -l
21
27
  ```
22
28
 
23
29
  Licenses names are all based on SPDX identifiers and are not case sensitive.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ task default: :install
data/gem-license.gemspec CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'gem-license'
5
- spec.version = '0.2.0'
5
+ spec.version = '0.3.0'
6
6
  spec.authors = ['Matt Carey']
7
7
  spec.email = ['matthew.b.carey@gmail.com']
8
+ spec.homepage = 'https://github.com/swarley/gem-license'
8
9
 
9
10
  spec.summary = 'Gem plugin to download licenses'
10
11
  spec.description = 'Gem plugin to download a LICENSE file based on its shortname'
@@ -14,7 +15,9 @@ Gem::Specification.new do |spec|
14
15
  spec.bindir = 'exe'
15
16
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
17
  spec.require_paths = ['lib']
18
+ spec.required_ruby_version = '>= 2.3'
17
19
 
18
20
  spec.add_development_dependency 'bundler', '~> 2.0.1'
21
+ spec.add_development_dependency 'rake', '>= 12.0.0'
19
22
  spec.add_development_dependency 'rubocop', '~> 0.69'
20
23
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+
5
+ # Container for license fetching utilities
6
+ module Gem::License
7
+ module_function
8
+
9
+ def fetch_license_list
10
+ list_uri = URI('https://spdx.org/licenses/licenses.json')
11
+ JSON.parse(list_uri.read)['licenses']
12
+ rescue OpenURI::HTTPError => e
13
+ raise Gem::CommandLineError, "Unable to get license list. [#{e.message}]"
14
+ end
15
+
16
+ def fetch_license_text(url)
17
+ license_uri = URI(url)
18
+ license_obj = JSON.parse(license_uri.read)
19
+ license_obj['licenseText']
20
+ rescue OpenURI::HTTPError => e
21
+ raise Gem::CommandLineError, "Unable to get license text. [#{e.message}]"
22
+ end
23
+
24
+ def match_license_id(license_id, id_list)
25
+ perfect_match = id_list.find { |id| id.downcase == license_id.downcase }
26
+ return perfect_match if perfect_match
27
+
28
+ spell_checker = DidYouMean::SpellChecker.new(dictionary: id_list)
29
+ id = spell_checker.correct(license_id).first
30
+ abort 'Unable to find a matching SPDX identifier.' + (id ? " Did you mean `#{id}'?" : '')
31
+ end
32
+
33
+ def write_license(license_obj, path = nil)
34
+ text = fetch_license_text(license_obj['detailsUrl'])
35
+ text = format_license(text) if format
36
+
37
+ if path
38
+ File.open(path, 'w+') do |f|
39
+ f.write text
40
+ end
41
+ else
42
+ $DEFAULT_OUTPUT.puts text
43
+ end
44
+ end
45
+
46
+ def download(shortname, opt)
47
+ license_list = fetch_license_list
48
+ id_list = license_list.collect { |l_obj| l_obj['licenseId'] }
49
+
50
+ id = match_license_id(shortname, id_list)
51
+ license_obj = license_list.find { |l_obj| l_obj['licenseId'] == id }
52
+
53
+ path = opt[:output_path]
54
+ path = 'LICENSE' + (opt[:markdown] ? '.md' : '') if path.nil? && !opt[:stdout]
55
+
56
+ write_license license_obj, path
57
+ end
58
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'gem_license'
3
4
  require 'open-uri'
4
5
  require 'json'
5
6
 
@@ -15,75 +16,28 @@ class Gem::Commands::LicenseCommand < Gem::Command
15
16
  add_option('-s', '--stdout', 'Write to STDOUT instead of LICENSE') do |_, options|
16
17
  options[:stdout] = true
17
18
  end
18
- end
19
-
20
- def fetch_license_list
21
- list_uri = URI('https://spdx.org/licenses/licenses.json')
22
- JSON.parse(list_uri.read)
23
- rescue OpenURI::HTTPError => e
24
- raise Gem::CommandLineError, "Unable to get license list. [#{e.message}]"
25
- end
26
-
27
- def fetch_license_text(url)
28
- license_uri = URI(url)
29
- license_obj = JSON.parse(license_uri.read)
30
- license_obj['licenseText']
31
- rescue OpenURI::HTTPError => e
32
- raise Gem::CommandLineError, "Unable to get license text. [#{e.message}]"
33
- end
34
-
35
- def match_license_id(license_id, id_list)
36
- license_id_rxp = Regexp.new(Regexp.escape(license_id), Regexp::IGNORECASE)
37
- matched_ids = id_list.select { |id| id =~ license_id_rxp }
38
-
39
- if matched_ids.empty?
40
- say 'Unable to find a matching SPDX identifier'
41
- exit
42
- end
43
-
44
- perfect_match = matched_ids.find { |id| id =~ /\A#{license_id_rxp}\Z/i }
45
19
 
46
- unless perfect_match
47
- say 'Unable to find an exact match. Suggestions below'
48
- matched_ids.each { |id| say "\t#{id}" }
49
- exit
20
+ add_option('-o', '--output=PATH', 'Specify an output path') do |value, options|
21
+ options[:output_path] = value
50
22
  end
51
23
 
52
- perfect_match
53
- end
54
-
55
- def write_license(license_obj)
56
- text = fetch_license_text(license_obj['detailsUrl'])
57
- if options[:stdout]
58
- say text
59
- else
60
- fname = 'LICENSE'
61
- fname += '.md' if options[:markdown]
62
- File.open(fname, 'w+') do |f|
63
- f.write text
64
- end
24
+ add_option('-l', '--list', 'View all available licenses') do |_, options|
25
+ options[:list] = true
65
26
  end
66
27
  end
67
28
 
68
- def download(shortname)
69
- license_list = fetch_license_list['licenses']
70
- id_list = license_list.collect { |l_obj| l_obj['licenseId'] }
71
-
72
- id = match_license_id(shortname, id_list)
73
- license_obj = license_list.find { |l_obj| l_obj['licenseId'] == id }
74
-
75
- write_license license_obj
76
- end
77
-
78
29
  def execute
79
- id = options[:args].first
80
-
81
- if id.nil?
82
- say "USAGE: #{usage}"
30
+ if options[:list]
31
+ list = Gem::License.fetch_license_list
32
+ just_size = list.collect { |lsc| lsc['licenseId'].length }.max
33
+ list.each do |license|
34
+ say(license['licenseId'].ljust(just_size) + ' - ' + license['name'])
35
+ end
83
36
  exit
84
37
  end
85
38
 
86
- download(id)
39
+ id = options[:args].first || abort("USAGE: #{usage}")
40
+ Gem::License.download(id, options)
87
41
  end
88
42
 
89
43
  def description
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-license
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Carey
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 12.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 12.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rubocop
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -45,14 +59,17 @@ executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
- - ".gitignore"
62
+ - ".editorconfig"
49
63
  - ".rubocop.yml"
64
+ - CHANGELOG.md
50
65
  - LICENSE
51
66
  - README.md
67
+ - Rakefile
52
68
  - gem-license.gemspec
69
+ - lib/gem_license.rb
53
70
  - lib/rubygems/commands/license_command.rb
54
71
  - lib/rubygems_plugin.rb
55
- homepage:
72
+ homepage: https://github.com/swarley/gem-license
56
73
  licenses:
57
74
  - MIT
58
75
  metadata: {}
@@ -64,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
81
  requirements:
65
82
  - - ">="
66
83
  - !ruby/object:Gem::Version
67
- version: '0'
84
+ version: '2.3'
68
85
  required_rubygems_version: !ruby/object:Gem::Requirement
69
86
  requirements:
70
87
  - - ">="
data/.gitignore DELETED
@@ -1,53 +0,0 @@
1
- *.gem
2
- *.rbc
3
- /.config
4
- /coverage/
5
- /InstalledFiles
6
- /pkg/
7
- /spec/reports/
8
- /spec/examples.txt
9
- /test/tmp/
10
- /test/version_tmp/
11
- /tmp/
12
-
13
- # Used by dotenv library to load environment variables.
14
- # .env
15
-
16
- # Ignore Byebug command history file.
17
- .byebug_history
18
-
19
- ## Specific to RubyMotion:
20
- .dat*
21
- .repl_history
22
- build/
23
- *.bridgesupport
24
- build-iPhoneOS/
25
- build-iPhoneSimulator/
26
-
27
- ## Specific to RubyMotion (use of CocoaPods):
28
- #
29
- # We recommend against adding the Pods directory to your .gitignore. However
30
- # you should judge for yourself, the pros and cons are mentioned at:
31
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
- #
33
- # vendor/Pods/
34
-
35
- ## Documentation cache and generated files:
36
- /.yardoc/
37
- /_yardoc/
38
- /doc/
39
- /rdoc/
40
-
41
- ## Environment normalization:
42
- /.bundle/
43
- /vendor/bundle
44
- /lib/bundler/man/
45
-
46
- # for a library or gem, you might want to ignore these files since the code is
47
- # intended to run in multiple environments; otherwise, check them in:
48
- # Gemfile.lock
49
- # .ruby-version
50
- # .ruby-gemset
51
-
52
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
- .rvmrc