clamp 1.2.0 → 1.2.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/lib/clamp/attribute/definition.rb +11 -0
- data/lib/clamp/attribute/instance.rb +21 -1
- data/lib/clamp/option/parsing.rb +1 -13
- data/lib/clamp/version.rb +1 -1
- data/spec/clamp/command_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e919d5a5f983e9de93adeccf16090c2ccf673d6
|
4
|
+
data.tar.gz: fcc637ed598db752ac2411970391ff9440e96fcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc3d0c1e9a7172ab3a0f8d09cc0583aec4f03ee8a85db033d2e0c413a03a7455ddc1c1cca622781620a28ab47148ebe9b3245d54ac533278bc0398e767dc558b
|
7
|
+
data.tar.gz: 9551a0bbae48288c19b9ac5a2f1918753620d4deefd8efc1e47fa5206c9911e9ee80aa60223f017133e7ff545d8d61624ff1308fb17a9412d2c1724ee6623c9b
|
@@ -74,6 +74,17 @@ module Clamp
|
|
74
74
|
Attribute::Instance.new(self, command)
|
75
75
|
end
|
76
76
|
|
77
|
+
def option_missing_message
|
78
|
+
if environment_variable
|
79
|
+
Clamp.message(:option_or_env_required,
|
80
|
+
:option => switches.first,
|
81
|
+
:env => environment_variable)
|
82
|
+
else
|
83
|
+
Clamp.message(:option_required,
|
84
|
+
:option => switches.first)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
77
88
|
private
|
78
89
|
|
79
90
|
def default_description
|
@@ -60,6 +60,10 @@ module Clamp
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
def signal_usage_error(*args)
|
64
|
+
command.send(:signal_usage_error, *args)
|
65
|
+
end
|
66
|
+
|
63
67
|
def default_from_environment
|
64
68
|
return if self.defined?
|
65
69
|
return if attribute.environment_variable.nil?
|
@@ -69,10 +73,26 @@ module Clamp
|
|
69
73
|
begin
|
70
74
|
take(value)
|
71
75
|
rescue ArgumentError => e
|
72
|
-
|
76
|
+
signal_usage_error Clamp.message(:env_argument_error, :env => attribute.environment_variable, :message => e.message)
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
80
|
+
def unset?
|
81
|
+
if attribute.multivalued?
|
82
|
+
read.empty?
|
83
|
+
else
|
84
|
+
read.nil?
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def missing?
|
89
|
+
attribute.required? && unset?
|
90
|
+
end
|
91
|
+
|
92
|
+
def verify_not_missing
|
93
|
+
signal_usage_error attribute.option_missing_message if missing?
|
94
|
+
end
|
95
|
+
|
76
96
|
end
|
77
97
|
|
78
98
|
end
|
data/lib/clamp/option/parsing.rb
CHANGED
@@ -69,19 +69,7 @@ module Clamp
|
|
69
69
|
|
70
70
|
def verify_required_options_are_set
|
71
71
|
self.class.recognised_options.each do |option|
|
72
|
-
|
73
|
-
next unless option.required? &&
|
74
|
-
(!option.multivalued? && send(option.attribute_name).nil?) ||
|
75
|
-
(option.multivalued? && send(option.attribute_name).empty?)
|
76
|
-
if option.environment_variable
|
77
|
-
message = Clamp.message(:option_or_env_required,
|
78
|
-
:option => option.switches.first,
|
79
|
-
:env => option.environment_variable)
|
80
|
-
else
|
81
|
-
message = Clamp.message(:option_required,
|
82
|
-
:option => option.switches.first)
|
83
|
-
end
|
84
|
-
signal_usage_error message
|
72
|
+
option.of(self).verify_not_missing
|
85
73
|
end
|
86
74
|
end
|
87
75
|
|
data/lib/clamp/version.rb
CHANGED
data/spec/clamp/command_spec.rb
CHANGED
@@ -139,6 +139,12 @@ describe Clamp::Command do
|
|
139
139
|
expect(command.flavours).to eql %w(mud pie)
|
140
140
|
end
|
141
141
|
|
142
|
+
it "does not require a value" do
|
143
|
+
expect do
|
144
|
+
command.parse([])
|
145
|
+
end.not_to raise_error
|
146
|
+
end
|
147
|
+
|
142
148
|
end
|
143
149
|
|
144
150
|
context "with :environment_variable" 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.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Clamp provides an object-model for command-line utilities.
|