getv 1.0.0 → 1.2.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: 5a68d43a8a011bcf8f9dfe6da94fe08a3774dfaab5b0b00d2c8d879b9678487b
4
- data.tar.gz: a58a0775503091b3721ae6098240575dad501100a587eb5a278d84a0ac6a5080
3
+ metadata.gz: 549d2b57e5c43edd1ef2e1863ae5f77a2fb90ae084af476538a4be8ede571b96
4
+ data.tar.gz: 70d9e117658760a203c38154ffcdb07b59a45755188738745810a7b190c4a699
5
5
  SHA512:
6
- metadata.gz: d80d95dff250b3a699327f747cd6cb59407f9ad42603731c239b0784f870f9622e01d50e3fe52c3eeab674575f8126a690837801e0ff73ce4e0bdf18953ea060
7
- data.tar.gz: f517c35bbfaaab58456ce36da1629d66ef2390da980e60b98100d9f65f5c18d944eac678aa6c51993273d96656cbae934f8f0628a5006fed328a7d72ead81f58
6
+ metadata.gz: 74e3de7eb766b38f77f963b73f86d53453af269a007c83e3329a4e4e51274fd052fee4d9bd68f79037abdb0cb5575d91eabdbba57db7dd43a14073738f9dd76c
7
+ data.tar.gz: ac8824867be53ca59914e4edb77b0eeed7f46c204e63c2664a1d3897d291dbd1bc77b49917044a2bc45db3602918d384521422773f382ee468ca5d490c6fc1fa
@@ -0,0 +1,37 @@
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 CHANGED
@@ -1,3 +1,6 @@
1
+ /bin/*
2
+ !/bin/console
3
+ !/bin/setup
1
4
  /bundle/
2
5
  /.yardoc
3
6
  /_yardoc/
data/.rubocop.yml CHANGED
@@ -1,10 +1,16 @@
1
1
  ---
2
+ require:
3
+ - rubocop-rspec
2
4
  AllCops:
5
+ Exclude:
6
+ - 'bin/**/*'
7
+ - 'bundle/**/*'
8
+ - 'vendor/**/*'
9
+ - '*.gemspec'
3
10
  NewCops: enable
4
11
 
5
12
  Metrics/BlockLength:
6
13
  Exclude:
7
14
  - 'Rakefile'
8
15
  - '**/*.rake'
9
- - 'test/**/*.rb'
10
16
  - 'spec/**/*_spec.rb'
data/Gemfile CHANGED
@@ -6,12 +6,16 @@ source 'https://rubygems.org'
6
6
  gemspec
7
7
 
8
8
  gem 'docker_registry2', '~> 1.10'
9
+ gem 'gli', '~> 2.20'
9
10
  gem 'irb', '~> 1.4'
10
11
  gem 'nokogiri', '~> 1.13'
11
12
  gem 'octokit', '~> 4.21'
12
13
  gem 'rake', '~> 12.0'
13
14
  gem 'rdoc', '~> 6.4'
14
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
15
19
  gem 'semantic', '~> 1.6'
16
20
  gem 'vcr', '~> 6.0'
17
21
  gem 'webmock', '~> 3.0'
data/README.md CHANGED
@@ -1,10 +1,16 @@
1
- # Getv
1
+ # getv
2
2
 
3
- Pull package version numbers from the web in various ways.
3
+ 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
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Install `getv` with:
8
+
9
+ ```
10
+ gem install getv
11
+ ```
12
+
13
+ Or add this line to your application's Gemfile:
8
14
 
9
15
  ```ruby
10
16
  gem 'getv'
@@ -12,50 +18,132 @@ gem 'getv'
12
18
 
13
19
  And then execute:
14
20
 
15
- $ bundle install
21
+ ```sh
22
+ bundle install
23
+ ```
24
+
25
+ ## CLI
26
+
27
+ An executable command tool, `getv` is bundled with this gem:
28
+
29
+ ```console
30
+ $ getv
31
+ NAME
32
+ getv - Get package version numbers from the web in various ways
33
+
34
+
35
+ SYNOPSIS
36
+ getv [global options] command [command options] [arguments...]
37
+
16
38
 
17
- Or install it yourself as:
39
+ VERSION
40
+ 1.1.0
18
41
 
19
- $ gem install getv
20
42
 
21
- ## Usage
22
43
 
44
+ 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
52
+
53
+
54
+
55
+ COMMANDS
56
+ docker - Get package versions from a Docker or OCI container image registry
57
+ gem - Get package versions from RubyGems.org
58
+ 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
62
+ help - Shows a list of commands or help for one command
63
+ index - Get package versions from web page of links
64
+ npm - Get package versions from npm at registry.npmjs.org
65
+ pypi - Get package versions from the Python Package Index at pypi.org
23
66
  ```
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"}>
67
+
68
+ ### CLI examples
69
+
70
+ Show the latest available version of the `getv` gem:
71
+
72
+ ```console
73
+ $ getv --latest gem getv
74
+ 1.1.0
47
75
  ```
48
76
 
49
- ## Development
77
+ Show all `dep` GitHub release versions in JSON:
50
78
 
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.
79
+ ```console
80
+ $ getv --json github_release golang/dep
81
+ {"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"]}
82
+ ```
52
83
 
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).
84
+ Show all AtomicParsley Github release versions:
54
85
 
55
- ## Contributing
86
+ ```console
87
+ $ getv --select_search='(.*)' github_release --invalid_versions wez/atomicparsley
88
+ 20200701.154658.b0d6223
89
+ 20201231.092811.cbecfb1
90
+ 20210114.184825.1dbe1be
91
+ 20210124.204813.840499f
92
+ 20210617.200601.1ac7c08
93
+ 20210715.151551.e7ad03a
94
+ ```
95
+
96
+ Show the latest stable version of Kubernetes using the release text file URL:
56
97
 
57
- Bug reports and pull requests are welcome on GitHub at https://github.com/liger1978/getv.
98
+ ```console
99
+ $ getv -l get --url=https://storage.googleapis.com/kubernetes-release/release/stable.txt kubernetes
100
+ 1.23.2
101
+ ```
102
+
103
+ Show selected semantic versions of the `apache/superset` Docker image in JSON:
104
+
105
+ ```console
106
+ $ getv --json --reject '-' docker --semantic_select '~>1.3.0,!=1.3.1' apache/superset
107
+ {"name":"apache/superset","versions":["1.3.0","1.3.2"]}
108
+ ```
109
+
110
+ Show all versions of `libnetfilter_acct` using selected link values on an indexed web page:
111
+
112
+ ```console
113
+ $ getv --select_search='^.*libnetfilter_acct-([\d\.]*)\.tar\.bz2$' index --url=https://netfilter.org/projects/libnetfilter_acct/files --link_value libnetfilter_acct
114
+ 1.0.0
115
+ 1.0.1
116
+ 1.0.2
117
+ 1.0.3
118
+ ```
119
+
120
+ Show the latest GitHub commit to the `main` branch of the `getv` project in a useful versioning format:
121
+
122
+ ```console
123
+ # 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
125
+ 20220123git9ed86f0
126
+ ```
127
+
128
+ ## Ruby library
129
+
130
+ Example:
131
+
132
+ ```ruby
133
+ require 'getv'
134
+
135
+ superset = Getv::Package.new 'superset', type: 'docker', owner: 'apache', reject: '-'
136
+ puts superset.versions
137
+ puts superset.latest_version
138
+ ```
139
+
140
+ ## Development
141
+
142
+ 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
+
144
+ ## Contributing
58
145
 
146
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/liger1978/getv).
59
147
 
60
148
  ## License
61
149
 
data/Rakefile CHANGED
@@ -1,6 +1,13 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
3
6
 
4
7
  RSpec::Core::RakeTask.new(:spec)
5
8
 
6
- task :default => :spec
9
+ RuboCop::RakeTask.new do |task|
10
+ task.requires << 'rubocop-rspec'
11
+ end
12
+
13
+ task default: :spec
data/exe/getv ADDED
@@ -0,0 +1,265 @@
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/getv.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
+ spec.add_dependency('gli', '>= 2.20.1', '< 3.0.0')
29
30
  spec.add_dependency('docker_registry2', '>= 1.0.0', '< 2.0.0')
30
31
  spec.add_dependency('nokogiri', '>= 1.0.0', '< 2.0.0')
31
32
  spec.add_dependency('octokit', '>= 3.0.0', '< 5.0.0')
data/lib/getv/package.rb CHANGED
@@ -5,7 +5,7 @@ module Getv
5
5
  class Package # rubocop:disable Metrics/ClassLength
6
6
  attr_accessor :name, :opts
7
7
 
8
- def initialize(name, opts = {}) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize
8
+ def initialize(name, opts = {}) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
9
9
  @name = name
10
10
  case name
11
11
  when /rubygem-.*/
@@ -32,6 +32,9 @@ module Getv
32
32
  versions: nil,
33
33
  latest_version: nil
34
34
  }.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
35
38
  case opts[:type]
36
39
  when 'docker'
37
40
  opts = { owner: 'library', repo: name, url: 'https://registry.hub.docker.com' }.merge(opts)
@@ -80,7 +83,7 @@ module Getv
80
83
  else
81
84
  versions.sort! unless opts[:type] == 'github_commit'
82
85
  end
83
- opts[:versions] = versions
86
+ opts[:versions] = versions.uniq
84
87
  opts[:latest_version] = opts[:versions][-1] unless opts[:versions].empty?
85
88
  end
86
89
 
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.0.0'
4
+ VERSION = '1.2.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.0.0
4
+ version: 1.2.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-16 00:00:00.000000000 Z
11
+ date: 2022-01-23 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,11 +113,13 @@ 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
121
  - ".bundle/config"
122
+ - ".github/workflows/ruby.yml"
101
123
  - ".gitignore"
102
124
  - ".rspec"
103
125
  - ".rubocop.yml"
@@ -106,19 +128,9 @@ files:
106
128
  - LICENSE.txt
107
129
  - README.md
108
130
  - Rakefile
109
- - bin/bundle
110
131
  - bin/console
111
- - bin/htmldiff
112
- - bin/irb
113
- - bin/ldiff
114
- - bin/nokogiri
115
- - bin/racc
116
- - bin/rake
117
- - bin/rdoc
118
- - bin/restclient
119
- - bin/ri
120
- - bin/rspec
121
132
  - bin/setup
133
+ - exe/getv
122
134
  - getv.gemspec
123
135
  - lib/getv.rb
124
136
  - lib/getv/package.rb
data/bin/bundle DELETED
@@ -1,114 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'bundle' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "rubygems"
12
-
13
- m = Module.new do
14
- module_function
15
-
16
- def invoked_as_script?
17
- File.expand_path($0) == File.expand_path(__FILE__)
18
- end
19
-
20
- def env_var_version
21
- ENV["BUNDLER_VERSION"]
22
- end
23
-
24
- def cli_arg_version
25
- return unless invoked_as_script? # don't want to hijack other binstubs
26
- return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
- bundler_version = nil
28
- update_index = nil
29
- ARGV.each_with_index do |a, i|
30
- if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
- bundler_version = a
32
- end
33
- next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
- bundler_version = $1
35
- update_index = i
36
- end
37
- bundler_version
38
- end
39
-
40
- def gemfile
41
- gemfile = ENV["BUNDLE_GEMFILE"]
42
- return gemfile if gemfile && !gemfile.empty?
43
-
44
- File.expand_path("../../Gemfile", __FILE__)
45
- end
46
-
47
- def lockfile
48
- lockfile =
49
- case File.basename(gemfile)
50
- when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
- else "#{gemfile}.lock"
52
- end
53
- File.expand_path(lockfile)
54
- end
55
-
56
- def lockfile_version
57
- return unless File.file?(lockfile)
58
- lockfile_contents = File.read(lockfile)
59
- return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
- Regexp.last_match(1)
61
- end
62
-
63
- def bundler_requirement
64
- @bundler_requirement ||=
65
- env_var_version || cli_arg_version ||
66
- bundler_requirement_for(lockfile_version)
67
- end
68
-
69
- def bundler_requirement_for(version)
70
- return "#{Gem::Requirement.default}.a" unless version
71
-
72
- bundler_gem_version = Gem::Version.new(version)
73
-
74
- requirement = bundler_gem_version.approximate_recommendation
75
-
76
- return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
77
-
78
- requirement += ".a" if bundler_gem_version.prerelease?
79
-
80
- requirement
81
- end
82
-
83
- def load_bundler!
84
- ENV["BUNDLE_GEMFILE"] ||= gemfile
85
-
86
- activate_bundler
87
- end
88
-
89
- def activate_bundler
90
- gem_error = activation_error_handling do
91
- gem "bundler", bundler_requirement
92
- end
93
- return if gem_error.nil?
94
- require_error = activation_error_handling do
95
- require "bundler/version"
96
- end
97
- return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
98
- warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
99
- exit 42
100
- end
101
-
102
- def activation_error_handling
103
- yield
104
- nil
105
- rescue StandardError, LoadError => e
106
- e
107
- end
108
- end
109
-
110
- m.load_bundler!
111
-
112
- if m.invoked_as_script?
113
- load Gem.bin_path("bundler", "bundle")
114
- end
data/bin/htmldiff DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'htmldiff' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("diff-lcs", "htmldiff")
data/bin/irb DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'irb' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("irb", "irb")
data/bin/ldiff DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'ldiff' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("diff-lcs", "ldiff")
data/bin/nokogiri DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'nokogiri' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("nokogiri", "nokogiri")
data/bin/racc DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'racc' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("racc", "racc")
data/bin/rake DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rake' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rake", "rake")
data/bin/rdoc DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rdoc' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rdoc", "rdoc")
data/bin/restclient DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'restclient' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rest-client", "restclient")
data/bin/ri DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'ri' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rdoc", "ri")
data/bin/rspec DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rspec' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rspec-core", "rspec")