getv 1.4.0 → 1.6.1

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: 03d655407021c76e4df2c9ece13fb42e6447f597f9492d240901e49442144e43
4
- data.tar.gz: 6f48191ff06387bfea424457ee41fd5f514cda257c1341ecba87eb82c7237279
3
+ metadata.gz: 853e816de90adcfaac9c59f8b12819af4abf2d12db77bf43c3cc4fd74033ae34
4
+ data.tar.gz: e99c28ae47b5d735c35d01b4d057d9dff33e67d767d4eab1af0611b3ea8431c4
5
5
  SHA512:
6
- metadata.gz: 56d72bdde2f6f8aceb8d0844e30fda53e428efebe748ea8bb98848943f5bad319ff566f2d8d6fde7b71812dbf40bb13b29094d00f6296fb6d88e7910e37b7bd5
7
- data.tar.gz: ecd3ee651658cf63c659a4195dc5f0e7e5d113d963d82f68f1ead2f9ad74cdb76c75f65f6b7c3578da40e96bae39fc296f6db9b6953650044d4ea8b15d86c719
6
+ metadata.gz: c87577b970b42e41c006f36ecf9ad9b1bec1b21838eb2daecf189502ccd5eda7f659544488f5f8613bd95bf59c939d595b2353a01cdd22890aae47525e012576
7
+ data.tar.gz: c1227dddae53f9f8352ba70e5a3aa5bd5a157a1dd35e0c5c92803d63aedf1f72e035a301aa3702d8475f9ac4f4837d6557454be30e351dff55c57cf32e8e6129
data/README.md CHANGED
@@ -39,7 +39,7 @@ SYNOPSIS
39
39
 
40
40
 
41
41
  VERSION
42
- 1.3.0
42
+ 1.5.0
43
43
 
44
44
 
45
45
 
@@ -55,9 +55,9 @@ COMMANDS
55
55
  docker - Get package versions from a Docker or OCI container image registry
56
56
  gem - Get package versions from RubyGems.org
57
57
  get - Get package versions from text file URL
58
- github_commit - Get package versions from GitHub commits. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.
59
- github_release - Get package versions from GitHub releases. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.
60
- github_tag - Get package versions from GitHub tags. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.
58
+ github_commit - Get package versions from GitHub commits
59
+ github_release - Get package versions from GitHub releases
60
+ github_tag - Get package versions from GitHub tags
61
61
  help - Shows a list of commands or help for one command
62
62
  index - Get package versions from web page of links
63
63
  npm - Get package versions from npm at registry.npmjs.org
@@ -70,7 +70,7 @@ Show the latest available version of the `getv` gem:
70
70
 
71
71
  ```console
72
72
  $ getv --latest gem getv
73
- 1.3.0
73
+ 1.5.0
74
74
  ```
75
75
 
76
76
  Show all `dep` GitHub release versions in JSON:
data/exe/getv CHANGED
@@ -34,10 +34,11 @@ class App # rubocop:disable Metrics/ClassLength
34
34
 
35
35
  switch %i[l latest], desc: 'Latest version', negatable: false
36
36
  switch %i[j json], desc: 'Output in json', negatable: false
37
+ flag %i[p proxy], desc: 'Web proxy', default_value: nil
37
38
 
38
- desc 'Get package versions from a Docker or OCI container image registry. Set environment variables $DOCKER_PROXY, $DOCKER_USER and $DOCKER_PASSWORD if required.' # rubocop:disable Layout/LineLength
39
+ desc 'Get package versions from a Docker or OCI container image registry'
39
40
  arg_name 'package_name'
40
- command :docker do |c|
41
+ command :docker do |c| # rubocop:disable Metrics/BlockLength
41
42
  defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
42
43
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
43
44
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
@@ -46,16 +47,19 @@ class App # rubocop:disable Metrics/ClassLength
46
47
  c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
47
48
  default_value: defaults[:semantic_select]
48
49
  c.flag %i[owner], desc: 'Repository owner',
49
- default_value: "'<owner>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
50
+ default_value: "'<owner>' if package_name is in format '<registry>/<owner>/<repo>' or '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
50
51
  c.flag %i[repo], desc: 'Repository name',
51
- default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
52
- c.flag %i[url], desc: 'URL', default_value: defaults[:url]
52
+ default_value: "'<repo>' if package_name is in format '<registry>/<owner>/<repo>' or <owner>/<repo>, otherwise just package_name" # rubocop:disable Layout/LineLength
53
+ c.flag %i[url], desc: 'URL',
54
+ default_value: "'https://<registry>' if package_name is in format '<registry>/<owner>/<repo>', otherwise #{defaults[:url]}" # rubocop:disable Layout/LineLength
55
+ c.flag %i[user], desc: 'Username', default_value: defaults[:user]
56
+ c.flag %i[password], desc: 'Password', default_value: defaults[:password]
53
57
  c.action do |global_options, options, args|
54
58
  help_now! unless args.size == 1
55
59
 
56
60
  opts = global_options.merge(options)
57
61
  opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo,
58
- :url
62
+ :url, :user, :password, :proxy
59
63
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
60
64
  opts[:semantic_only] = !options[:invalid_versions]
61
65
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
@@ -78,7 +82,7 @@ class App # rubocop:disable Metrics/ClassLength
78
82
  help_now! unless args.size == 1
79
83
 
80
84
  opts = global_options.merge(options)
81
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
85
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :proxy
82
86
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
83
87
  opts[:semantic_only] = !options[:invalid_versions]
84
88
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
@@ -101,7 +105,7 @@ class App # rubocop:disable Metrics/ClassLength
101
105
  c.action do |global_options, options, args|
102
106
  help_now! unless args.size == 1
103
107
 
104
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url
108
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url, :proxy
105
109
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
106
110
  opts[:semantic_only] = !options[:invalid_versions]
107
111
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
@@ -110,7 +114,7 @@ class App # rubocop:disable Metrics/ClassLength
110
114
  end
111
115
  end
112
116
 
113
- desc 'Get package versions from GitHub commits. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
117
+ desc 'Get package versions from GitHub commits'
114
118
  arg_name 'package_name'
115
119
  command :github_commit do |c|
116
120
  defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
@@ -122,18 +126,19 @@ class App # rubocop:disable Metrics/ClassLength
122
126
  c.flag %i[repo], desc: 'Repository name',
123
127
  default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
124
128
  c.flag %i[branch], desc: 'Repository branch', default_value: defaults[:branch]
129
+ c.flag %i[token], desc: 'Token', default_value: defaults[:token]
125
130
  c.action do |global_options, options, args|
126
131
  help_now! unless args.size == 1
127
132
 
128
133
  opts = global_options.merge(options)
129
- opts = opts.slice :select_search, :select_replace, :reject, :owner, :repo, :branch
134
+ opts = opts.slice :select_search, :select_replace, :reject, :owner, :repo, :branch, :token, :proxy
130
135
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
131
136
  package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
132
137
  Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
133
138
  end
134
139
  end
135
140
 
136
- desc 'Get package versions from GitHub releases. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
141
+ desc 'Get package versions from GitHub releases'
137
142
  arg_name 'package_name'
138
143
  command :github_release do |c|
139
144
  defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
@@ -147,11 +152,13 @@ class App # rubocop:disable Metrics/ClassLength
147
152
  default_value: "'<owner>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
148
153
  c.flag %i[repo], desc: 'Repository name',
149
154
  default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
155
+ c.flag %i[token], desc: 'Token', default_value: defaults[:token]
150
156
  c.action do |global_options, options, args|
151
157
  help_now! unless args.size == 1
152
158
 
153
159
  opts = global_options.merge(options)
154
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo
160
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo,
161
+ :token, :proxy
155
162
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
156
163
  opts[:semantic_only] = !options[:invalid_versions]
157
164
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
@@ -160,7 +167,7 @@ class App # rubocop:disable Metrics/ClassLength
160
167
  end
161
168
  end
162
169
 
163
- desc 'Get package versions from GitHub tags. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
170
+ desc 'Get package versions from GitHub tags'
164
171
  arg_name 'package_name'
165
172
  command :github_tag do |c|
166
173
  defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
@@ -174,11 +181,13 @@ class App # rubocop:disable Metrics/ClassLength
174
181
  default_value: "'<owner>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
175
182
  c.flag %i[repo], desc: 'Repository name',
176
183
  default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
184
+ c.flag %i[token], desc: 'Token', default_value: defaults[:token]
177
185
  c.action do |global_options, options, args|
178
186
  help_now! unless args.size == 1
179
187
 
180
188
  opts = global_options.merge(options)
181
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo
189
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo,
190
+ :token, :proxy
182
191
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
183
192
  opts[:semantic_only] = !options[:invalid_versions]
184
193
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
@@ -204,7 +213,7 @@ class App # rubocop:disable Metrics/ClassLength
204
213
  help_now! unless args.size == 1
205
214
 
206
215
  opts = global_options.merge(options)
207
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url
216
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url, :proxy
208
217
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
209
218
  opts[:link] == 'value' if options[:link_value]
210
219
  opts[:semantic_only] = !options[:invalid_versions]
@@ -228,7 +237,7 @@ class App # rubocop:disable Metrics/ClassLength
228
237
  help_now! unless args.size == 1
229
238
 
230
239
  opts = global_options.merge(options)
231
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
240
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :proxy
232
241
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
233
242
  opts[:semantic_only] = !options[:invalid_versions]
234
243
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
@@ -251,7 +260,7 @@ class App # rubocop:disable Metrics/ClassLength
251
260
  help_now! unless args.size == 1
252
261
 
253
262
  opts = global_options.merge(options)
254
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
263
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :proxy
255
264
  opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
256
265
  opts[:semantic_only] = !options[:invalid_versions]
257
266
  opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
data/lib/getv/package.rb CHANGED
@@ -9,11 +9,11 @@ module Getv
9
9
  @name = name
10
10
  case name
11
11
  when /rubygem-.*/
12
- opts = { 'type' => 'gem' }.merge(opts)
12
+ opts = { type: 'gem' }.merge(opts)
13
13
  when /nodejs-.*/
14
- opts = { 'type' => 'npm' }.merge(opts)
14
+ opts = { type: 'npm' }.merge(opts)
15
15
  when /python.*-.*/
16
- opts = { 'type' => 'pypi' }.merge(opts)
16
+ opts = { type: 'pypi' }.merge(opts)
17
17
  end
18
18
  if opts[:type] == 'github_commit'
19
19
  opts = {
@@ -29,25 +29,39 @@ module Getv
29
29
  reject: nil,
30
30
  semantic_only: true,
31
31
  semantic_select: ['*'],
32
+ proxy: nil,
32
33
  versions: nil,
33
34
  latest_version: nil
34
35
  }.merge(opts)
35
- if (opts[:type] == 'docker' || opts[:type] =~ /github.*/) && (name.count('/') == 1)
36
- opts = { owner: name.split('/')[0], repo: name.split('/')[1] }.merge(opts)
37
- end
38
36
  case opts[:type]
39
37
  when 'docker'
40
- opts = { owner: 'library', repo: name, url: 'https://registry.hub.docker.com' }.merge(opts)
38
+ opts = { user: nil, password: nil }.merge(opts)
39
+ opts = case name.count('/')
40
+ when 0
41
+ { owner: 'library', repo: name, url: 'https://registry.hub.docker.com' }.merge(opts)
42
+ when 1
43
+ { owner: name.split('/')[0], repo: name.split('/')[1],
44
+ url: 'https://registry.hub.docker.com' }.merge(opts)
45
+ else
46
+ { owner: name.split('/')[1], repo: name.split('/')[2..-1].join('/'),
47
+ url: "https://#{name.split('/')[0]}" }.merge(opts)
48
+ end
41
49
  when 'gem'
42
50
  opts = { gem: name[/rubygem-(.*)/, 1] || name }.merge(opts)
43
51
  when /github.*/
44
- opts = { owner: name, repo: name }.merge(opts)
52
+ opts = { token: nil }.merge(opts)
53
+ opts = case name.count('/')
54
+ when 1
55
+ { owner: name.split('/')[0], repo: name.split('/')[1] }.merge(opts)
56
+ else
57
+ { owner: name, repo: name }.merge(opts)
58
+ end
45
59
  when 'index'
46
60
  opts = { link: 'content' }.merge(opts)
47
61
  when 'npm'
48
62
  opts = { npm: name[/nodejs-(.*)/, 1] || name }.merge(opts)
49
63
  when 'pypi'
50
- opts = { npm: name[/python.*-(.*)/, 1] || name }.merge(opts)
64
+ opts = { pypi: name[/python.*-(.*)/, 1] || name }.merge(opts)
51
65
  end
52
66
  @opts = opts
53
67
  end
@@ -89,43 +103,47 @@ module Getv
89
103
 
90
104
  private
91
105
 
92
- def versions_using_docker # rubocop:disable Metrics/AbcSize
106
+ def get(url)
107
+ require 'rest-client'
108
+ RestClient::Request.execute(method: :get, url: url, proxy: opts[:proxy]).body
109
+ end
110
+
111
+ def versions_using_docker # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
93
112
  require 'docker_registry2'
94
113
  docker_opts = {}
95
- docker_opts[:http_options] = { proxy: ENV['DOCKER_PROXY'] } if ENV['DOCKER_PROXY']
96
- if ENV['DOCKER_USER'] && ENV['DOCKER_PASSWORD']
97
- docker_opts[:user] = ENV['DOCKER_USER']
98
- docker_opts[:password] = ENV['DOCKER_PASSWORD']
114
+ docker_opts[:http_options] = { proxy: opts[:proxy] } unless opts[:proxy].nil?
115
+ if opts[:user] && opts[:password]
116
+ docker_opts[:user] = opts[:user]
117
+ docker_opts[:password] = opts[:password]
99
118
  end
100
119
  docker = DockerRegistry2.connect(opts[:url], docker_opts)
101
120
  docker.tags("#{opts[:owner]}/#{opts[:repo]}")['tags']
121
+ rescue DockerRegistry2::NotFound
122
+ []
102
123
  end
103
124
 
104
125
  def versions_using_gem
105
126
  require 'json'
106
- require 'open-uri'
107
- require 'net/http'
108
- JSON.parse(Net::HTTP.get(URI("https://rubygems.org/api/v1/versions/#{opts[:gem]}.json"))).map do |v|
127
+ JSON.parse(get("https://rubygems.org/api/v1/versions/#{opts[:gem]}.json")).map do |v|
109
128
  v['number']
110
129
  end
111
130
  end
112
131
 
113
132
  def versions_using_get
114
- require 'open-uri'
115
- require 'net/http'
116
- Net::HTTP.get(URI(opts[:url])).split("\n")
133
+ get(opts[:url]).split("\n")
117
134
  end
118
135
 
119
- def github
136
+ def github # rubocop:disable Metrics/MethodLength
120
137
  require 'octokit'
121
- if ENV['GITHUB_TOKEN']
122
- github = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])
138
+ if opts[:token]
139
+ github = Octokit::Client.new(access_token: opts[:token])
123
140
  user = github.user
124
141
  user.login
125
142
  else
126
143
  github = Octokit::Client.new
127
144
  end
128
145
  github.auto_paginate = true
146
+ github.proxy = opts[:proxy]
129
147
  github
130
148
  end
131
149
 
@@ -143,11 +161,8 @@ module Getv
143
161
  end
144
162
 
145
163
  def versions_using_index
146
- require 'open-uri'
147
- require 'net/http'
148
164
  require 'nokogiri'
149
-
150
- Nokogiri::HTML(URI.open(opts[:url])).css('a').map do |a| # rubocop:disable Security/Open
165
+ Nokogiri::HTML(get(opts[:url])).css('a').map do |a|
151
166
  if opts[:link] == 'value'
152
167
  a.values[0]
153
168
  else
@@ -158,16 +173,12 @@ module Getv
158
173
 
159
174
  def versions_using_npm
160
175
  require 'json'
161
- require 'open-uri'
162
- require 'net/http'
163
- JSON.parse(Net::HTTP.get(URI("https://registry.npmjs.org/#{opts[:npm]}")))['versions'].keys
176
+ JSON.parse(get("https://registry.npmjs.org/#{opts[:npm]}"))['versions'].keys
164
177
  end
165
178
 
166
179
  def versions_using_pypi
167
180
  require 'json'
168
- require 'open-uri'
169
- require 'net/http'
170
- JSON.parse(Net::HTTP.get(URI("https://pypi.org/pypi/#{opts[:pypi]}/json")))['releases'].keys
181
+ JSON.parse(get("https://pypi.org/pypi/#{opts[:pypi]}/json"))['releases'].keys
171
182
  end
172
183
  end
173
184
  end
data/lib/getv/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Getv
4
- VERSION = '1.4.0'
4
+ VERSION = '1.6.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - harbottle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-27 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -90,6 +90,26 @@ dependencies:
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
92
  version: 5.0.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: rest-client
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 2.1.0
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: 3.0.0
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.1.0
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: 3.0.0
93
113
  - !ruby/object:Gem::Dependency
94
114
  name: semantic
95
115
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
166
  - !ruby/object:Gem::Version
147
167
  version: '0'
148
168
  requirements: []
149
- rubygems_version: 3.0.3
169
+ rubygems_version: 3.1.2
150
170
  signing_key:
151
171
  specification_version: 4
152
172
  summary: Pull package version numbers from the web in various ways.