getv 0.2.2 → 1.2.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: 7369ef91a1c131d8bfefc1092766605327b09f75a3850ae8b344525d70ae7941
4
- data.tar.gz: 9ef77edcfe4b6c897af791ce70aeb880477a2526bdee4ac21b9ee08c3b05520f
3
+ metadata.gz: daac0f934a1cdcea8875d71dc0a2579df0cfc79a11c81adf11249aa0a3fc14c8
4
+ data.tar.gz: 6af122cebd5cb12cbd1c11bc615c5e2eb9aaec166ac5d7b7b55c456d496e1e4f
5
5
  SHA512:
6
- metadata.gz: 8084e7d170ec2cd4545e80f99ec87255af60fe468b9d409ee7af7e2bbc7a4f832b73505b247d889ced894a35b75603d24abcba083ababf6c6cec030fd08074e6
7
- data.tar.gz: ef69ca6d1c0a8e5fcba0273a55346d4ed7db0297638c6aab79a42ffb2b39b1e03c21dc08454754bce570204bcb35556413a05ea7bbb813cef44543b4ca3b597b
6
+ metadata.gz: 77e6a4c99d59ecf7f6bfaf9a10e37854ea90d80cc41115a581c84398f52d9c1048059a66482860add6ecc4f80d593ddab9481a2cc313b61fbef7bc2b417e2ce6
7
+ data.tar.gz: 1c578d98f20fa6d690b2b4db46f2cb5b21af39ece384a4ec08d57c7f2a12c6aa3a8ac1ea07d74115ab37c7b711eb74c4b02a3113d6722a958f6b4959b7e8bdc4
@@ -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,7 @@
1
+ /bin/*
2
+ !/bin/console
3
+ !/bin/getv
4
+ !/bin/setup
1
5
  /bundle/
2
6
  /.yardoc
3
7
  /_yardoc/
@@ -7,6 +11,8 @@
7
11
  /spec/reports/
8
12
  /tmp/
9
13
  /*.gem
14
+ /vendor
15
+ Gemfile.lock
10
16
 
11
17
  # rspec failure tracking
12
18
  .rspec_status
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
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/Gemfile CHANGED
@@ -1,13 +1,21 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in getv.gemspec
4
6
  gemspec
5
7
 
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
8
- gem "nokogiri", "~> 1.13"
9
- gem "irb", "~> 1.4"
10
- gem "rdoc", "~> 6.4"
11
- gem "octokit", "~> 4.21"
12
- gem "semantic", "~> 1.6"
13
- gem "docker_registry2", "~> 1.10"
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/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.get_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.get_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/bin/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
@@ -1,31 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/getv/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
4
- spec.name = "getv"
6
+ spec.name = 'getv'
5
7
  spec.version = Getv::VERSION
6
- spec.authors = ["harbottle"]
7
- spec.email = ["harbottle@room3d3.com"]
8
+ spec.authors = ['harbottle']
9
+ spec.email = ['harbottle@room3d3.com']
8
10
 
9
- spec.summary = "Pull package version numbers from the web in various ways."
10
- spec.description = "Pull package version numbers from the web in various ways."
11
- spec.homepage = "https://github.com/liger1978/getv"
12
- spec.license = "MIT"
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'
13
15
 
14
- spec.metadata["homepage_uri"] = spec.homepage
15
- spec.metadata["source_code_uri"] = "https://github.com/liger1978/getv"
16
- spec.metadata["changelog_uri"] = "https://github.com/liger1978/getv"
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'
17
19
 
18
20
  # Specify which files should be added to the gem when it is released.
19
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
23
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
24
  end
23
- spec.bindir = "exe"
25
+ spec.bindir = 'exe'
24
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ["lib"]
27
+ spec.require_paths = ['lib']
26
28
 
27
- spec.add_dependency("nokogiri", ">= 1.0.0", "< 2.0.0")
28
- spec.add_dependency("octokit", ">= 3.0.0", "< 5.0.0")
29
- spec.add_dependency("semantic", ">= 1.0.0", "< 2.0.0")
30
- spec.add_dependency("docker_registry2", ">= 1.0.0", "< 2.0.0")
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')
31
34
  end