gem-license 0.3.0 → 0.4.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: 0f287b4ff8ad851be08bf6470638c8ed27e2513fe6437e16ac95ed9abd40a722
4
- data.tar.gz: ab1f84d65a0050a76541d3aa227c0d0f6471251876dac8e17d5d19c5923b74c0
3
+ metadata.gz: b102bbba895ece6a8926aeea927a29a3b3c65476e8b43b8385b850ba2354611f
4
+ data.tar.gz: 68f5eb591ef07643eec680943f32f2755d3682314eefcda886f077a11d0c24a3
5
5
  SHA512:
6
- metadata.gz: df9f71bd7567d0e3d4967c759ddd350d8c660283ad4b6fd2d4e26e214f60d9465997ba9de8c88082b598e5350d1342c32aa966d15e64d87f72e99b37d31b7768
7
- data.tar.gz: c9e2bb3ec419a29a532fdd044d9e56bb8fd5d2740fc990e10bd4b5f0a67ff8ed6d4de80ccf50411d744ccf1b28d71b35dc38b652955816f52d370dead32b2e85
6
+ metadata.gz: b5e83086d6ae3b7706e31a371e1e89c5303bb21e0902422fde6577c7da83bef7d39ed888f71e3cb8f7de84ac3b9d6371271b18d10bbcd5f52ead7360d1ce0f53
7
+ data.tar.gz: 40892a7898e4a82b6e2533208164cc32511bf143b1ab90ffa684df9cac75034737c6b38973cf5703781d1e30df0256fc3948b873f712065e48781391a96ff140
@@ -0,0 +1,53 @@
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
@@ -3,3 +3,6 @@ Style/ClassAndModuleChildren:
3
3
 
4
4
  Metrics:
5
5
  Enabled: false
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 2.3
@@ -25,3 +25,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
25
25
  - Suggestions when an identifier does not match in the license list
26
26
  - -l/--list for viewing all available licenses
27
27
  - -o/--output for specifying an output path
28
+ - -f/--format attempt to format common values
data/README.md CHANGED
@@ -11,6 +11,7 @@ gem install gem-license
11
11
  ## Usage
12
12
 
13
13
  ```sh
14
+ # download the MIT license to `LICENSE'
14
15
  gem license mit
15
16
 
16
17
  # output to stdout
@@ -22,6 +23,12 @@ gem license apl-1.0 -m
22
23
  # specify output path
23
24
  gem license mit -o MIT.license
24
25
 
26
+ # attempt to format common values
27
+ # Uses git config --get user.name for author names,
28
+ # and the base name of the current working directory for
29
+ # program/project name.
30
+ gem license mit -f
31
+
25
32
  # view a list of all available licenses
26
33
  gem license -l
27
34
  ```
@@ -2,13 +2,13 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'gem-license'
5
- spec.version = '0.3.0'
5
+ spec.version = '0.4.0'
6
6
  spec.authors = ['Matt Carey']
7
7
  spec.email = ['matthew.b.carey@gmail.com']
8
8
  spec.homepage = 'https://github.com/swarley/gem-license'
9
9
 
10
10
  spec.summary = 'Gem plugin to download licenses'
11
- spec.description = 'Gem plugin to download a LICENSE file based on its shortname'
11
+ spec.description = 'Gem plugin to download a LICENSE file based on its SPDX identifier'
12
12
  spec.license = 'MIT'
13
13
 
14
14
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -4,8 +4,6 @@ require 'English'
4
4
 
5
5
  # Container for license fetching utilities
6
6
  module Gem::License
7
- module_function
8
-
9
7
  def fetch_license_list
10
8
  list_uri = URI('https://spdx.org/licenses/licenses.json')
11
9
  JSON.parse(list_uri.read)['licenses']
@@ -30,7 +28,43 @@ module Gem::License
30
28
  abort 'Unable to find a matching SPDX identifier.' + (id ? " Did you mean `#{id}'?" : '')
31
29
  end
32
30
 
33
- def write_license(license_obj, path = nil)
31
+ def format_license(text)
32
+ data_map = {
33
+ /<\s*(year|yyyy|dates)\s*>/i => Time.now.year,
34
+ /<program>/i => File.basename(Dir.pwd)
35
+ }
36
+
37
+ begin
38
+ name = `git config --get user.name`.chomp
39
+ rescue Errno::ENOENT
40
+ name = nil
41
+ say 'Can\'t find git for user.name'
42
+ end
43
+
44
+ if name
45
+ if name.empty?
46
+ say '[WARN] No user.name git config value'
47
+ else
48
+ author = `git config --get user.name`.chomp
49
+ data_map[
50
+ Regexp.union(
51
+ /<\s*author\s*>/i,
52
+ /<\s*name of author\s*>/i,
53
+ /<\s*owner\s*>/i,
54
+ /<copyright holders?>/i
55
+ )
56
+ ] = author
57
+ end
58
+ end
59
+
60
+ data_map.each do |pattern, value|
61
+ text.gsub!(pattern, value.to_s)
62
+ end
63
+
64
+ text
65
+ end
66
+
67
+ def write_license(license_obj, path = nil, format = false)
34
68
  text = fetch_license_text(license_obj['detailsUrl'])
35
69
  text = format_license(text) if format
36
70
 
@@ -43,16 +77,18 @@ module Gem::License
43
77
  end
44
78
  end
45
79
 
46
- def download(shortname, opt)
80
+ def download(spdx_id, opt)
47
81
  license_list = fetch_license_list
48
82
  id_list = license_list.collect { |l_obj| l_obj['licenseId'] }
49
83
 
50
- id = match_license_id(shortname, id_list)
84
+ id = match_license_id(spdx_id, id_list)
51
85
  license_obj = license_list.find { |l_obj| l_obj['licenseId'] == id }
52
86
 
53
87
  path = opt[:output_path]
54
88
  path = 'LICENSE' + (opt[:markdown] ? '.md' : '') if path.nil? && !opt[:stdout]
55
89
 
56
- write_license license_obj, path
90
+ write_license license_obj, path, opt[:format]
91
+
92
+ say 'Remember to read your license for any fields you might need to fill in.'
57
93
  end
58
94
  end
@@ -6,6 +6,8 @@ require 'json'
6
6
 
7
7
  # license gem plugin
8
8
  class Gem::Commands::LicenseCommand < Gem::Command
9
+ include Gem::License
10
+
9
11
  def initialize
10
12
  super('license', 'Download a license by SPDX id')
11
13
 
@@ -24,11 +26,15 @@ class Gem::Commands::LicenseCommand < Gem::Command
24
26
  add_option('-l', '--list', 'View all available licenses') do |_, options|
25
27
  options[:list] = true
26
28
  end
29
+
30
+ add_option('-f', '--format', 'Attempt to fill in values like year, author, and program name') do |_, options|
31
+ options[:format] = true
32
+ end
27
33
  end
28
34
 
29
35
  def execute
30
36
  if options[:list]
31
- list = Gem::License.fetch_license_list
37
+ list = fetch_license_list
32
38
  just_size = list.collect { |lsc| lsc['licenseId'].length }.max
33
39
  list.each do |license|
34
40
  say(license['licenseId'].ljust(just_size) + ' - ' + license['name'])
@@ -37,7 +43,7 @@ class Gem::Commands::LicenseCommand < Gem::Command
37
43
  end
38
44
 
39
45
  id = options[:args].first || abort("USAGE: #{usage}")
40
- Gem::License.download(id, options)
46
+ download(id, options)
41
47
  end
42
48
 
43
49
  def description
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-license
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Carey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-23 00:00:00.000000000 Z
11
+ date: 2019-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.69'
55
- description: Gem plugin to download a LICENSE file based on its shortname
55
+ description: Gem plugin to download a LICENSE file based on its SPDX identifier
56
56
  email:
57
57
  - matthew.b.carey@gmail.com
58
58
  executables: []
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".editorconfig"
63
+ - ".gitignore"
63
64
  - ".rubocop.yml"
64
65
  - CHANGELOG.md
65
66
  - LICENSE