clamp 1.2.0.beta1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -16
- data/CHANGES.md +1 -1
- data/Gemfile +1 -1
- data/README.md +4 -2
- data/lib/clamp/option/parsing.rb +4 -2
- data/lib/clamp/version.rb +1 -1
- data/spec/clamp/command_spec.rb +28 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fe91eba2afc3a9297ecee33bfaf08a3be3522db
|
4
|
+
data.tar.gz: 54f0085f58bf85f9cb5d0db0339eaabfe7ffb528
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffd0bc644d279f96e68663a0a815ebc0c6825d8cbb4ec69d2fea5315e273fdc587040f1dc761cb51a66362aa6b203789d9c15f56b02bd37c1c98024eaf6b79ff
|
7
|
+
data.tar.gz: 06a3e512e3bec497227459f93a9dfd7357fd258695f837d1a3ba4569ae2f3bcfeb0561a7d65f8163b5272e0251224017b7e80e64fbe861295223c9ade8ce9e69
|
data/.rubocop.yml
CHANGED
@@ -2,6 +2,15 @@ Eval:
|
|
2
2
|
Exclude:
|
3
3
|
- "Rakefile"
|
4
4
|
|
5
|
+
Layout/EmptyLinesAroundBlockBody:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Layout/EmptyLinesAroundClassBody:
|
9
|
+
EnforcedStyle: empty_lines
|
10
|
+
|
11
|
+
Layout/EmptyLinesAroundModuleBody:
|
12
|
+
Enabled: false
|
13
|
+
|
5
14
|
Metrics/AbcSize:
|
6
15
|
Enabled: false
|
7
16
|
|
@@ -11,9 +20,13 @@ Metrics/LineLength:
|
|
11
20
|
Metrics/MethodLength:
|
12
21
|
Max: 30
|
13
22
|
|
14
|
-
|
23
|
+
Naming/AccessorMethodName:
|
15
24
|
Enabled: false
|
16
25
|
|
26
|
+
Naming/FileName:
|
27
|
+
Exclude:
|
28
|
+
- "bin/*"
|
29
|
+
|
17
30
|
Style/ClassAndModuleChildren:
|
18
31
|
EnforcedStyle: nested
|
19
32
|
Exclude:
|
@@ -24,23 +37,9 @@ Style/Documentation:
|
|
24
37
|
- "lib/**/version.rb"
|
25
38
|
- "spec/**/*"
|
26
39
|
|
27
|
-
Style/EmptyLinesAroundBlockBody:
|
28
|
-
Enabled: false
|
29
|
-
|
30
|
-
Style/EmptyLinesAroundClassBody:
|
31
|
-
EnforcedStyle: empty_lines
|
32
|
-
|
33
|
-
Style/EmptyLinesAroundModuleBody:
|
34
|
-
Enabled: false
|
35
|
-
|
36
40
|
Style/Encoding:
|
37
|
-
EnforcedStyle: when_needed
|
38
41
|
Enabled: true
|
39
42
|
|
40
|
-
Style/FileName:
|
41
|
-
Exclude:
|
42
|
-
- "bin/*"
|
43
|
-
|
44
43
|
Style/HashSyntax:
|
45
44
|
EnforcedStyle: hash_rockets
|
46
45
|
|
@@ -50,7 +49,7 @@ Style/Lambda:
|
|
50
49
|
Style/NumericLiterals:
|
51
50
|
Enabled: false
|
52
51
|
|
53
|
-
|
52
|
+
Naming/PredicateName:
|
54
53
|
Enabled: false
|
55
54
|
|
56
55
|
Style/StringLiterals:
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -298,11 +298,13 @@ Clamp will check the specified envariables in the absence of values supplied on
|
|
298
298
|
|
299
299
|
### Allowing options after parameters
|
300
300
|
|
301
|
-
|
301
|
+
By default, Clamp only recognises options _before_ positional parameters.
|
302
|
+
|
303
|
+
Some other option-parsing libraries - notably [GNU `getopt(3)`](https://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html) - allow option and parameter arguments to appear in any order on the command-line, e.g.
|
302
304
|
|
303
305
|
foobar --foo=bar something --fnord=snuffle another-thing
|
304
306
|
|
305
|
-
|
307
|
+
If you want Clamp to allow options and parameters to be "interspersed" in this way, set:
|
306
308
|
|
307
309
|
```ruby
|
308
310
|
Clamp.allow_options_after_parameters = true
|
data/lib/clamp/option/parsing.rb
CHANGED
@@ -69,8 +69,10 @@ module Clamp
|
|
69
69
|
|
70
70
|
def verify_required_options_are_set
|
71
71
|
self.class.recognised_options.each do |option|
|
72
|
-
# If this option is required and the value is nil, there's an error.
|
73
|
-
next unless option.required? &&
|
72
|
+
# If this option is required and the value is nil (or [] for multivalued), there's an error.
|
73
|
+
next unless option.required? &&
|
74
|
+
(!option.multivalued? && send(option.attribute_name).nil?) ||
|
75
|
+
(option.multivalued? && send(option.attribute_name).empty?)
|
74
76
|
if option.environment_variable
|
75
77
|
message = Clamp.message(:option_or_env_required,
|
76
78
|
:option => option.switches.first,
|
data/lib/clamp/version.rb
CHANGED
data/spec/clamp/command_spec.rb
CHANGED
@@ -269,6 +269,34 @@ describe Clamp::Command do
|
|
269
269
|
|
270
270
|
end
|
271
271
|
|
272
|
+
context "with :required and :multivalued" do
|
273
|
+
|
274
|
+
before do
|
275
|
+
command.class.option "--port", "PORT", "port to listen on", :required => true, :multivalued => true
|
276
|
+
end
|
277
|
+
|
278
|
+
context "when no value is provided" do
|
279
|
+
|
280
|
+
it "raises a UsageError" do
|
281
|
+
expect do
|
282
|
+
command.parse([])
|
283
|
+
end.to raise_error(Clamp::UsageError)
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
288
|
+
context "when a value is provided" do
|
289
|
+
|
290
|
+
it "does not raise an error" do
|
291
|
+
expect do
|
292
|
+
command.parse(["--port", "12345"])
|
293
|
+
end.not_to raise_error
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
|
272
300
|
context "with a block" do
|
273
301
|
|
274
302
|
before do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Clamp provides an object-model for command-line utilities.
|
@@ -82,9 +82,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- - "
|
85
|
+
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
87
|
+
version: '0'
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
90
|
rubygems_version: 2.6.13
|