getv 1.3.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/exe/getv +100 -121
  4. data/lib/getv/package.rb +30 -27
  5. data/lib/getv/version.rb +1 -1
  6. metadata +26 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3f1afae07aeb895e7cac0ef722a2a0c12008681ee09bfa724cdfc692accba75
4
- data.tar.gz: 67ea05289cee910c2c53db2fa337cc6a20bc2459d407bf5bf995d01b5cea41a5
3
+ metadata.gz: '089dcf7c1b77a594ef0d7362f8d64f9f1df0ac6a8642947c3448299bc21e6680'
4
+ data.tar.gz: f890fce6a6fe69416ddfee40cda03a1cf28ee4c70c88c04352712f8d9d373422
5
5
  SHA512:
6
- metadata.gz: e33576d51b5d6a32d39f54421e87d458542b3ce38a52f2e8b5182d4c38d54257b5e4a75469f96d15df8ab34c0546e03a153e7133138dd5d2dd9b63258d0eaa02
7
- data.tar.gz: da5ed58b41e029f1979147c6d3d614bdc9841f267fc56e37f9b4775b7f7c8dc1836141f57e477156876b03b2daa9ac518445364386f4e85802728e0981a7577e
6
+ metadata.gz: 4d282b8cf6471125466a80e024e47b4346d2a2be3dc80a7c0ff7e31e60fc25f0efbfc32d2068ed58dabb2f3da862ede4519217b83f2603eb78bedd7367bb4f51
7
+ data.tar.gz: 1dc7d16a64011dca99f288001ff787c99efe82ee4b096955fd5f44913b6a5c669817bceab5e001acf94bacdaea19db356f36ec9536232a19dd2d053c9ca3134f
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
@@ -7,26 +7,16 @@ require 'gli'
7
7
  module Getv
8
8
  # cli class
9
9
  class Cli
10
- def self.output(package, latest: false, json: false) # rubocop:disable Metrics/MethodLength
11
- if latest
12
- if json
13
- require 'json'
14
- puts({
15
- 'name' => package.name,
16
- 'latest_version' => package.latest_version
17
- }.to_json)
18
- else
19
- puts package.latest_version
20
- end
21
- elsif json
10
+ def self.output(package, latest: false, json: false)
11
+ key = latest ? 'latest_version' : 'versions'
12
+ result = package.send(key)
13
+
14
+ if json
22
15
  require 'json'
23
- puts({
24
- 'name' => package.name,
25
- 'versions' => package.versions
26
- }.to_json)
27
- else
28
- puts package.versions
16
+ result = { 'name' => package.name, key => result }.to_json
29
17
  end
18
+
19
+ puts result
30
20
  end
31
21
  end
32
22
  end
@@ -44,10 +34,11 @@ class App # rubocop:disable Metrics/ClassLength
44
34
 
45
35
  switch %i[l latest], desc: 'Latest version', negatable: false
46
36
  switch %i[j json], desc: 'Output in json', negatable: false
37
+ flag %i[p proxy], desc: 'Web proxy', default_value: nil
47
38
 
48
39
  desc 'Get package versions from a Docker or OCI container image registry'
49
40
  arg_name 'package_name'
50
- command :docker do |c| # rubocop:disable Metrics/BlockLength
41
+ command :docker do |c|
51
42
  defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
52
43
  c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
53
44
  c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
@@ -60,19 +51,19 @@ class App # rubocop:disable Metrics/ClassLength
60
51
  c.flag %i[repo], desc: 'Repository name',
61
52
  default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
62
53
  c.flag %i[url], desc: 'URL', default_value: defaults[:url]
54
+ c.flag %i[user], desc: 'Username', default_value: defaults[:user]
55
+ c.flag %i[password], desc: 'Password', default_value: defaults[:password]
63
56
  c.action do |global_options, options, args|
64
- if args.size == 1
65
- opts = global_options.merge(options)
66
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo,
67
- :url
68
- opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
69
- opts[:semantic_only] = !options[:invalid_versions]
70
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
71
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
72
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
73
- else
74
- help_now!
75
- end
57
+ help_now! unless args.size == 1
58
+
59
+ opts = global_options.merge(options)
60
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo,
61
+ :url, :user, :password, :proxy
62
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
63
+ opts[:semantic_only] = !options[:invalid_versions]
64
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
65
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
66
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
76
67
  end
77
68
  end
78
69
 
@@ -87,17 +78,15 @@ class App # rubocop:disable Metrics/ClassLength
87
78
  c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
88
79
  default_value: defaults[:semantic_select]
89
80
  c.action do |global_options, options, args|
90
- if args.size == 1
91
- opts = global_options.merge(options)
92
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
93
- opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
94
- opts[:semantic_only] = !options[:invalid_versions]
95
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
96
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
97
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
98
- else
99
- help_now!
100
- end
81
+ help_now! unless args.size == 1
82
+
83
+ opts = global_options.merge(options)
84
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :proxy
85
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
86
+ opts[:semantic_only] = !options[:invalid_versions]
87
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
88
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
89
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
101
90
  end
102
91
  end
103
92
 
@@ -113,21 +102,18 @@ class App # rubocop:disable Metrics/ClassLength
113
102
  default_value: defaults[:semantic_select]
114
103
  c.flag %i[url], desc: 'URL', default_value: defaults[:url]
115
104
  c.action do |global_options, options, args|
116
- if args.size == 1
117
- opts = global_options.merge(options)
118
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url
119
- opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
120
- opts[:semantic_only] = !options[:invalid_versions]
121
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
122
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
123
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
124
- else
125
- help_now!
126
- end
105
+ help_now! unless args.size == 1
106
+
107
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url, :proxy
108
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
109
+ opts[:semantic_only] = !options[:invalid_versions]
110
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
111
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
112
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
127
113
  end
128
114
  end
129
115
 
130
- desc 'Get package versions from GitHub commits. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
116
+ desc 'Get package versions from GitHub commits'
131
117
  arg_name 'package_name'
132
118
  command :github_commit do |c|
133
119
  defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
@@ -139,20 +125,19 @@ class App # rubocop:disable Metrics/ClassLength
139
125
  c.flag %i[repo], desc: 'Repository name',
140
126
  default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
141
127
  c.flag %i[branch], desc: 'Repository branch', default_value: defaults[:branch]
128
+ c.flag %i[token], desc: 'Token', default_value: defaults[:token]
142
129
  c.action do |global_options, options, args|
143
- if args.size == 1
144
- opts = global_options.merge(options)
145
- opts = opts.slice :select_search, :select_replace, :reject, :owner, :repo, :branch
146
- opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
147
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
148
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
149
- else
150
- help_now!
151
- end
130
+ help_now! unless args.size == 1
131
+
132
+ opts = global_options.merge(options)
133
+ opts = opts.slice :select_search, :select_replace, :reject, :owner, :repo, :branch, :token, :proxy
134
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
135
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
136
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
152
137
  end
153
138
  end
154
139
 
155
- desc 'Get package versions from GitHub releases. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
140
+ desc 'Get package versions from GitHub releases'
156
141
  arg_name 'package_name'
157
142
  command :github_release do |c|
158
143
  defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
@@ -166,22 +151,22 @@ class App # rubocop:disable Metrics/ClassLength
166
151
  default_value: "'<owner>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
167
152
  c.flag %i[repo], desc: 'Repository name',
168
153
  default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
154
+ c.flag %i[token], desc: 'Token', default_value: defaults[:token]
169
155
  c.action do |global_options, options, args|
170
- if args.size == 1
171
- opts = global_options.merge(options)
172
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo
173
- opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
174
- opts[:semantic_only] = !options[:invalid_versions]
175
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
176
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
177
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
178
- else
179
- help_now!
180
- end
156
+ help_now! unless args.size == 1
157
+
158
+ opts = global_options.merge(options)
159
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo,
160
+ :token, :proxy
161
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
162
+ opts[:semantic_only] = !options[:invalid_versions]
163
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
164
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
165
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
181
166
  end
182
167
  end
183
168
 
184
- desc 'Get package versions from GitHub tags. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
169
+ desc 'Get package versions from GitHub tags'
185
170
  arg_name 'package_name'
186
171
  command :github_tag do |c|
187
172
  defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
@@ -195,18 +180,18 @@ class App # rubocop:disable Metrics/ClassLength
195
180
  default_value: "'<owner>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
196
181
  c.flag %i[repo], desc: 'Repository name',
197
182
  default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
183
+ c.flag %i[token], desc: 'Token', default_value: defaults[:token]
198
184
  c.action do |global_options, options, args|
199
- if args.size == 1
200
- opts = global_options.merge(options)
201
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo
202
- opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
203
- opts[:semantic_only] = !options[:invalid_versions]
204
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
205
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
206
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
207
- else
208
- help_now!
209
- end
185
+ help_now! unless args.size == 1
186
+
187
+ opts = global_options.merge(options)
188
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo,
189
+ :token, :proxy
190
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
191
+ opts[:semantic_only] = !options[:invalid_versions]
192
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
193
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
194
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
210
195
  end
211
196
  end
212
197
 
@@ -224,18 +209,16 @@ class App # rubocop:disable Metrics/ClassLength
224
209
  c.switch %i[link_value], desc: 'Use the value (target) of links rather than the content (display text)',
225
210
  negatable: false, default_value: false
226
211
  c.action do |global_options, options, args|
227
- if args.size == 1
228
- opts = global_options.merge(options)
229
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url
230
- opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
231
- opts[:link] == 'value' if options[:link_value]
232
- opts[:semantic_only] = !options[:invalid_versions]
233
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
234
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
235
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
236
- else
237
- help_now!
238
- end
212
+ help_now! unless args.size == 1
213
+
214
+ opts = global_options.merge(options)
215
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url, :proxy
216
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
217
+ opts[:link] == 'value' if options[:link_value]
218
+ opts[:semantic_only] = !options[:invalid_versions]
219
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
220
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
221
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
239
222
  end
240
223
  end
241
224
 
@@ -250,17 +233,15 @@ class App # rubocop:disable Metrics/ClassLength
250
233
  c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
251
234
  default_value: defaults[:semantic_select]
252
235
  c.action do |global_options, options, args|
253
- if args.size == 1
254
- opts = global_options.merge(options)
255
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
256
- opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
257
- opts[:semantic_only] = !options[:invalid_versions]
258
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
259
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
260
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
261
- else
262
- help_now!
263
- end
236
+ help_now! unless args.size == 1
237
+
238
+ opts = global_options.merge(options)
239
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :proxy
240
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
241
+ opts[:semantic_only] = !options[:invalid_versions]
242
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
243
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
244
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
264
245
  end
265
246
  end
266
247
 
@@ -275,17 +256,15 @@ class App # rubocop:disable Metrics/ClassLength
275
256
  c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
276
257
  default_value: defaults[:semantic_select]
277
258
  c.action do |global_options, options, args|
278
- if args.size == 1
279
- opts = global_options.merge(options)
280
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
281
- opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
282
- opts[:semantic_only] = !options[:invalid_versions]
283
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
284
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
285
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
286
- else
287
- help_now!
288
- end
259
+ help_now! unless args.size == 1
260
+
261
+ opts = global_options.merge(options)
262
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :proxy
263
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
264
+ opts[:semantic_only] = !options[:invalid_versions]
265
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
266
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
267
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
289
268
  end
290
269
  end
291
270
 
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,6 +29,7 @@ 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)
@@ -37,17 +38,18 @@ module Getv
37
38
  end
38
39
  case opts[:type]
39
40
  when 'docker'
40
- opts = { owner: 'library', repo: name, url: 'https://registry.hub.docker.com' }.merge(opts)
41
+ opts = { owner: 'library', repo: name, url: 'https://registry.hub.docker.com', user: nil,
42
+ password: nil }.merge(opts)
41
43
  when 'gem'
42
44
  opts = { gem: name[/rubygem-(.*)/, 1] || name }.merge(opts)
43
45
  when /github.*/
44
- opts = { owner: name, repo: name }.merge(opts)
46
+ opts = { owner: name, repo: name, token: nil }.merge(opts)
45
47
  when 'index'
46
48
  opts = { link: 'content' }.merge(opts)
47
49
  when 'npm'
48
50
  opts = { npm: name[/nodejs-(.*)/, 1] || name }.merge(opts)
49
51
  when 'pypi'
50
- opts = { npm: name[/python.*-(.*)/, 1] || name }.merge(opts)
52
+ opts = { pypi: name[/python.*-(.*)/, 1] || name }.merge(opts)
51
53
  end
52
54
  @opts = opts
53
55
  end
@@ -89,37 +91,45 @@ module Getv
89
91
 
90
92
  private
91
93
 
92
- def versions_using_docker
94
+ def get(url)
95
+ require 'rest-client'
96
+ RestClient::Request.execute(method: :get, url: url, proxy: opts[:proxy]).body
97
+ end
98
+
99
+ def versions_using_docker # rubocop:disable Metrics/AbcSize
93
100
  require 'docker_registry2'
94
- docker = DockerRegistry2.connect(opts[:url])
101
+ docker_opts = {}
102
+ docker_opts[:http_options] = { proxy: opts[:proxy] } unless opts[:proxy].nil?
103
+ if opts[:user] && opts[:password]
104
+ docker_opts[:user] = opts[:user]
105
+ docker_opts[:password] = opts[:password]
106
+ end
107
+ docker = DockerRegistry2.connect(opts[:url], docker_opts)
95
108
  docker.tags("#{opts[:owner]}/#{opts[:repo]}")['tags']
96
109
  end
97
110
 
98
111
  def versions_using_gem
99
112
  require 'json'
100
- require 'open-uri'
101
- require 'net/http'
102
- JSON.parse(Net::HTTP.get(URI("https://rubygems.org/api/v1/versions/#{opts[:gem]}.json"))).map do |v|
113
+ JSON.parse(get("https://rubygems.org/api/v1/versions/#{opts[:gem]}.json")).map do |v|
103
114
  v['number']
104
115
  end
105
116
  end
106
117
 
107
118
  def versions_using_get
108
- require 'open-uri'
109
- require 'net/http'
110
- Net::HTTP.get(URI(opts[:url])).split("\n")
119
+ get(opts[:url]).split("\n")
111
120
  end
112
121
 
113
- def github
122
+ def github # rubocop:disable Metrics/MethodLength
114
123
  require 'octokit'
115
- if ENV['GITHUB_TOKEN']
116
- github = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])
124
+ if opts[:token]
125
+ github = Octokit::Client.new(access_token: opts[:token])
117
126
  user = github.user
118
127
  user.login
119
128
  else
120
129
  github = Octokit::Client.new
121
130
  end
122
131
  github.auto_paginate = true
132
+ github.proxy = opts[:proxy]
123
133
  github
124
134
  end
125
135
 
@@ -137,11 +147,8 @@ module Getv
137
147
  end
138
148
 
139
149
  def versions_using_index
140
- require 'open-uri'
141
- require 'net/http'
142
150
  require 'nokogiri'
143
-
144
- Nokogiri::HTML(URI.open(opts[:url])).css('a').map do |a| # rubocop:disable Security/Open
151
+ Nokogiri::HTML(get(opts[:url])).css('a').map do |a|
145
152
  if opts[:link] == 'value'
146
153
  a.values[0]
147
154
  else
@@ -152,16 +159,12 @@ module Getv
152
159
 
153
160
  def versions_using_npm
154
161
  require 'json'
155
- require 'open-uri'
156
- require 'net/http'
157
- JSON.parse(Net::HTTP.get(URI("https://registry.npmjs.org/#{opts[:npm]}")))['versions'].keys
162
+ JSON.parse(get("https://registry.npmjs.org/#{opts[:npm]}"))['versions'].keys
158
163
  end
159
164
 
160
165
  def versions_using_pypi
161
166
  require 'json'
162
- require 'open-uri'
163
- require 'net/http'
164
- JSON.parse(Net::HTTP.get(URI("https://pypi.org/pypi/#{opts[:pypi]}/json")))['releases'].keys
167
+ JSON.parse(get("https://pypi.org/pypi/#{opts[:pypi]}/json"))['releases'].keys
165
168
  end
166
169
  end
167
170
  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.3.0'
4
+ VERSION = '1.5.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.3.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - harbottle
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-26 00:00:00.000000000 Z
11
+ date: 2022-01-30 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
@@ -131,7 +151,7 @@ metadata:
131
151
  homepage_uri: https://github.com/liger1978/getv
132
152
  source_code_uri: https://github.com/liger1978/getv
133
153
  changelog_uri: https://github.com/liger1978/getv
134
- post_install_message:
154
+ post_install_message:
135
155
  rdoc_options: []
136
156
  require_paths:
137
157
  - lib
@@ -146,8 +166,8 @@ 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
150
- signing_key:
169
+ rubygems_version: 3.2.22
170
+ signing_key:
151
171
  specification_version: 4
152
172
  summary: Pull package version numbers from the web in various ways.
153
173
  test_files: []