getv 1.3.1 → 1.6.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: 76b665201a4d7f1ecdaa9047121a3b4fece0805d5de821b9acf636cc9f82a506
4
- data.tar.gz: 620003975f2b25a1d6df14edfda536e7710cfbcbd6ab4f329c710c4ee820a281
3
+ metadata.gz: 98a04bab50075d670df75705579e743dcfa11f8348333ff05071294355303860
4
+ data.tar.gz: e55cc07d8d7167176f3557a1eecf8f99f9c6f6908922fbf4901d97dd10951d70
5
5
  SHA512:
6
- metadata.gz: 61f05289eca59aab2435330d79d849876cf2e3d160d214899a4644c11cba109a4337a5b9bac8c905a54e020b06362201befe63302a5d513efe4f07e82c2fc6fb
7
- data.tar.gz: 56c9e45f319a0bd94bd27b15053f782731b0f08d6b94c55fbfc8d449b80a3fb8deb96af6fd7e51403305b4875f0231986bb114834b069e243027df56a4f671aa
6
+ metadata.gz: 5b93e911ecd136a22555e97fcd0c62986a862adc4809b37a5c1cd1d047a8bdfd1f663fb7159548b2d4bb3f9558fcd9643831e4b91791b696a90313aa81af8388
7
+ data.tar.gz: 0a3a86b63ff5250f3b07bd419d5ecbafca05fe0f63384e12178675411d9ab0fb25f4c56a614d39cb34058d967b09b4b6414ef277a05e565930cc36e7f0bc440a
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
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,37 +103,45 @@ module Getv
89
103
 
90
104
  private
91
105
 
92
- def versions_using_docker
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
93
112
  require 'docker_registry2'
94
- docker = DockerRegistry2.connect(opts[:url])
113
+ docker_opts = {}
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]
118
+ end
119
+ docker = DockerRegistry2.connect(opts[:url], docker_opts)
95
120
  docker.tags("#{opts[:owner]}/#{opts[:repo]}")['tags']
96
121
  end
97
122
 
98
123
  def versions_using_gem
99
124
  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|
125
+ JSON.parse(get("https://rubygems.org/api/v1/versions/#{opts[:gem]}.json")).map do |v|
103
126
  v['number']
104
127
  end
105
128
  end
106
129
 
107
130
  def versions_using_get
108
- require 'open-uri'
109
- require 'net/http'
110
- Net::HTTP.get(URI(opts[:url])).split("\n")
131
+ get(opts[:url]).split("\n")
111
132
  end
112
133
 
113
- def github
134
+ def github # rubocop:disable Metrics/MethodLength
114
135
  require 'octokit'
115
- if ENV['GITHUB_TOKEN']
116
- github = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])
136
+ if opts[:token]
137
+ github = Octokit::Client.new(access_token: opts[:token])
117
138
  user = github.user
118
139
  user.login
119
140
  else
120
141
  github = Octokit::Client.new
121
142
  end
122
143
  github.auto_paginate = true
144
+ github.proxy = opts[:proxy]
123
145
  github
124
146
  end
125
147
 
@@ -137,11 +159,8 @@ module Getv
137
159
  end
138
160
 
139
161
  def versions_using_index
140
- require 'open-uri'
141
- require 'net/http'
142
162
  require 'nokogiri'
143
-
144
- Nokogiri::HTML(URI.open(opts[:url])).css('a').map do |a| # rubocop:disable Security/Open
163
+ Nokogiri::HTML(get(opts[:url])).css('a').map do |a|
145
164
  if opts[:link] == 'value'
146
165
  a.values[0]
147
166
  else
@@ -152,16 +171,12 @@ module Getv
152
171
 
153
172
  def versions_using_npm
154
173
  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
174
+ JSON.parse(get("https://registry.npmjs.org/#{opts[:npm]}"))['versions'].keys
158
175
  end
159
176
 
160
177
  def versions_using_pypi
161
178
  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
179
+ JSON.parse(get("https://pypi.org/pypi/#{opts[:pypi]}/json"))['releases'].keys
165
180
  end
166
181
  end
167
182
  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.1'
4
+ VERSION = '1.6.0'
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.1
4
+ version: 1.6.0
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-27 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: []