optparse2 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/optparse2/version.rb +1 -1
- data/lib/optparse2.rb +15 -31
- data/publish +81 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4b73eda58e3715e16d45898c5d4e22386a23ba2363d0708c02ea336aec51a631
|
|
4
|
+
data.tar.gz: 777192092c696ec69bd6199fbcbd09819468dc0b06541268fa8d1a1ba4b4e389
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c31c01a23b2d0b7020cc004d6a4dda0f24ed2dfe18464a5f8f71249502cedd425e4cb2bb341d4974e733b7e1e721b9f421e49ee022009780c3d512216df220fb
|
|
7
|
+
data.tar.gz: e0d55f1dc1a4743a3b7d3e763272791d30895e89fcbc60ebab3554bce3f0fa1dc3dcbd0a40cef3248875d32b8d1c9da507c773e4e41e33c02065af0439e9676f
|
data/lib/optparse2/version.rb
CHANGED
data/lib/optparse2.rb
CHANGED
|
@@ -6,7 +6,6 @@ OptionParser2 = OptParse2 # Alias
|
|
|
6
6
|
|
|
7
7
|
require_relative "optparse2/version"
|
|
8
8
|
require_relative "optparse2/fixes"
|
|
9
|
-
# require_relative "optparse2/helpers"
|
|
10
9
|
|
|
11
10
|
class OptParse2
|
|
12
11
|
class << self
|
|
@@ -29,20 +28,18 @@ class OptParse2
|
|
|
29
28
|
def self.summarize(*) end
|
|
30
29
|
end
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@switch_name = val
|
|
35
|
-
end
|
|
31
|
+
attr_writer :switch_name
|
|
32
|
+
def switch_name; defined?(@switch_name) ? @switch_name : super end
|
|
36
33
|
|
|
37
|
-
def
|
|
34
|
+
def set_switch_name_possibly_block_value(val)
|
|
38
35
|
if @block.nil? && @arg.nil?
|
|
39
|
-
q =
|
|
36
|
+
q = switch_name.to_sym
|
|
40
37
|
@block = proc { q }
|
|
41
38
|
end
|
|
39
|
+
|
|
40
|
+
self.switch_name = val
|
|
42
41
|
end
|
|
43
42
|
|
|
44
|
-
# attr_writer :switch_name
|
|
45
|
-
def switch_name; defined?(@switch_name) ? @switch_name : super end
|
|
46
43
|
|
|
47
44
|
# requires `switch_name`, `desc` to work
|
|
48
45
|
def set_default(value, description)
|
|
@@ -73,8 +70,7 @@ class OptParse2
|
|
|
73
70
|
|
|
74
71
|
sw.extend Helpers
|
|
75
72
|
if key
|
|
76
|
-
sw.
|
|
77
|
-
sw.set_block_name_because_of_switch_name
|
|
73
|
+
sw.set_switch_name_possibly_block_value key
|
|
78
74
|
end
|
|
79
75
|
sw.set_hidden if hidden
|
|
80
76
|
|
|
@@ -227,6 +223,14 @@ class OptParse2
|
|
|
227
223
|
end
|
|
228
224
|
|
|
229
225
|
def rest(name, *description, key: name.to_s.tr(' ', '-').to_sym, required: 0, &block)
|
|
226
|
+
required = case required
|
|
227
|
+
when true then 1
|
|
228
|
+
when false then 0
|
|
229
|
+
when ->x{ Integer === x && !x.negative? } then required
|
|
230
|
+
else raise TypeError, "invalid type for required: #{required.class} (must be bool or positive integer)"
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
required = 1 if required == true
|
|
230
234
|
title = "#{'[' if required.zero?}#{name} ...#{']' if required.zero?}"
|
|
231
235
|
banner.concat " #{title}" if pos_set_banner
|
|
232
236
|
title += " (#{required} arg minimum)" if required > 0
|
|
@@ -239,23 +243,3 @@ class OptParse2
|
|
|
239
243
|
@rest = { name:, key:, required: required || 0, block: }
|
|
240
244
|
end
|
|
241
245
|
end
|
|
242
|
-
|
|
243
|
-
__END__
|
|
244
|
-
return unless $0 == __FILE__
|
|
245
|
-
require_relative 'optparse2/pathname'
|
|
246
|
-
|
|
247
|
-
# $* << '-tFOO' << '--no-cache' << '-x'
|
|
248
|
-
# $*.replace %w[123 lol what -t10 is up here]
|
|
249
|
-
$*.replace %w[1 -t3 bb lol what -- is up]
|
|
250
|
-
|
|
251
|
-
OPTS={}
|
|
252
|
-
OptParse2.new do |op|
|
|
253
|
-
$op = op
|
|
254
|
-
op.on '-t', '--timeout=FOO', Array,required: true
|
|
255
|
-
op.pos 'file', Integer, 'sets the file name', 'is also pretty cool', 1..1000, required: true do it * 2 end
|
|
256
|
-
op.pos '[start[-end]]', 'things to do', key: 'line', default: 123
|
|
257
|
-
|
|
258
|
-
op.rest 'branch name', 'Message to submit', 'pretty coo', required: 1 do it.join ' ' end
|
|
259
|
-
p op.parse! into: OPTS
|
|
260
|
-
p ["finish: ", OPTS, $*]
|
|
261
|
-
end
|
data/publish
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# require 'optparse2'
|
|
4
|
+
require_relative 'lib/optparse2'
|
|
5
|
+
require 'gvars'
|
|
6
|
+
|
|
7
|
+
def `(cmd)
|
|
8
|
+
super.tap { raise "cmd failed: #{cmd} (exit: #{$?.exitstatus})" unless $?.success? }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
####################################################################################################
|
|
12
|
+
# Parse CLI Opts #
|
|
13
|
+
####################################################################################################
|
|
14
|
+
|
|
15
|
+
OptParse2.new do |op|
|
|
16
|
+
op.pos 'gem', 'The name of the gem', default: proc { File.basename Dir.pwd }, default_description: 'current dir'
|
|
17
|
+
|
|
18
|
+
op.on '-f', '--force', 'Proceed even with dirty git status'
|
|
19
|
+
op.on '-n', '--dry', 'Do not actually publish the gem'
|
|
20
|
+
|
|
21
|
+
op.on '--version VERSION', 'Set the version string to VERSION'
|
|
22
|
+
op.on '-p', '--patch', 'Bump the patch version up', key: :version
|
|
23
|
+
op.on '-m', '--minor', 'Bump the minor version up (and reset patch to 0)', key: :version
|
|
24
|
+
op.on '--version-file=PATH', 'The file where the new version is stored', default: proc { File.join("lib", $gem, "version.rb") },
|
|
25
|
+
default_description: 'lib/<gem>/version.rb'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# note: no `--major`, as that should be done with `--version`
|
|
29
|
+
op.parse! into: GVars
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
####################################################################################################
|
|
33
|
+
# Check Git Dirty Status #
|
|
34
|
+
####################################################################################################
|
|
35
|
+
|
|
36
|
+
unless `git status --porcelain`.chomp.empty?
|
|
37
|
+
if $force
|
|
38
|
+
warn "Proceeding with a dirty git status"
|
|
39
|
+
else
|
|
40
|
+
abort "Not proceeding due to dirty git status; use --force to override"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
####################################################################################################
|
|
45
|
+
# Update VERSION, if supplied #
|
|
46
|
+
####################################################################################################
|
|
47
|
+
|
|
48
|
+
# Fetch the git version
|
|
49
|
+
def get_old_version
|
|
50
|
+
File.read($version_file)[/VERSION\s+=\s+"(\d+\.\d+\.\d+)"/, 1] or fail "cannot fetch old version"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def update_version
|
|
54
|
+
|
|
55
|
+
case $version
|
|
56
|
+
when :patch then $version = get_old_version.succ!
|
|
57
|
+
when :minor then $version = get_old_version.sub!(/\A(\d+\.\d+)\.\d*\z/, '\1').succ + '.0'
|
|
58
|
+
when String then # already set
|
|
59
|
+
else raise
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
puts "Using version #$version"
|
|
63
|
+
vf = File.read($version_file)
|
|
64
|
+
vf.sub!(/(VERSION\s+=\s+")\d+\.\d+\.\d+(")/, "\\1#$version\\2") or fail "cannot update version"
|
|
65
|
+
File.write $version_file, vf
|
|
66
|
+
|
|
67
|
+
unless $dry
|
|
68
|
+
system('git', 'add', '--', $version_file, exception: true)
|
|
69
|
+
system('git', 'commit', '-m', "Version #$version", exception: true)
|
|
70
|
+
system('git', 'push', exception: true)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
update_version unless $version.nil?
|
|
75
|
+
|
|
76
|
+
####################################################################################################
|
|
77
|
+
# Build and Publish the Gem #
|
|
78
|
+
####################################################################################################
|
|
79
|
+
|
|
80
|
+
system('gem', 'build', exception: true)
|
|
81
|
+
system('gem', 'push', "#$gem-#$version.gem", exception: true) unless $dry
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: optparse2
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SamW
|
|
@@ -22,6 +22,7 @@ files:
|
|
|
22
22
|
- lib/optparse2/fixes.rb
|
|
23
23
|
- lib/optparse2/pathname.rb
|
|
24
24
|
- lib/optparse2/version.rb
|
|
25
|
+
- publish
|
|
25
26
|
- sig/optparse2.rbs
|
|
26
27
|
licenses:
|
|
27
28
|
- MIT
|