getv 1.1.0 → 1.3.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: 8b7033c123fd837edd23f202973d20c313932df2e35bb8eb680c2ecd4aa3f674
4
- data.tar.gz: 5e66336327fc70676fba92f92eb56398b00bdfcc780cf4ec54365c38bf1edce3
3
+ metadata.gz: 76b665201a4d7f1ecdaa9047121a3b4fece0805d5de821b9acf636cc9f82a506
4
+ data.tar.gz: 620003975f2b25a1d6df14edfda536e7710cfbcbd6ab4f329c710c4ee820a281
5
5
  SHA512:
6
- metadata.gz: cf6eb57389b7cf24b99177a8dba23da0095719da908672489b5e137e4c89aee948fd134f28bba952785098db43f60cf2645b2bf0bfaffcb81be849382c26db5b
7
- data.tar.gz: 1b24a3216e4b33febabe870994c901c48e17108718f5d5d86dee79f0dabd77936e26b20a3b19ea41160a7774e8eb2e27ae69a31d32fd887d192a6c2ba52e7ffb
6
+ metadata.gz: 61f05289eca59aab2435330d79d849876cf2e3d160d214899a4644c11cba109a4337a5b9bac8c905a54e020b06362201befe63302a5d513efe4f07e82c2fc6fb
7
+ data.tar.gz: 56c9e45f319a0bd94bd27b15053f782731b0f08d6b94c55fbfc8d449b80a3fb8deb96af6fd7e51403305b4875f0231986bb114834b069e243027df56a4f671aa
data/README.md CHANGED
@@ -1,10 +1,18 @@
1
- # Getv
1
+ # getv
2
2
 
3
- Pull package version numbers from the web in various ways.
3
+ [![Gem Version](https://badge.fury.io/rb/getv.svg)](https://rubygems.org/gems/getv)
4
+
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
6
8
 
7
- Add this line to your application's Gemfile:
9
+ Install `getv` with:
10
+
11
+ ```
12
+ gem install getv
13
+ ```
14
+
15
+ Or add this line to your application's Gemfile:
8
16
 
9
17
  ```ruby
10
18
  gem 'getv'
@@ -12,50 +20,137 @@ gem 'getv'
12
20
 
13
21
  And then execute:
14
22
 
15
- $ bundle install
23
+ ```sh
24
+ bundle install
25
+ ```
26
+
27
+ ## CLI
28
+
29
+ An executable command tool, `getv` is bundled with this gem:
30
+
31
+ ```console
32
+ $ getv
33
+ NAME
34
+ getv - Get package version numbers from the web in various ways
35
+
36
+
37
+ SYNOPSIS
38
+ getv [global options] command [command options] [arguments...]
39
+
40
+
41
+ VERSION
42
+ 1.3.0
43
+
44
+
45
+
46
+ GLOBAL OPTIONS
47
+ --help - Show this message
48
+ -j, --json - Output in json
49
+ -l, --latest - Latest version
50
+ --version - Display the program version
51
+
52
+
53
+
54
+ COMMANDS
55
+ docker - Get package versions from a Docker or OCI container image registry
56
+ gem - Get package versions from RubyGems.org
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.
61
+ help - Shows a list of commands or help for one command
62
+ index - Get package versions from web page of links
63
+ npm - Get package versions from npm at registry.npmjs.org
64
+ pypi - Get package versions from the Python Package Index at pypi.org
65
+ ```
66
+
67
+ ### CLI examples
68
+
69
+ Show the latest available version of the `getv` gem:
70
+
71
+ ```console
72
+ $ getv --latest gem getv
73
+ 1.3.0
74
+ ```
75
+
76
+ Show all `dep` GitHub release versions in JSON:
77
+
78
+ ```console
79
+ $ getv --json github_release golang/dep
80
+ {"name":"golang/dep","versions":["0.2.0","0.2.1","0.3.0","0.3.1","0.3.2","0.4.0","0.4.1","0.5.0","0.5.1","0.5.2","0.5.3","0.5.4"]}
81
+ ```
82
+
83
+ Show all AtomicParsley Github release versions:
84
+
85
+ ```console
86
+ $ getv github_release --invalid_versions wez/atomicparsley
87
+ 20200701.154658.b0d6223
88
+ 20201231.092811.cbecfb1
89
+ 20210114.184825.1dbe1be
90
+ 20210124.204813.840499f
91
+ 20210617.200601.1ac7c08
92
+ 20210715.151551.e7ad03a
93
+ ```
16
94
 
17
- Or install it yourself as:
95
+ Show the latest stable version of Kubernetes using the release text file URL:
18
96
 
19
- $ gem install getv
97
+ ```console
98
+ $ getv -l get --url=https://storage.googleapis.com/kubernetes-release/release/stable.txt kubernetes
99
+ 1.23.2
100
+ ```
20
101
 
21
- ## Usage
102
+ Show selected semantic versions of the `apache/superset` Docker image in JSON:
22
103
 
104
+ ```console
105
+ $ getv --json docker --reject '-' --semantic_select '~>1.3.0,!=1.3.1' apache/superset
106
+ {"name":"apache/superset","versions":["1.3.0","1.3.2"]}
23
107
  ```
24
- irb(main):024:0> superset = Getv::Package.new('superset', type: 'docker', owner: 'apache', reject: '-')
25
- =>
26
- #<Getv::Package:0x000055b6d2326f20
27
- ...
28
- irb(main):025:0> superset.versions
29
- => ["1.0.0", "1.0.1", "1.1.0", "1.2.0", "1.3.0", "1.3.1", "1.3.2"]
30
- irb(main):026:0> superset.latest_version
31
- => "1.3.2"
32
- irb(main):027:0> superset
33
- =>
34
- #<Getv::Package:0x000055b6d2326f20
35
- @name="superset",
36
- @opts=
37
- {:owner=>"apache",
38
- :repo=>"superset",
39
- :url=>"https://registry.hub.docker.com",
40
- :type=>"docker",
41
- :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*$", :replace=>"\\1"},
42
- :reject=>"-",
43
- :semantic_only=>true,
44
- :semantic_select=>["*"],
45
- :versions=>["1.0.0", "1.0.1", "1.1.0", "1.2.0", "1.3.0", "1.3.1", "1.3.2"],
46
- :latest_version=>"1.3.2"}>
108
+
109
+ Show all versions of `libnetfilter_acct` using selected link values on an indexed web page:
110
+
111
+ ```console
112
+ $ getv --select_search='^.*libnetfilter_acct-([\d\.]*)\.tar\.bz2$' index --url=https://netfilter.org/projects/libnetfilter_acct/files --link_value libnetfilter_acct
113
+ 1.0.0
114
+ 1.0.1
115
+ 1.0.2
116
+ 1.0.3
117
+ ```
118
+
119
+ Show the latest GitHub commit to the `main` branch of the `getv` project in a useful versioning format:
120
+
121
+ ```console
122
+ # By default the \2 capture group contains the date and \5 contains the short commit hash
123
+ $ getv -l github_commit --select_replace '\2git\5' --branch main liger1978/getv
124
+ 20220123git9ed86f0
125
+ ```
126
+
127
+ ## Ruby library
128
+
129
+ Example:
130
+
131
+ ```ruby
132
+ require 'getv'
133
+
134
+ superset = Getv::Package.new 'superset', type: 'docker', owner: 'apache', reject: '-'
135
+ puts superset.versions
136
+ puts superset.latest_version
47
137
  ```
48
138
 
49
139
  ## Development
50
140
 
51
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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.
52
142
 
53
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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.
54
148
 
55
- ## Contributing
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`)
56
150
 
57
- Bug reports and pull requests are welcome on GitHub at https://github.com/liger1978/getv.
151
+ ## Contributing
58
152
 
153
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/liger1978/getv).
59
154
 
60
155
  ## License
61
156
 
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'
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,
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.1.0'
4
+ VERSION = '1.3.1'
5
5
  end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.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-18 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.20.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.20.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: docker_registry2
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -93,20 +113,14 @@ dependencies:
93
113
  description: Pull package version numbers from the web in various ways.
94
114
  email:
95
115
  - harbottle@room3d3.com
96
- executables: []
116
+ executables:
117
+ - getv
97
118
  extensions: []
98
119
  extra_rdoc_files: []
99
120
  files:
100
- - ".bundle/config"
101
- - ".gitignore"
102
- - ".rspec"
103
- - ".rubocop.yml"
104
- - ".travis.yml"
105
- - Gemfile
106
121
  - LICENSE.txt
107
122
  - README.md
108
- - Rakefile
109
- - getv.gemspec
123
+ - exe/getv
110
124
  - lib/getv.rb
111
125
  - lib/getv/package.rb
112
126
  - lib/getv/version.rb
data/.bundle/config DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- BUNDLE_BIN: "bin"
3
- BUNDLE_DISABLE_SHARED_GEMS: "true"
4
- BUNDLE_PATH: "./bundle"
data/.gitignore DELETED
@@ -1,15 +0,0 @@
1
- /bin/
2
- /bundle/
3
- /.yardoc
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /*.gem
11
- /vendor
12
- Gemfile.lock
13
-
14
- # rspec failure tracking
15
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,14 +0,0 @@
1
- ---
2
- AllCops:
3
- Exclude:
4
- - 'bin/**/*'
5
- - 'bundle/**/*'
6
- - '*.gemspec'
7
- NewCops: enable
8
-
9
- Metrics/BlockLength:
10
- Exclude:
11
- - 'Rakefile'
12
- - '**/*.rake'
13
- - 'test/**/*.rb'
14
- - '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,20 +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 'irb', '~> 1.4'
10
- gem 'nokogiri', '~> 1.13'
11
- gem 'octokit', '~> 4.21'
12
- gem 'rake', '~> 12.0'
13
- gem 'rdoc', '~> 6.4'
14
- gem 'rspec', '~> 3.0'
15
- gem 'rubocop', '~> 1.24', require: false
16
- gem 'rubocop-rake', '~> 0.6', require: false
17
- gem 'rubocop-rspec', '~> 2.7', require: false
18
- gem 'semantic', '~> 1.6'
19
- gem 'vcr', '~> 6.0'
20
- gem 'webmock', '~> 3.0'
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
data/getv.gemspec DELETED
@@ -1,33 +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('docker_registry2', '>= 1.0.0', '< 2.0.0')
30
- spec.add_dependency('nokogiri', '>= 1.0.0', '< 2.0.0')
31
- spec.add_dependency('octokit', '>= 3.0.0', '< 5.0.0')
32
- spec.add_dependency('semantic', '>= 1.0.0', '< 2.0.0')
33
- end