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