cliutils 2.2.2 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +6 -0
- data/lib/cliutils/constants.rb +1 -1
- data/lib/cliutils/messenger.rb +1 -1
- data/lib/cliutils/prefs/pref.rb +16 -19
- data/spec/pref_spec.rb +18 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74dcd411f3846055d59b17657ce5fc4664abca70
|
4
|
+
data.tar.gz: 85d369daafb30cf5f5a0110b783928a00ebd4f90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99aeb8fcb77f0cfdc5bad45727ad37861bb454e5e8442d2fd8c6fd3c0eefacd3f0229da51dcbf1a93f8b1dbb3eb1c419de6af15ed422d149810bf2737a23862b
|
7
|
+
data.tar.gz: 829b1e7e5275f456effead9406e9d04241b321d40791d77c37b5715e9ee4ea031ed30e81d6352533a68109fcb35dd61045946bfd8c01f8168fb286dfe6101473
|
data/HISTORY.md
CHANGED
data/lib/cliutils/constants.rb
CHANGED
data/lib/cliutils/messenger.rb
CHANGED
data/lib/cliutils/prefs/pref.rb
CHANGED
@@ -187,39 +187,35 @@ module CLIUtils
|
|
187
187
|
ret
|
188
188
|
end
|
189
189
|
|
190
|
-
|
191
|
-
|
192
|
-
def _eval_pre
|
193
|
-
messenger.info(@pre[:message])
|
190
|
+
def _eval_action(type = 'pre')
|
191
|
+
messenger.info(instance_variable_get("@#{ type }")[:message])
|
194
192
|
messenger.prompt('Press enter to continue')
|
195
193
|
|
196
|
-
if (
|
197
|
-
action_obj = _init_action(
|
194
|
+
if instance_variable_get("@#{ type }")[:action]
|
195
|
+
action_obj = _init_action(instance_variable_get("@#{ type }")[:action])
|
198
196
|
action_obj.run if action_obj
|
199
197
|
end
|
200
198
|
end
|
201
199
|
|
200
|
+
# Evaluates the pre-prompt Hash and does the right thing. :)
|
201
|
+
# @return [void]
|
202
|
+
def _eval_pre
|
203
|
+
_eval_action('pre')
|
204
|
+
end
|
205
|
+
|
202
206
|
# Evaluates the post-prompt Hash and does the right thing. :)
|
203
207
|
# @return [void]
|
204
208
|
def _eval_post
|
205
|
-
|
206
|
-
messenger.prompt('Press enter to continue')
|
207
|
-
|
208
|
-
if (@post[:action])
|
209
|
-
action_obj = _init_action(@post[:action])
|
210
|
-
action_obj.run if action_obj
|
211
|
-
end
|
209
|
+
_eval_action('post')
|
212
210
|
end
|
213
211
|
|
214
212
|
# Attempts to instantiate a Pre or Post Action based on name; if
|
215
213
|
# successful, the new object gets placed in @validator_objects
|
216
|
-
# @param [
|
214
|
+
# @param [Hash] action_hash The hash of action data (name, params, etc.)
|
217
215
|
# @return [void]
|
218
|
-
def _init_action(
|
219
|
-
obj = _load_asset(ASSET_TYPE_ACTION,
|
220
|
-
|
221
|
-
obj.parameters = @pre[:parameters]
|
222
|
-
end
|
216
|
+
def _init_action(action_hash)
|
217
|
+
obj = _load_asset(ASSET_TYPE_ACTION, action_hash[:name])
|
218
|
+
obj.parameters = action_hash[:parameters]
|
223
219
|
obj
|
224
220
|
end
|
225
221
|
|
@@ -254,6 +250,7 @@ module CLIUtils
|
|
254
250
|
# @return [Object]
|
255
251
|
def _load_asset(type, path_or_name)
|
256
252
|
asset_found = false
|
253
|
+
|
257
254
|
if File.file?(File.expand_path(path_or_name))
|
258
255
|
# If the file exists, we're assuming that the user
|
259
256
|
# passed a filepath.
|
data/spec/pref_spec.rb
CHANGED
@@ -20,14 +20,18 @@ describe CLIUtils::Pref do
|
|
20
20
|
options: ['bachya'],
|
21
21
|
pre: {
|
22
22
|
message: 'Test pre message',
|
23
|
-
action:
|
24
|
-
|
25
|
-
|
23
|
+
action: {
|
24
|
+
name: "#{ File.join(base_path, 'test_action.rb') }",
|
25
|
+
parameters: {
|
26
|
+
param1: 'value1'
|
27
|
+
}
|
26
28
|
}
|
27
29
|
},
|
28
30
|
post: {
|
29
31
|
message: 'Test post message',
|
30
|
-
action:
|
32
|
+
action: {
|
33
|
+
name: "#{ File.join(base_path, 'test_action.rb') }"
|
34
|
+
}
|
31
35
|
},
|
32
36
|
prereqs: [
|
33
37
|
{ config_section: 'section' },
|
@@ -47,14 +51,18 @@ describe CLIUtils::Pref do
|
|
47
51
|
options: ['bachya'],
|
48
52
|
pre: {
|
49
53
|
message: 'Test pre message',
|
50
|
-
action:
|
51
|
-
|
52
|
-
|
54
|
+
action: {
|
55
|
+
name: 'test',
|
56
|
+
parameters: {
|
57
|
+
param1: 'value1'
|
58
|
+
}
|
53
59
|
}
|
54
60
|
},
|
55
61
|
post: {
|
56
62
|
message: 'Test post message',
|
57
|
-
action:
|
63
|
+
action: {
|
64
|
+
name: 'test'
|
65
|
+
}
|
58
66
|
},
|
59
67
|
prereqs: [
|
60
68
|
{ config_section: 'section' },
|
@@ -94,8 +102,8 @@ describe CLIUtils::Pref do
|
|
94
102
|
expect(pref.default).to eq(pref_data[:default])
|
95
103
|
expect(pref.last_error_message).to eq(nil)
|
96
104
|
expect(pref.options).to eq(['bachya'])
|
97
|
-
expect(pref.post).to eq({
|
98
|
-
expect(pref.pre).to eq({message: 'Test pre message', action:
|
105
|
+
expect(pref.post).to eq({message: 'Test post message', action: { name: '/Users/abach/Git/cliutils/spec/../support/test_action.rb' } })
|
106
|
+
expect(pref.pre).to eq({message: 'Test pre message', action: { name: '/Users/abach/Git/cliutils/spec/../support/test_action.rb', parameters: { param1: 'value1'} } })
|
99
107
|
expect(pref.prereqs).to eq([{ config_section: 'section' }, { config_value: 'value' }])
|
100
108
|
expect(pref.validator_objects[0].class).to eq(CLIUtils::TestValidator)
|
101
109
|
expect(pref.validators).to eq([File.join(base_path, 'test_validator.rb')])
|