-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse-gemspec
executable file
·40 lines (31 loc) · 989 Bytes
/
parse-gemspec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env ruby
require 'optparse'
gemspecs = Dir["*.gemspec"]
if gemspecs.empty?
warn "No gemspec found in #{Dir.pwd}"
exit 10
end
if gemspecs.count > 1
warn "More than one gemspec found in #{Dir.pwd}"
exit 10
end
spec = Gem::Specification.load(gemspecs.first)
exit 10 unless spec
def puts!(msg)
puts msg
exit
end
OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename($0)} [options]"
opts.on("-h", "--help", "Prints this help") do puts! opts end
opts.on("--name", "Output name") do |v| puts! spec.name end
opts.on("--version", "Output gem version") do |v| puts! spec.version end
opts.on("--metadata", "Output metadata") do |v| puts! spec.metadata end
opts.on("--push-host", "Output metadata.allowed_push_host") do |v|
puts! spec.metadata.dig "allowed_push_host"
end
opts.on("--is-pre-release", "Exit 0 if pre-release, 1 otherwise") do |v|
exit 0 if spec.version.prerelease?
exit 1
end
end.parse!