switches.rb 0.10.0 → 0.10.1
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/CHANGELOG +9 -0
- data/Gemfile +5 -1
- data/Rakefile +14 -0
- data/lib/Switches.rb +1 -1
- data/spec/all.rb +160 -156
- data/switches.rb.gemspec +3 -1
- metadata +16 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e900150793418981ab52b35828a2fc696a5e7b826d4eba77047d96cc7532dfe
|
|
4
|
+
data.tar.gz: f4e598c29f7dbaf2c61b8e685151732afba5770b94085cbe06a413f85151b692
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe23cc64afe81e073164650ef50b64ae208cfc57cc82a9e6e57efc4925f8cd87853b0b5726f2dea6cbe528cf9348fc1499e9e5fe6febf2e9f4348eb96a1b2e9e
|
|
7
|
+
data.tar.gz: 4ab5f810b80fc2716684aaa46481a2e83db7bf628a6a81bdfe25c4f1ed588eaf3fb090fd011e92df3592ec93962e2915b2ec3f0821c4d93081f04624e207a7cc
|
data/CHANGELOG
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## 20260809
|
|
4
4
|
|
|
5
|
+
0.10.1: Get the specs running again, under rspec 3 and rake.
|
|
6
|
+
|
|
7
|
+
1. ~ spec/all.rb: rspec 3 syntax throughout, in place of the pre-rspec-3 #should ==, so the specs run at all.
|
|
8
|
+
2. ~ spec/all.rb: the six raise expectations were written as switches.should{raise MissingArgument}, which asserts nothing and names a constant which doesn't exist; they now expect OptionParser::MissingArgument and RequiredSwitchMissing for real.
|
|
9
|
+
3. ~ spec/all.rb: + specs for #perform and #perform!, which had been left pending, and - the Array#empty! alias, since ARGV.clear says it without patching Array.
|
|
10
|
+
4. + Rakefile: an rspec task pointed at spec/all.rb, since the specs live in the one file rather than under the default spec/**/*_spec.rb, + a version task, and spec as the default task.
|
|
11
|
+
5. ~ Gemfile: use gemspec rather than restate rspec, and + ostruct, which the bundle must provide for require_gem to find under Ruby 4.0.
|
|
12
|
+
6. ~ switches.rb.gemspec: + rake as a development dependency and + Rakefile to the file list.
|
|
13
|
+
|
|
5
14
|
0.10.0: Restore loading and building under Ruby 4.0, and bring the repo up to standard.
|
|
6
15
|
|
|
7
16
|
1. ~ lib/Switches.rb: require ostruct through a vendored require_gem (+ lib/Kernel/require_gem.rb, + lib/Thoran/Kernel/RequireGem/require_gem.rb), so it no longer needs ostruct to be a default gem — which it stopped being as of Ruby 4.0 — nor require_gem to be found on RUBYLIB.
|
data/Gemfile
CHANGED
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Rakefile
|
|
2
|
+
|
|
3
|
+
require 'rspec/core/rake_task'
|
|
4
|
+
|
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
6
|
+
t.pattern = 'spec/all.rb'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
task default: :spec
|
|
10
|
+
|
|
11
|
+
desc "Show version"
|
|
12
|
+
task :version do
|
|
13
|
+
puts "switches.rb #{Gem::Specification.load('switches.rb.gemspec').version}"
|
|
14
|
+
end
|
data/lib/Switches.rb
CHANGED
data/spec/all.rb
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
# spec/all.rb
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
alias_method :empty!, :clear
|
|
6
|
-
|
|
7
|
-
end
|
|
3
|
+
require_relative '../lib/Switches'
|
|
8
4
|
|
|
9
5
|
describe Switches do
|
|
10
|
-
|
|
11
6
|
describe ".new" do
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Switches.new.class.should == Switches
|
|
7
|
+
it "returns an object of class Switches" do
|
|
8
|
+
expect(Switches.new.class).to eq(Switches)
|
|
15
9
|
end
|
|
16
|
-
|
|
17
10
|
end
|
|
18
|
-
|
|
11
|
+
|
|
19
12
|
describe "#set" do
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ARGV.empty!
|
|
13
|
+
def build(switches_string = '')
|
|
14
|
+
ARGV.clear
|
|
23
15
|
switches_string.split.each{|a| ARGV << a}
|
|
24
16
|
Switches.new do |s|
|
|
25
17
|
s.set :v?, :verbose?
|
|
@@ -27,196 +19,208 @@ describe Switches do
|
|
|
27
19
|
s.set :host, :h
|
|
28
20
|
end
|
|
29
21
|
end
|
|
30
|
-
|
|
31
|
-
it "
|
|
32
|
-
|
|
22
|
+
|
|
23
|
+
it "sets a short boolean switch to true when supplied with a short switch" do
|
|
24
|
+
expect(build('-v').v?).to eq(true)
|
|
33
25
|
end
|
|
34
|
-
|
|
35
|
-
it "
|
|
36
|
-
|
|
26
|
+
|
|
27
|
+
it "sets a long boolean switch to true when supplied with a short switch" do
|
|
28
|
+
expect(build('-v').verbose?).to eq(true)
|
|
37
29
|
end
|
|
38
|
-
|
|
39
|
-
it "
|
|
40
|
-
|
|
30
|
+
|
|
31
|
+
it "sets a short boolean switch to true when supplied with a long switch" do
|
|
32
|
+
expect(build('--verbose').v?).to eq(true)
|
|
41
33
|
end
|
|
42
|
-
|
|
43
|
-
it "
|
|
44
|
-
|
|
34
|
+
|
|
35
|
+
it "sets a long boolean switch to true when supplied with a long switch" do
|
|
36
|
+
expect(build('--verbose').verbose?).to eq(true)
|
|
45
37
|
end
|
|
46
|
-
|
|
47
|
-
it "
|
|
48
|
-
|
|
38
|
+
|
|
39
|
+
it "sets a short switch to the value supplied when supplied with a short switch" do
|
|
40
|
+
expect(build('-p 22').p).to eq('22')
|
|
49
41
|
end
|
|
50
|
-
|
|
51
|
-
it "
|
|
52
|
-
|
|
42
|
+
|
|
43
|
+
it "sets a long switch to the value supplied when supplied with a short switch" do
|
|
44
|
+
expect(build('-p 22').port).to eq('22')
|
|
53
45
|
end
|
|
54
|
-
|
|
55
|
-
it "
|
|
56
|
-
|
|
46
|
+
|
|
47
|
+
it "sets a short switch to the value supplied when supplied with a long switch" do
|
|
48
|
+
expect(build('--port 22').p).to eq('22')
|
|
57
49
|
end
|
|
58
|
-
|
|
59
|
-
it "
|
|
60
|
-
|
|
50
|
+
|
|
51
|
+
it "sets a long switch to the value supplied when supplied with a long switch" do
|
|
52
|
+
expect(build('--port 22').port).to eq('22')
|
|
61
53
|
end
|
|
62
|
-
|
|
63
|
-
it "
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
|
|
55
|
+
it "doesn't matter in which order the short and long switches are given" do
|
|
56
|
+
expect(build('-h example.com').h).to eq('example.com')
|
|
57
|
+
expect(build('--host example.com').h).to eq('example.com')
|
|
66
58
|
end
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
59
|
+
end
|
|
60
|
+
|
|
70
61
|
describe "#set!" do
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
ARGV.empty!
|
|
62
|
+
def build(switches_string = '')
|
|
63
|
+
ARGV.clear
|
|
74
64
|
switches_string.split.each{|a| ARGV << a}
|
|
75
65
|
Switches.new do |s|
|
|
76
66
|
s.set! :p, :port
|
|
77
67
|
end
|
|
78
68
|
end
|
|
79
|
-
|
|
80
|
-
it "
|
|
81
|
-
|
|
69
|
+
|
|
70
|
+
it "sets a short switch to the argument supplied with a short switch" do
|
|
71
|
+
expect(build('-p 22').p).to eq('22')
|
|
82
72
|
end
|
|
83
|
-
|
|
84
|
-
it "
|
|
85
|
-
|
|
73
|
+
|
|
74
|
+
it "sets a long switch to the argument supplied with a short switch" do
|
|
75
|
+
expect(build('-p 22').port).to eq('22')
|
|
86
76
|
end
|
|
87
|
-
|
|
88
|
-
it "
|
|
89
|
-
|
|
77
|
+
|
|
78
|
+
it "sets a short switch to the argument supplied with a long switch" do
|
|
79
|
+
expect(build('--port 22').p).to eq('22')
|
|
90
80
|
end
|
|
91
|
-
|
|
92
|
-
it "
|
|
93
|
-
|
|
81
|
+
|
|
82
|
+
it "sets a long switch to the argument supplied with a long switch" do
|
|
83
|
+
expect(build('--port 22').port).to eq('22')
|
|
94
84
|
end
|
|
95
|
-
|
|
96
|
-
it "
|
|
97
|
-
|
|
98
|
-
switches.should{raise MissingArgument}
|
|
85
|
+
|
|
86
|
+
it "raises OptionParser::MissingArgument when no argument is supplied to a short switch" do
|
|
87
|
+
expect{build('-p')}.to raise_error(OptionParser::MissingArgument)
|
|
99
88
|
end
|
|
100
|
-
|
|
101
|
-
it "
|
|
102
|
-
|
|
103
|
-
switches.should{raise MissingArgument}
|
|
89
|
+
|
|
90
|
+
it "raises OptionParser::MissingArgument when no argument is supplied to a long switch" do
|
|
91
|
+
expect{build('--port')}.to raise_error(OptionParser::MissingArgument)
|
|
104
92
|
end
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
93
|
+
end
|
|
94
|
+
|
|
108
95
|
describe "#required" do
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
ARGV.empty!
|
|
96
|
+
def build(switches_string = '')
|
|
97
|
+
ARGV.clear
|
|
112
98
|
switches_string.split.each{|a| ARGV << a}
|
|
113
99
|
Switches.new do |s|
|
|
114
100
|
s.required :p, :port
|
|
115
101
|
end
|
|
116
102
|
end
|
|
117
|
-
|
|
118
|
-
it "
|
|
119
|
-
|
|
103
|
+
|
|
104
|
+
it "sets a short switch to the argument supplied with a short switch" do
|
|
105
|
+
expect(build('-p 22').p).to eq('22')
|
|
120
106
|
end
|
|
121
|
-
|
|
122
|
-
it "
|
|
123
|
-
|
|
107
|
+
|
|
108
|
+
it "sets a long switch to the argument supplied with a short switch" do
|
|
109
|
+
expect(build('-p 22').port).to eq('22')
|
|
124
110
|
end
|
|
125
|
-
|
|
126
|
-
it "
|
|
127
|
-
|
|
111
|
+
|
|
112
|
+
it "sets a short switch to the argument supplied with a long switch" do
|
|
113
|
+
expect(build('--port 22').p).to eq('22')
|
|
128
114
|
end
|
|
129
|
-
|
|
130
|
-
it "
|
|
131
|
-
|
|
115
|
+
|
|
116
|
+
it "sets a long switch to the argument supplied with a long switch" do
|
|
117
|
+
expect(build('--port 22').port).to eq('22')
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "raises RequiredSwitchMissing when no switch is supplied" do
|
|
121
|
+
expect{build}.to raise_error(RequiredSwitchMissing)
|
|
132
122
|
end
|
|
133
|
-
|
|
134
|
-
it "
|
|
135
|
-
|
|
136
|
-
switches.should{raise RequiredSwitchMissing}
|
|
123
|
+
|
|
124
|
+
it "names every missing switch in the RequiredSwitchMissing message" do
|
|
125
|
+
expect{build}.to raise_error(RequiredSwitchMissing, /-p.*--port/m)
|
|
137
126
|
end
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
127
|
+
end
|
|
128
|
+
|
|
141
129
|
describe "#required!" do
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
ARGV.empty!
|
|
130
|
+
def build(switches_string = '')
|
|
131
|
+
ARGV.clear
|
|
145
132
|
switches_string.split.each{|a| ARGV << a}
|
|
146
133
|
Switches.new do |s|
|
|
147
134
|
s.required! :p, :port
|
|
148
135
|
end
|
|
149
136
|
end
|
|
150
|
-
|
|
151
|
-
it "
|
|
152
|
-
|
|
137
|
+
|
|
138
|
+
it "sets a short switch to the argument supplied with a short switch" do
|
|
139
|
+
expect(build('-p 22').p).to eq('22')
|
|
153
140
|
end
|
|
154
|
-
|
|
155
|
-
it "
|
|
156
|
-
|
|
141
|
+
|
|
142
|
+
it "sets a long switch to the argument supplied with a short switch" do
|
|
143
|
+
expect(build('-p 22').port).to eq('22')
|
|
157
144
|
end
|
|
158
|
-
|
|
159
|
-
it "
|
|
160
|
-
|
|
145
|
+
|
|
146
|
+
it "sets a short switch to the argument supplied with a long switch" do
|
|
147
|
+
expect(build('--port 22').p).to eq('22')
|
|
161
148
|
end
|
|
162
|
-
|
|
163
|
-
it "
|
|
164
|
-
|
|
149
|
+
|
|
150
|
+
it "sets a long switch to the argument supplied with a long switch" do
|
|
151
|
+
expect(build('--port 22').port).to eq('22')
|
|
165
152
|
end
|
|
166
|
-
|
|
167
|
-
it "
|
|
168
|
-
|
|
169
|
-
switches.should{raise MissingArgument}
|
|
153
|
+
|
|
154
|
+
it "raises OptionParser::MissingArgument when no argument is supplied to a short switch" do
|
|
155
|
+
expect{build('-p')}.to raise_error(OptionParser::MissingArgument)
|
|
170
156
|
end
|
|
171
|
-
|
|
172
|
-
it "
|
|
173
|
-
|
|
174
|
-
switches.should{raise MissingArgument}
|
|
157
|
+
|
|
158
|
+
it "raises OptionParser::MissingArgument when no argument is supplied to a long switch" do
|
|
159
|
+
expect{build('--port')}.to raise_error(OptionParser::MissingArgument)
|
|
175
160
|
end
|
|
176
|
-
|
|
177
|
-
it "
|
|
178
|
-
|
|
179
|
-
switches.should{raise RequiredSwitchMissing}
|
|
161
|
+
|
|
162
|
+
it "raises RequiredSwitchMissing when no switch is supplied" do
|
|
163
|
+
expect{build}.to raise_error(RequiredSwitchMissing)
|
|
180
164
|
end
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
165
|
+
end
|
|
166
|
+
|
|
184
167
|
describe "#perform" do
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
ARGV.empty!
|
|
168
|
+
def build(switches_string = '', &block)
|
|
169
|
+
ARGV.clear
|
|
188
170
|
switches_string.split.each{|a| ARGV << a}
|
|
189
|
-
Switches.new
|
|
190
|
-
|
|
191
|
-
|
|
171
|
+
Switches.new{|s| s.perform(:a, :action, &block)}
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "calls the block when supplied with a short switch" do
|
|
175
|
+
called = false
|
|
176
|
+
build('-a'){called = true}
|
|
177
|
+
expect(called).to eq(true)
|
|
192
178
|
end
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
179
|
+
|
|
180
|
+
it "calls the block when supplied with a long switch" do
|
|
181
|
+
called = false
|
|
182
|
+
build('--action'){called = true}
|
|
183
|
+
expect(called).to eq(true)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "doesn't call the block when the switch isn't supplied" do
|
|
187
|
+
called = false
|
|
188
|
+
build{called = true}
|
|
189
|
+
expect(called).to eq(false)
|
|
196
190
|
end
|
|
197
|
-
|
|
198
|
-
it "
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
191
|
+
|
|
192
|
+
it "doesn't require an argument" do
|
|
193
|
+
expect{build('-a'){}}.not_to raise_error
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
202
197
|
describe "#perform!" do
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
ARGV.empty!
|
|
198
|
+
def build(switches_string = '', &block)
|
|
199
|
+
ARGV.clear
|
|
206
200
|
switches_string.split.each{|a| ARGV << a}
|
|
207
|
-
Switches.new
|
|
208
|
-
|
|
209
|
-
|
|
201
|
+
Switches.new{|s| s.perform!(:a, :action, &block)}
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it "passes the argument to the block when supplied with a short switch" do
|
|
205
|
+
argument = nil
|
|
206
|
+
build('-a value'){|o| argument = o}
|
|
207
|
+
expect(argument).to eq('value')
|
|
210
208
|
end
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
it "
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
end
|
|
209
|
+
|
|
210
|
+
it "passes the argument to the block when supplied with a long switch" do
|
|
211
|
+
argument = nil
|
|
212
|
+
build('--action value'){|o| argument = o}
|
|
213
|
+
expect(argument).to eq('value')
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it "doesn't call the block when the switch isn't supplied" do
|
|
217
|
+
called = false
|
|
218
|
+
build{called = true}
|
|
219
|
+
expect(called).to eq(false)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
it "raises OptionParser::MissingArgument when no argument is supplied" do
|
|
223
|
+
expect{build('-a'){}}.to raise_error(OptionParser::MissingArgument)
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
data/switches.rb.gemspec
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'switches.rb' # I would have preferred 'switches', but there's a gem with the name of switches.
|
|
3
3
|
|
|
4
|
-
s.version = '0.10.
|
|
4
|
+
s.version = '0.10.1'
|
|
5
5
|
s.date = '2026-08-09'
|
|
6
6
|
|
|
7
7
|
s.summary = "The easiest way to provide switches to a Ruby program."
|
|
@@ -12,12 +12,14 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
s.license = 'MIT'
|
|
13
13
|
s.required_ruby_version = ">= 2.7.0"
|
|
14
14
|
|
|
15
|
+
s.add_development_dependency('rake')
|
|
15
16
|
s.add_development_dependency('rspec')
|
|
16
17
|
|
|
17
18
|
s.files = [
|
|
18
19
|
'CHANGELOG',
|
|
19
20
|
'Gemfile',
|
|
20
21
|
'LICENSE.txt',
|
|
22
|
+
'Rakefile',
|
|
21
23
|
'README.md',
|
|
22
24
|
'switches.rb.gemspec',
|
|
23
25
|
Dir['lib/**/*.rb'],
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: switches.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.10.
|
|
4
|
+
version: 0.10.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -9,6 +9,20 @@ bindir: bin
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 2026-08-09 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rake
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: rspec
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -34,6 +48,7 @@ files:
|
|
|
34
48
|
- Gemfile
|
|
35
49
|
- LICENSE.txt
|
|
36
50
|
- README.md
|
|
51
|
+
- Rakefile
|
|
37
52
|
- lib/Kernel/require_gem.rb
|
|
38
53
|
- lib/Switches.rb
|
|
39
54
|
- lib/Thoran/Kernel/RequireGem/require_gem.rb
|