simple_scripting 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -3
- data/lib/simple_scripting/argv.rb +7 -0
- data/lib/simple_scripting/version.rb +1 -1
- data/simple_scripting.gemspec +1 -1
- data/spec/simple_scripting/argv_spec.rb +37 -8
- metadata +3 -4
- data/Gemfile.lock +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc0247a6611c5316dad4d41f31b6127cf6bc7aaed615bcc271e548c11f272226
|
4
|
+
data.tar.gz: 3f6602c871caf6666caacfc001d47b6296be49e76c69f56e9903b0438a1fc38e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09293ef72e58432cfbb31d282f3ac86141e978dcacdc00a30203f621871bc72663c7566aaf344cb45cc8990ba6e65f1e5b7b401e09e1acc9c86bc0c6f42f05ec'
|
7
|
+
data.tar.gz: 024a82b8d6e483df5e679b549f17266e9c5e6d74cc25a46038484f5ac69b1534d7147ce2114f09f07589625d16f6ef51e1cfa41c12ea0655b40600d335aed1ad
|
data/.gitignore
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
coverage/
|
1
|
+
/.ruby-gemset
|
2
|
+
/.ruby-version
|
3
|
+
/coverage/
|
4
|
+
/Gemfile.lock
|
@@ -44,6 +44,7 @@ module SimpleScripting
|
|
44
44
|
long_help = options[:long_help]
|
45
45
|
auto_help = options.fetch(:auto_help, true)
|
46
46
|
output = options.fetch(:output, $stdout)
|
47
|
+
raise_errors = options.fetch(:raise_errors, false)
|
47
48
|
|
48
49
|
# WATCH OUT! @long_help can also be set in :decode_command!. See issue #17.
|
49
50
|
#
|
@@ -60,6 +61,12 @@ module SimpleScripting
|
|
60
61
|
exit_data.print_help(output, @long_help)
|
61
62
|
|
62
63
|
nil # to be used with the 'decode(...) || exit' pattern
|
64
|
+
rescue SimpleScripting::Argv::ArgumentError, SimpleScripting::Argv::InvalidCommand, OptionParser::InvalidOption => error
|
65
|
+
if raise_errors
|
66
|
+
raise
|
67
|
+
else
|
68
|
+
output.puts "Command error!: #{error.message}"
|
69
|
+
end
|
63
70
|
ensure
|
64
71
|
@long_help = nil
|
65
72
|
end
|
data/simple_scripting.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.required_ruby_version = '>= 2.3.0'
|
12
12
|
s.authors = ["Saverio Miroddi"]
|
13
|
-
s.date = "2019-
|
13
|
+
s.date = "2019-03-20"
|
14
14
|
s.email = ["saverio.pub2@gmail.com"]
|
15
15
|
s.homepage = "https://github.com/saveriomiroddi/simple_scripting"
|
16
16
|
s.summary = "Library for simplifying some typical scripting functionalities."
|
@@ -67,7 +67,8 @@ describe SimpleScripting::Argv do
|
|
67
67
|
it "should check all the options/arguments when --help is passed, raising an error when they're not correct" do
|
68
68
|
decoder_params.last.merge!(
|
69
69
|
arguments: ['--help'],
|
70
|
-
auto_help: false
|
70
|
+
auto_help: false,
|
71
|
+
raise_errors: true,
|
71
72
|
)
|
72
73
|
|
73
74
|
decoding = -> { described_class.decode(*decoder_params) }
|
@@ -145,16 +146,35 @@ describe SimpleScripting::Argv do
|
|
145
146
|
|
146
147
|
context "error handling" do
|
147
148
|
|
148
|
-
|
149
|
+
# All the other UTs use error raising, for convenience.
|
150
|
+
it "should print the error, with a previx, by default, instead of raising an error" do
|
149
151
|
decoder_params.last[:arguments] = []
|
150
152
|
|
153
|
+
actual_result = described_class.decode(*decoder_params)
|
154
|
+
|
155
|
+
# Returning nil is an important specification, as it's part of the Argv protocol of doing
|
156
|
+
# so in case of problem/exit.
|
157
|
+
expect(actual_result).to be(nil)
|
158
|
+
|
159
|
+
expect(output_buffer.string).to eql("Command error!: Missing mandatory argument(s)\n")
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should raise an error when mandatory arguments are missing" do
|
163
|
+
decoder_params.last.merge!(
|
164
|
+
arguments: [],
|
165
|
+
raise_errors: true,
|
166
|
+
)
|
167
|
+
|
151
168
|
decoding = -> { described_class.decode(*decoder_params) }
|
152
169
|
|
153
170
|
expect(decoding).to raise_error(SimpleScripting::Argv::ArgumentError, "Missing mandatory argument(s)")
|
154
171
|
end
|
155
172
|
|
156
|
-
it "should
|
157
|
-
decoder_params.last
|
173
|
+
it "should raise an error when there are too many arguments" do
|
174
|
+
decoder_params.last.merge!(
|
175
|
+
arguments: ['arg1', 'arg2', 'excessive_arg'],
|
176
|
+
raise_errors: true,
|
177
|
+
)
|
158
178
|
|
159
179
|
decoding = -> { described_class.decode(*decoder_params) }
|
160
180
|
|
@@ -219,7 +239,9 @@ describe SimpleScripting::Argv do
|
|
219
239
|
arguments: [],
|
220
240
|
]}
|
221
241
|
|
222
|
-
it "should
|
242
|
+
it "should raise an error when they are not specified" do
|
243
|
+
decoder_params.last[:raise_errors] = true
|
244
|
+
|
223
245
|
decoding = -> { described_class.decode(*decoder_params) }
|
224
246
|
|
225
247
|
expect(decoding).to raise_error(SimpleScripting::Argv::ArgumentError, "Missing mandatory argument(s)")
|
@@ -292,15 +314,21 @@ describe SimpleScripting::Argv do
|
|
292
314
|
context "error handling" do
|
293
315
|
|
294
316
|
it "should raise an error on invalid command" do
|
295
|
-
decoder_params
|
317
|
+
decoder_params.merge!(
|
318
|
+
arguments: ['pizza'],
|
319
|
+
raise_errors: true,
|
320
|
+
)
|
296
321
|
|
297
322
|
decoding = -> { described_class.decode(decoder_params) }
|
298
323
|
|
299
324
|
expect(decoding).to raise_error(SimpleScripting::Argv::InvalidCommand, "Invalid command: pizza")
|
300
325
|
end
|
301
326
|
|
302
|
-
it "should
|
303
|
-
decoder_params
|
327
|
+
it "should raise a specific error message on missing command" do
|
328
|
+
decoder_params.merge!(
|
329
|
+
arguments: [],
|
330
|
+
raise_errors: true,
|
331
|
+
)
|
304
332
|
|
305
333
|
decoding = -> { described_class.decode(decoder_params) }
|
306
334
|
|
@@ -458,6 +486,7 @@ describe SimpleScripting::Argv do
|
|
458
486
|
|
459
487
|
it 'should avoid options being interpreted as definitions' do
|
460
488
|
decoder_params[:arguments] = ['pizza']
|
489
|
+
decoder_params[:raise_errors] = true
|
461
490
|
|
462
491
|
decoding = -> { described_class.decode(decoder_params) }
|
463
492
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_scripting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Saverio Miroddi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parseconfig
|
@@ -64,7 +64,6 @@ files:
|
|
64
64
|
- ".simplecov"
|
65
65
|
- ".travis.yml"
|
66
66
|
- Gemfile
|
67
|
-
- Gemfile.lock
|
68
67
|
- LICENSE
|
69
68
|
- README.md
|
70
69
|
- Rakefile
|
@@ -101,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
100
|
version: '0'
|
102
101
|
requirements: []
|
103
102
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.7.
|
103
|
+
rubygems_version: 2.7.8
|
105
104
|
signing_key:
|
106
105
|
specification_version: 4
|
107
106
|
summary: Library for simplifying some typical scripting functionalities.
|
data/Gemfile.lock
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
simple_scripting (0.10.1)
|
5
|
-
parseconfig (~> 1.0)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
ast (2.4.0)
|
11
|
-
byebug (10.0.2)
|
12
|
-
coveralls (0.8.21)
|
13
|
-
json (>= 1.8, < 3)
|
14
|
-
simplecov (~> 0.14.1)
|
15
|
-
term-ansicolor (~> 1.3)
|
16
|
-
thor (~> 0.19.4)
|
17
|
-
tins (~> 1.6)
|
18
|
-
diff-lcs (1.3)
|
19
|
-
docile (1.1.5)
|
20
|
-
jaro_winkler (1.5.1)
|
21
|
-
json (2.1.0)
|
22
|
-
parallel (1.12.1)
|
23
|
-
parseconfig (1.0.8)
|
24
|
-
parser (2.5.1.2)
|
25
|
-
ast (~> 2.4.0)
|
26
|
-
powerpack (0.1.2)
|
27
|
-
rainbow (3.0.0)
|
28
|
-
rake (12.0.0)
|
29
|
-
rspec (3.7.0)
|
30
|
-
rspec-core (~> 3.7.0)
|
31
|
-
rspec-expectations (~> 3.7.0)
|
32
|
-
rspec-mocks (~> 3.7.0)
|
33
|
-
rspec-core (3.7.1)
|
34
|
-
rspec-support (~> 3.7.0)
|
35
|
-
rspec-expectations (3.7.0)
|
36
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.7.0)
|
38
|
-
rspec-mocks (3.7.0)
|
39
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.7.0)
|
41
|
-
rspec-support (3.7.1)
|
42
|
-
rubocop (0.58.1)
|
43
|
-
jaro_winkler (~> 1.5.1)
|
44
|
-
parallel (~> 1.10)
|
45
|
-
parser (>= 2.5, != 2.5.1.1)
|
46
|
-
powerpack (~> 0.1)
|
47
|
-
rainbow (>= 2.2.2, < 4.0)
|
48
|
-
ruby-progressbar (~> 1.7)
|
49
|
-
unicode-display_width (~> 1.0, >= 1.0.1)
|
50
|
-
ruby-progressbar (1.9.0)
|
51
|
-
simplecov (0.14.1)
|
52
|
-
docile (~> 1.1.0)
|
53
|
-
json (>= 1.8, < 3)
|
54
|
-
simplecov-html (~> 0.10.0)
|
55
|
-
simplecov-html (0.10.2)
|
56
|
-
term-ansicolor (1.6.0)
|
57
|
-
tins (~> 1.0)
|
58
|
-
thor (0.19.4)
|
59
|
-
tins (1.15.0)
|
60
|
-
unicode-display_width (1.4.0)
|
61
|
-
|
62
|
-
PLATFORMS
|
63
|
-
ruby
|
64
|
-
|
65
|
-
DEPENDENCIES
|
66
|
-
byebug (~> 10.0.2)
|
67
|
-
coveralls (~> 0.8.21)
|
68
|
-
rake (~> 12.0)
|
69
|
-
rspec (~> 3.7)
|
70
|
-
rubocop (= 0.58.1)
|
71
|
-
simple_scripting!
|
72
|
-
|
73
|
-
BUNDLED WITH
|
74
|
-
1.16.1
|