optparse2 0.5.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3dff76909d0005ee325d16f79bfa00b18d26a65b3b06b018eef33713e40d250
4
- data.tar.gz: 14733f7d9258908dc1df030b475937590089d1f6eb45f0a99f7df8dbcc6a0ded
3
+ metadata.gz: 4b73eda58e3715e16d45898c5d4e22386a23ba2363d0708c02ea336aec51a631
4
+ data.tar.gz: 777192092c696ec69bd6199fbcbd09819468dc0b06541268fa8d1a1ba4b4e389
5
5
  SHA512:
6
- metadata.gz: e715049dd9d3d3089c6d7ae994666b497eab0436927fe9a98114fcf1d46456798284fb5402fde4edf34ff2dcaf95f5856067fcbcc313fe20ccc46cc0e78635d1
7
- data.tar.gz: 32fc2f6d56246b215845adf065103a60be82d5daf78f3d09d6ae64c1a100664a7521cfdfbc2c362047df74933567f59fe97caa839fce054e2baec97d943e863d
6
+ metadata.gz: c31c01a23b2d0b7020cc004d6a4dda0f24ed2dfe18464a5f8f71249502cedd425e4cb2bb341d4974e733b7e1e721b9f421e49ee022009780c3d512216df220fb
7
+ data.tar.gz: e0d55f1dc1a4743a3b7d3e763272791d30895e89fcbc60ebab3554bce3f0fa1dc3dcbd0a40cef3248875d32b8d1c9da507c773e4e41e33c02065af0439e9676f
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class OptParse2
4
- VERSION = "0.5.2"
4
+ VERSION = "0.5.3"
5
5
  end
data/lib/optparse2.rb CHANGED
@@ -31,7 +31,7 @@ class OptParse2
31
31
  attr_writer :switch_name
32
32
  def switch_name; defined?(@switch_name) ? @switch_name : super end
33
33
 
34
- def set_switch_name_possibly_block_value
34
+ def set_switch_name_possibly_block_value(val)
35
35
  if @block.nil? && @arg.nil?
36
36
  q = switch_name.to_sym
37
37
  @block = proc { q }
@@ -223,6 +223,14 @@ class OptParse2
223
223
  end
224
224
 
225
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
226
234
  title = "#{'[' if required.zero?}#{name} ...#{']' if required.zero?}"
227
235
  banner.concat " #{title}" if pos_set_banner
228
236
  title += " (#{required} arg minimum)" if required > 0
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.2
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