clamp 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fe91eba2afc3a9297ecee33bfaf08a3be3522db
4
- data.tar.gz: 54f0085f58bf85f9cb5d0db0339eaabfe7ffb528
3
+ metadata.gz: 7e919d5a5f983e9de93adeccf16090c2ccf673d6
4
+ data.tar.gz: fcc637ed598db752ac2411970391ff9440e96fcc
5
5
  SHA512:
6
- metadata.gz: ffd0bc644d279f96e68663a0a815ebc0c6825d8cbb4ec69d2fea5315e273fdc587040f1dc761cb51a66362aa6b203789d9c15f56b02bd37c1c98024eaf6b79ff
7
- data.tar.gz: 06a3e512e3bec497227459f93a9dfd7357fd258695f837d1a3ba4569ae2f3bcfeb0561a7d65f8163b5272e0251224017b7e80e64fbe861295223c9ade8ce9e69
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
- command.send(:signal_usage_error, Clamp.message(:env_argument_error, :env => attribute.environment_variable, :message => e.message))
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
@@ -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
- # 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?)
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
 
@@ -1,3 +1,3 @@
1
1
  module Clamp
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "1.2.1".freeze
3
3
  end
@@ -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.0
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 00:00:00.000000000 Z
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.