getv 1.2.0 → 1.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: daac0f934a1cdcea8875d71dc0a2579df0cfc79a11c81adf11249aa0a3fc14c8
4
- data.tar.gz: 6af122cebd5cb12cbd1c11bc615c5e2eb9aaec166ac5d7b7b55c456d496e1e4f
3
+ metadata.gz: 03d655407021c76e4df2c9ece13fb42e6447f597f9492d240901e49442144e43
4
+ data.tar.gz: 6f48191ff06387bfea424457ee41fd5f514cda257c1341ecba87eb82c7237279
5
5
  SHA512:
6
- metadata.gz: 77e6a4c99d59ecf7f6bfaf9a10e37854ea90d80cc41115a581c84398f52d9c1048059a66482860add6ecc4f80d593ddab9481a2cc313b61fbef7bc2b417e2ce6
7
- data.tar.gz: 1c578d98f20fa6d690b2b4db46f2cb5b21af39ece384a4ec08d57c7f2a12c6aa3a8ac1ea07d74115ab37c7b711eb74c4b02a3113d6722a958f6b4959b7e8bdc4
6
+ metadata.gz: 56d72bdde2f6f8aceb8d0844e30fda53e428efebe748ea8bb98848943f5bad319ff566f2d8d6fde7b71812dbf40bb13b29094d00f6296fb6d88e7910e37b7bd5
7
+ data.tar.gz: ecd3ee651658cf63c659a4195dc5f0e7e5d113d963d82f68f1ead2f9ad74cdb76c75f65f6b7c3578da40e96bae39fc296f6db9b6953650044d4ea8b15d86c719
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # getv
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/getv.svg)](https://rubygems.org/gems/getv)
4
+
3
5
  The goal of `getv` is to make it easy and quick to pull software package version numbers from various sources on the web. The application is packaged as a [gem](https://rubygems.org/gems/getv) and provides both a Ruby library and an executable command line tool, `getv`.
4
6
 
5
7
  ## Installation
@@ -37,18 +39,15 @@ SYNOPSIS
37
39
 
38
40
 
39
41
  VERSION
40
- 1.1.0
42
+ 1.3.0
41
43
 
42
44
 
43
45
 
44
46
  GLOBAL OPTIONS
45
- --help - Show this message
46
- -j, --json - Output in json
47
- -l, --latest - Latest version
48
- --reject=arg - Regex version rejection (default: none)
49
- --select_replace=arg - Regex version selection replace (default: none)
50
- --select_search=arg - Regex version selection search (default: none)
51
- --version - Display the program version
47
+ --help - Show this message
48
+ -j, --json - Output in json
49
+ -l, --latest - Latest version
50
+ --version - Display the program version
52
51
 
53
52
 
54
53
 
@@ -56,9 +55,9 @@ COMMANDS
56
55
  docker - Get package versions from a Docker or OCI container image registry
57
56
  gem - Get package versions from RubyGems.org
58
57
  get - Get package versions from text file URL
59
- github_commit - Get package versions from GitHub commits
60
- github_release - Get package versions from GitHub releases
61
- github_tag - Get package versions from GitHub tags
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.
62
61
  help - Shows a list of commands or help for one command
63
62
  index - Get package versions from web page of links
64
63
  npm - Get package versions from npm at registry.npmjs.org
@@ -71,7 +70,7 @@ Show the latest available version of the `getv` gem:
71
70
 
72
71
  ```console
73
72
  $ getv --latest gem getv
74
- 1.1.0
73
+ 1.3.0
75
74
  ```
76
75
 
77
76
  Show all `dep` GitHub release versions in JSON:
@@ -84,7 +83,7 @@ $ getv --json github_release golang/dep
84
83
  Show all AtomicParsley Github release versions:
85
84
 
86
85
  ```console
87
- $ getv --select_search='(.*)' github_release --invalid_versions wez/atomicparsley
86
+ $ getv github_release --invalid_versions wez/atomicparsley
88
87
  20200701.154658.b0d6223
89
88
  20201231.092811.cbecfb1
90
89
  20210114.184825.1dbe1be
@@ -103,7 +102,7 @@ $ getv -l get --url=https://storage.googleapis.com/kubernetes-release/release/st
103
102
  Show selected semantic versions of the `apache/superset` Docker image in JSON:
104
103
 
105
104
  ```console
106
- $ getv --json --reject '-' docker --semantic_select '~>1.3.0,!=1.3.1' apache/superset
105
+ $ getv --json docker --reject '-' --semantic_select '~>1.3.0,!=1.3.1' apache/superset
107
106
  {"name":"apache/superset","versions":["1.3.0","1.3.2"]}
108
107
  ```
109
108
 
@@ -121,7 +120,7 @@ Show the latest GitHub commit to the `main` branch of the `getv` project in a us
121
120
 
122
121
  ```console
123
122
  # By default the \2 capture group contains the date and \5 contains the short commit hash
124
- $ getv -l --select_replace '\2git\5' github_commit --branch main liger1978/getv
123
+ $ getv -l github_commit --select_replace '\2git\5' --branch main liger1978/getv
125
124
  20220123git9ed86f0
126
125
  ```
127
126
 
@@ -141,6 +140,14 @@ puts superset.latest_version
141
140
 
142
141
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. Run `bundle exec rubocop` to run the linter. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
143
142
 
143
+ Note that by default, Bundler will attempt to install gems to the system, e.g. `/usr/bin`, `/usr/share`, which requires elevated access and can interfere with files that are managed by the system's package manager. This behaviour can be overridden by creating the file `.bundle/config` and adding the following line:
144
+ ```
145
+ BUNDLE_PATH: "./.bundle"
146
+ ```
147
+ When you run `bin/setup` or `bundle install`, all gems will be installed inside the .bundle directory of this project.
148
+
149
+ To make this behaviour a default for all gem projects, the above line can be added to the user's bundle config file in their home directory (`~/.bundle/config`)
150
+
144
151
  ## Contributing
145
152
 
146
153
  Bug reports and pull requests are welcome on [GitHub](https://github.com/liger1978/getv).
data/exe/getv ADDED
@@ -0,0 +1,285 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'getv'
5
+ require 'gli'
6
+
7
+ module Getv
8
+ # cli class
9
+ class Cli
10
+ def self.output(package, latest: false, json: false)
11
+ key = latest ? 'latest_version' : 'versions'
12
+ result = package.send(key)
13
+
14
+ if json
15
+ require 'json'
16
+ result = { 'name' => package.name, key => result }.to_json
17
+ end
18
+
19
+ puts result
20
+ end
21
+ end
22
+ end
23
+
24
+ # app class
25
+ class App # rubocop:disable Metrics/ClassLength
26
+ extend GLI::App
27
+
28
+ program_desc 'Get package version numbers from the web in various ways'
29
+
30
+ version Getv::VERSION
31
+
32
+ subcommand_option_handling :normal
33
+ arguments :strict
34
+
35
+ switch %i[l latest], desc: 'Latest version', negatable: false
36
+ switch %i[j json], desc: 'Output in json', negatable: false
37
+
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
+ arg_name 'package_name'
40
+ command :docker do |c|
41
+ defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
42
+ c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
43
+ c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
44
+ c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
45
+ c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
46
+ c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
47
+ default_value: defaults[:semantic_select]
48
+ 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
+ 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]
53
+ c.action do |global_options, options, args|
54
+ help_now! unless args.size == 1
55
+
56
+ opts = global_options.merge(options)
57
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo,
58
+ :url
59
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
60
+ opts[:semantic_only] = !options[:invalid_versions]
61
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
62
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
63
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
64
+ end
65
+ end
66
+
67
+ desc 'Get package versions from RubyGems.org'
68
+ arg_name 'package_name'
69
+ command :gem do |c|
70
+ defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
71
+ c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
72
+ c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
73
+ c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
74
+ c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
75
+ c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
76
+ default_value: defaults[:semantic_select]
77
+ c.action do |global_options, options, args|
78
+ help_now! unless args.size == 1
79
+
80
+ opts = global_options.merge(options)
81
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
82
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
83
+ opts[:semantic_only] = !options[:invalid_versions]
84
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
85
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
86
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
87
+ end
88
+ end
89
+
90
+ desc 'Get package versions from text file URL'
91
+ arg_name 'package_name'
92
+ command :get do |c|
93
+ defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
94
+ c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
95
+ c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
96
+ c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
97
+ c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
98
+ c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
99
+ default_value: defaults[:semantic_select]
100
+ c.flag %i[url], desc: 'URL', default_value: defaults[:url]
101
+ c.action do |global_options, options, args|
102
+ help_now! unless args.size == 1
103
+
104
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url
105
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
106
+ opts[:semantic_only] = !options[:invalid_versions]
107
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
108
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
109
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
110
+ end
111
+ end
112
+
113
+ desc 'Get package versions from GitHub commits. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
114
+ arg_name 'package_name'
115
+ command :github_commit do |c|
116
+ defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
117
+ c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
118
+ c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
119
+ c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
120
+ c.flag %i[owner], desc: 'Repository owner',
121
+ default_value: "'<owner>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
122
+ c.flag %i[repo], desc: 'Repository name',
123
+ default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
124
+ c.flag %i[branch], desc: 'Repository branch', default_value: defaults[:branch]
125
+ c.action do |global_options, options, args|
126
+ help_now! unless args.size == 1
127
+
128
+ opts = global_options.merge(options)
129
+ opts = opts.slice :select_search, :select_replace, :reject, :owner, :repo, :branch
130
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
131
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
132
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
133
+ end
134
+ end
135
+
136
+ desc 'Get package versions from GitHub releases. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
137
+ arg_name 'package_name'
138
+ command :github_release do |c|
139
+ defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
140
+ c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
141
+ c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
142
+ c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
143
+ c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
144
+ c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
145
+ default_value: defaults[:semantic_select]
146
+ c.flag %i[owner], desc: 'Repository owner',
147
+ default_value: "'<owner>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
148
+ c.flag %i[repo], desc: 'Repository name',
149
+ default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
150
+ c.action do |global_options, options, args|
151
+ help_now! unless args.size == 1
152
+
153
+ opts = global_options.merge(options)
154
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo
155
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
156
+ opts[:semantic_only] = !options[:invalid_versions]
157
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
158
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
159
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
160
+ end
161
+ end
162
+
163
+ desc 'Get package versions from GitHub tags. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
164
+ arg_name 'package_name'
165
+ command :github_tag do |c|
166
+ defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
167
+ c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
168
+ c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
169
+ c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
170
+ c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
171
+ c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
172
+ default_value: defaults[:semantic_select]
173
+ c.flag %i[owner], desc: 'Repository owner',
174
+ default_value: "'<owner>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
175
+ c.flag %i[repo], desc: 'Repository name',
176
+ default_value: "'<repo>' if package_name is in format '<owner>/<repo>', otherwise just package_name" # rubocop:disable Layout/LineLength
177
+ c.action do |global_options, options, args|
178
+ help_now! unless args.size == 1
179
+
180
+ opts = global_options.merge(options)
181
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo
182
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
183
+ opts[:semantic_only] = !options[:invalid_versions]
184
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
185
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
186
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
187
+ end
188
+ end
189
+
190
+ desc 'Get package versions from web page of links'
191
+ arg_name 'package_name'
192
+ command :index do |c|
193
+ defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
194
+ c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
195
+ c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
196
+ c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
197
+ c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
198
+ c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
199
+ default_value: defaults[:semantic_select]
200
+ c.flag %i[url], desc: 'URL', default_value: defaults[:url]
201
+ c.switch %i[link_value], desc: 'Use the value (target) of links rather than the content (display text)',
202
+ negatable: false, default_value: false
203
+ c.action do |global_options, options, args|
204
+ help_now! unless args.size == 1
205
+
206
+ opts = global_options.merge(options)
207
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url
208
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
209
+ opts[:link] == 'value' if options[:link_value]
210
+ opts[:semantic_only] = !options[:invalid_versions]
211
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
212
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
213
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
214
+ end
215
+ end
216
+
217
+ desc 'Get package versions from npm at registry.npmjs.org'
218
+ arg_name 'package_name'
219
+ command :npm do |c|
220
+ defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
221
+ c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
222
+ c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
223
+ c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
224
+ c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
225
+ c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
226
+ default_value: defaults[:semantic_select]
227
+ c.action do |global_options, options, args|
228
+ help_now! unless args.size == 1
229
+
230
+ opts = global_options.merge(options)
231
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
232
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
233
+ opts[:semantic_only] = !options[:invalid_versions]
234
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
235
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
236
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
237
+ end
238
+ end
239
+
240
+ desc 'Get package versions from the Python Package Index at pypi.org'
241
+ arg_name 'package_name'
242
+ command :pypi do |c|
243
+ defaults = (Getv::Package.new 'name', type: c.name.to_s).opts
244
+ c.flag %i[select_search], desc: 'Regex version selection search', default_value: defaults[:select_search]
245
+ c.flag %i[select_replace], desc: 'Regex version selection replace', default_value: defaults[:select_replace]
246
+ c.flag %i[reject], desc: 'Regex version rejection', default_value: defaults[:reject]
247
+ c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
248
+ c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)',
249
+ default_value: defaults[:semantic_select]
250
+ c.action do |global_options, options, args|
251
+ help_now! unless args.size == 1
252
+
253
+ opts = global_options.merge(options)
254
+ opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
255
+ opts = opts.delete_if { |k, v| v.nil? || v == c.flags[k].default_value }
256
+ opts[:semantic_only] = !options[:invalid_versions]
257
+ opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
258
+ package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
259
+ Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
260
+ end
261
+ end
262
+
263
+ pre do |_global, _command, _options, _args|
264
+ # Pre logic here
265
+ # Return true to proceed; false to abort and not call the
266
+ # chosen command
267
+ # Use skips_pre before a command to skip this block
268
+ # on that command only
269
+ true
270
+ end
271
+
272
+ post do |global, command, options, args|
273
+ # Post logic here
274
+ # Use skips_post before a command to skip this
275
+ # block on that command only
276
+ end
277
+
278
+ on_error do |_exception|
279
+ # Error logic here
280
+ # return false to skip default error handling
281
+ true
282
+ end
283
+ end
284
+
285
+ exit App.run(ARGV)
data/lib/getv/package.rb CHANGED
@@ -24,7 +24,7 @@ module Getv
24
24
  end
25
25
  opts = {
26
26
  type: 'github_release',
27
- select_search: '^\s*v?((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)\s*$', # rubocop:disable Layout/LineLength
27
+ select_search: '^\s*v?(.*)\s*$',
28
28
  select_replace: '\1',
29
29
  reject: nil,
30
30
  semantic_only: true,
@@ -89,9 +89,15 @@ module Getv
89
89
 
90
90
  private
91
91
 
92
- def versions_using_docker
92
+ def versions_using_docker # rubocop:disable Metrics/AbcSize
93
93
  require 'docker_registry2'
94
- docker = DockerRegistry2.connect(opts[:url])
94
+ 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']
99
+ end
100
+ docker = DockerRegistry2.connect(opts[:url], docker_opts)
95
101
  docker.tags("#{opts[:owner]}/#{opts[:repo]}")['tags']
96
102
  end
97
103
 
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.2.0'
4
+ VERSION = '1.4.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.2.0
4
+ version: 1.4.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-23 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -113,24 +113,14 @@ dependencies:
113
113
  description: Pull package version numbers from the web in various ways.
114
114
  email:
115
115
  - harbottle@room3d3.com
116
- executables: []
116
+ executables:
117
+ - getv
117
118
  extensions: []
118
119
  extra_rdoc_files: []
119
120
  files:
120
- - ".bundle/config"
121
- - ".github/workflows/ruby.yml"
122
- - ".gitignore"
123
- - ".rspec"
124
- - ".rubocop.yml"
125
- - ".travis.yml"
126
- - Gemfile
127
121
  - LICENSE.txt
128
122
  - README.md
129
- - Rakefile
130
- - bin/console
131
- - bin/getv
132
- - bin/setup
133
- - getv.gemspec
123
+ - exe/getv
134
124
  - lib/getv.rb
135
125
  - lib/getv/package.rb
136
126
  - lib/getv/version.rb
@@ -141,7 +131,7 @@ metadata:
141
131
  homepage_uri: https://github.com/liger1978/getv
142
132
  source_code_uri: https://github.com/liger1978/getv
143
133
  changelog_uri: https://github.com/liger1978/getv
144
- post_install_message:
134
+ post_install_message:
145
135
  rdoc_options: []
146
136
  require_paths:
147
137
  - lib
@@ -156,8 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
146
  - !ruby/object:Gem::Version
157
147
  version: '0'
158
148
  requirements: []
159
- rubygems_version: 3.2.22
160
- signing_key:
149
+ rubygems_version: 3.0.3
150
+ signing_key:
161
151
  specification_version: 4
162
152
  summary: Pull package version numbers from the web in various ways.
163
153
  test_files: []
data/.bundle/config DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- BUNDLE_BIN: "bin"
3
- BUNDLE_DISABLE_SHARED_GEMS: "true"
4
- BUNDLE_PATH: "./bundle"
@@ -1,37 +0,0 @@
1
- # This workflow uses actions that are not certified by GitHub.
2
- # They are provided by a third-party and are governed by
3
- # separate terms of service, privacy policy, and support
4
- # documentation.
5
- # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
- # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
-
8
- name: Ruby
9
-
10
- on:
11
- push:
12
- branches: [ main ]
13
- pull_request:
14
- branches: [ main ]
15
-
16
- jobs:
17
- test:
18
-
19
- runs-on: ubuntu-latest
20
- strategy:
21
- matrix:
22
- ruby-version: ['2.6', '2.7', '3.0']
23
-
24
- steps:
25
- - uses: actions/checkout@v2
26
- - name: Set up Ruby
27
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
- # uses: ruby/setup-ruby@v1
30
- uses: ruby/setup-ruby@v1
31
- with:
32
- ruby-version: ${{ matrix.ruby-version }}
33
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
- - name: Run linter
35
- run: bundle exec rake rubocop
36
- - name: Run unit tests
37
- run: bundle exec rake
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- /bin/*
2
- !/bin/console
3
- !/bin/getv
4
- !/bin/setup
5
- /bundle/
6
- /.yardoc
7
- /_yardoc/
8
- /coverage/
9
- /doc/
10
- /pkg/
11
- /spec/reports/
12
- /tmp/
13
- /*.gem
14
- /vendor
15
- Gemfile.lock
16
-
17
- # rspec failure tracking
18
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,16 +0,0 @@
1
- ---
2
- require:
3
- - rubocop-rspec
4
- AllCops:
5
- Exclude:
6
- - !ruby/regexp /\/bin\/\b(?!getv\b)\w+/
7
- - 'bundle/**/*'
8
- - 'vendor/**/*'
9
- - '*.gemspec'
10
- NewCops: enable
11
-
12
- Metrics/BlockLength:
13
- Exclude:
14
- - 'Rakefile'
15
- - '**/*.rake'
16
- - 'spec/**/*_spec.rb'
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.6.6
6
- before_install: gem install bundler -v 2.1.4
data/Gemfile DELETED
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in getv.gemspec
6
- gemspec
7
-
8
- gem 'docker_registry2', '~> 1.10'
9
- gem 'gli', '~> 2.20'
10
- gem 'irb', '~> 1.4'
11
- gem 'nokogiri', '~> 1.13'
12
- gem 'octokit', '~> 4.21'
13
- gem 'rake', '~> 12.0'
14
- gem 'rdoc', '~> 6.4'
15
- gem 'rspec', '~> 3.0'
16
- gem 'rubocop', '~> 1.24', require: false
17
- gem 'rubocop-rake', '~> 0.6', require: false
18
- gem 'rubocop-rspec', '~> 2.7', require: false
19
- gem 'semantic', '~> 1.6'
20
- gem 'vcr', '~> 6.0'
21
- gem 'webmock', '~> 3.0'
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
- require 'rubocop/rake_task'
6
-
7
- RSpec::Core::RakeTask.new(:spec)
8
-
9
- RuboCop::RakeTask.new do |task|
10
- task.requires << 'rubocop-rspec'
11
- end
12
-
13
- task default: :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "getv"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/getv DELETED
@@ -1,265 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'getv'
5
- require 'gli'
6
-
7
- module Getv
8
- # cli class
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
22
- require 'json'
23
- puts({
24
- 'name' => package.name,
25
- 'versions' => package.versions
26
- }.to_json)
27
- else
28
- puts package.versions
29
- end
30
- end
31
- end
32
- end
33
-
34
- # app class
35
- class App # rubocop:disable Metrics/ClassLength
36
- extend GLI::App
37
-
38
- program_desc 'Get package version numbers from the web in various ways'
39
-
40
- version Getv::VERSION
41
-
42
- subcommand_option_handling :normal
43
- arguments :strict
44
-
45
- switch %i[l latest], desc: 'Latest version', negatable: false
46
- switch %i[j json], desc: 'Output in json', negatable: false
47
- flag %i[select_search], desc: 'Regex version selection search'
48
- flag %i[select_replace], desc: 'Regex version selection replace'
49
- flag %i[reject], desc: 'Regex version rejection'
50
-
51
- desc 'Get package versions from a Docker or OCI container image registry'
52
- arg_name 'package_name'
53
- command :docker do |c|
54
- c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
55
- c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)'
56
- c.flag %i[owner], desc: 'Repository owner'
57
- c.flag %i[repo], desc: 'Repository name'
58
- c.flag %i[url], desc: 'URL'
59
- c.action do |global_options, options, args|
60
- if args.size == 1
61
- opts = global_options.merge(options)
62
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo,
63
- :url
64
- opts = opts.delete_if { |_k, v| v.nil? }
65
- opts[:semantic_only] = !options[:invalid_versions]
66
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
67
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
68
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
69
- else
70
- help_now!
71
- end
72
- end
73
- end
74
-
75
- desc 'Get package versions from RubyGems.org'
76
- arg_name 'package_name'
77
- command :gem do |c|
78
- c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
79
- c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)'
80
- c.action do |global_options, options, args|
81
- if args.size == 1
82
- opts = global_options.merge(options)
83
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
84
- opts = opts.delete_if { |_k, v| v.nil? }
85
- opts[:semantic_only] = !options[:invalid_versions]
86
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
87
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
88
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
89
- else
90
- help_now!
91
- end
92
- end
93
- end
94
-
95
- desc 'Get package versions from text file URL'
96
- arg_name 'package_name'
97
- command :get do |c|
98
- c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
99
- c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)'
100
- c.flag %i[url], desc: 'URL'
101
- c.action do |global_options, options, args|
102
- if args.size == 1
103
- opts = global_options.merge(options)
104
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url
105
- opts = opts.delete_if { |_k, v| v.nil? }
106
- opts[:semantic_only] = !options[:invalid_versions]
107
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
108
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
109
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
110
- else
111
- help_now!
112
- end
113
- end
114
- end
115
-
116
- desc 'Get package versions from GitHub commits. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
117
- arg_name 'package_name'
118
- command :github_commit do |c|
119
- c.flag %i[owner], desc: 'Repository owner'
120
- c.flag %i[repo], desc: 'Repository name'
121
- c.flag %i[branch], desc: 'Repository branch'
122
- c.action do |global_options, options, args|
123
- if args.size == 1
124
- opts = global_options.merge(options)
125
- opts = opts.slice :select_search, :select_replace, :reject, :owner, :repo, :branch
126
- opts = opts.delete_if { |_k, v| v.nil? }
127
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
128
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
129
- else
130
- help_now!
131
- end
132
- end
133
- end
134
-
135
- desc 'Get package versions from GitHub releases. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
136
- arg_name 'package_name'
137
- command :github_release do |c|
138
- c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
139
- c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)'
140
- c.flag %i[owner], desc: 'Repository owner'
141
- c.flag %i[repo], desc: 'Repository name'
142
- 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, :semantic_only, :semantic_select, :owner, :repo
146
- opts = opts.delete_if { |_k, v| v.nil? }
147
- opts[:semantic_only] = !options[:invalid_versions]
148
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
149
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
150
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
151
- else
152
- help_now!
153
- end
154
- end
155
- end
156
-
157
- desc 'Get package versions from GitHub tags. Set environment variable $GITHUB_TOKEN to avoid GitHub API limit.'
158
- arg_name 'package_name'
159
- command :github_tag do |c|
160
- c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
161
- c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)'
162
- c.flag %i[owner], desc: 'Repository owner'
163
- c.flag %i[repo], desc: 'Repository name'
164
- c.action do |global_options, options, args|
165
- if args.size == 1
166
- opts = global_options.merge(options)
167
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :owner, :repo
168
- opts = opts.delete_if { |_k, v| v.nil? }
169
- opts[:semantic_only] = !options[:invalid_versions]
170
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
171
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
172
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
173
- else
174
- help_now!
175
- end
176
- end
177
- end
178
-
179
- desc 'Get package versions from web page of links'
180
- arg_name 'package_name'
181
- command :index do |c|
182
- c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
183
- c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)'
184
- c.flag %i[url], desc: 'URL'
185
- c.switch %i[link_value], desc: 'Use the value (target) of links rather than the content (display text)',
186
- negatable: false, default_value: false
187
- c.action do |global_options, options, args|
188
- if args.size == 1
189
- opts = global_options.merge(options)
190
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select, :url
191
- opts = opts.delete_if { |_k, v| v.nil? }
192
- opts[:link] == 'value' if options[:link_value]
193
- opts[:semantic_only] = !options[:invalid_versions]
194
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
195
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
196
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
197
- else
198
- help_now!
199
- end
200
- end
201
- end
202
-
203
- desc 'Get package versions from npm at registry.npmjs.org'
204
- arg_name 'package_name'
205
- command :npm do |c|
206
- c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
207
- c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)'
208
- c.action do |global_options, options, args|
209
- if args.size == 1
210
- opts = global_options.merge(options)
211
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
212
- opts = opts.delete_if { |_k, v| v.nil? }
213
- opts[:semantic_only] = !options[:invalid_versions]
214
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
215
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
216
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
217
- else
218
- help_now!
219
- end
220
- end
221
- end
222
-
223
- desc 'Get package versions from the Python Package Index at pypi.org'
224
- arg_name 'package_name'
225
- command :pypi do |c|
226
- c.switch %i[invalid_versions], desc: 'Include invalid semantic versions', negatable: false, default_value: false
227
- c.flag %i[semantic_select], desc: 'Semantic version selection (comma delimited)'
228
- c.action do |global_options, options, args|
229
- if args.size == 1
230
- opts = global_options.merge(options)
231
- opts = opts.slice :select_search, :select_replace, :reject, :semantic_only, :semantic_select
232
- opts = opts.delete_if { |_k, v| v.nil? }
233
- opts[:semantic_only] = !options[:invalid_versions]
234
- opts[:semantic_select] = opts[:semantic_select].split(',') unless opts.fetch(:semantic_select, nil).nil?
235
- package = Getv::Package.new args[0], { type: c.name.to_s }.merge(opts)
236
- Getv::Cli.output(package, latest: global_options[:latest], json: global_options[:json])
237
- else
238
- help_now!
239
- end
240
- end
241
- end
242
-
243
- pre do |_global, _command, _options, _args|
244
- # Pre logic here
245
- # Return true to proceed; false to abort and not call the
246
- # chosen command
247
- # Use skips_pre before a command to skip this block
248
- # on that command only
249
- true
250
- end
251
-
252
- post do |global, command, options, args|
253
- # Post logic here
254
- # Use skips_post before a command to skip this
255
- # block on that command only
256
- end
257
-
258
- on_error do |_exception|
259
- # Error logic here
260
- # return false to skip default error handling
261
- true
262
- end
263
- end
264
-
265
- exit App.run(ARGV)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/getv.gemspec DELETED
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/getv/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'getv'
7
- spec.version = Getv::VERSION
8
- spec.authors = ['harbottle']
9
- spec.email = ['harbottle@room3d3.com']
10
-
11
- spec.summary = 'Pull package version numbers from the web in various ways.'
12
- spec.description = 'Pull package version numbers from the web in various ways.'
13
- spec.homepage = 'https://github.com/liger1978/getv'
14
- spec.license = 'MIT'
15
-
16
- spec.metadata['homepage_uri'] = spec.homepage
17
- spec.metadata['source_code_uri'] = 'https://github.com/liger1978/getv'
18
- spec.metadata['changelog_uri'] = 'https://github.com/liger1978/getv'
19
-
20
- # Specify which files should be added to the gem when it is released.
21
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
- end
25
- spec.bindir = 'exe'
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ['lib']
28
-
29
- spec.add_dependency('gli', '>= 2.20.1', '< 3.0.0')
30
- spec.add_dependency('docker_registry2', '>= 1.0.0', '< 2.0.0')
31
- spec.add_dependency('nokogiri', '>= 1.0.0', '< 2.0.0')
32
- spec.add_dependency('octokit', '>= 3.0.0', '< 5.0.0')
33
- spec.add_dependency('semantic', '>= 1.0.0', '< 2.0.0')
34
- end