app_archetype 1.2.8 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +36 -9
- data/README.md +150 -28
- data/app_archetype.gemspec +3 -0
- data/bin/app_archetype +20 -0
- data/bin/archetype +1 -1
- data/lib/app_archetype/cli.rb +171 -139
- data/lib/app_archetype/commands/delete_template.rb +58 -0
- data/lib/app_archetype/commands/find_templates.rb +66 -0
- data/lib/app_archetype/commands/list_templates.rb +49 -0
- data/lib/app_archetype/commands/new_template.rb +42 -0
- data/lib/app_archetype/commands/open_manifest.rb +48 -0
- data/lib/app_archetype/commands/print_path.rb +20 -0
- data/lib/app_archetype/commands/print_template_variables.rb +67 -0
- data/lib/app_archetype/commands/print_version.rb +19 -0
- data/lib/app_archetype/commands/render_template.rb +178 -0
- data/lib/app_archetype/commands.rb +13 -0
- data/lib/app_archetype/generators.rb +1 -1
- data/lib/app_archetype/template_manager.rb +9 -0
- data/lib/app_archetype/version.rb +1 -1
- data/lib/app_archetype.rb +40 -23
- data/scripts/create_new_command +32 -0
- data/scripts/generators/command/manifest.json +15 -0
- data/scripts/generators/command/template/lib/app_archetype/commands/{{command_name.snake_case}}.rb.hbs +17 -0
- data/spec/app_archetype/cli/presenters_spec.rb +99 -99
- data/spec/app_archetype/cli/prompts_spec.rb +291 -291
- data/spec/app_archetype/cli_spec.rb +427 -65
- data/spec/app_archetype/commands/delete_template_spec.rb +132 -0
- data/spec/app_archetype/commands/find_templates_spec.rb +130 -0
- data/spec/app_archetype/commands/list_templates_spec.rb +55 -0
- data/spec/app_archetype/commands/new_template_spec.rb +84 -0
- data/spec/app_archetype/commands/open_manifest_spec.rb +113 -0
- data/spec/app_archetype/commands/print_path_spec.rb +22 -0
- data/spec/app_archetype/commands/print_template_variables_spec.rb +158 -0
- data/spec/app_archetype/commands/print_version_spec.rb +21 -0
- data/spec/app_archetype/commands/render_template_spec.rb +479 -0
- data/spec/app_archetype/generators_spec.rb +1 -1
- data/spec/app_archetype/template_manager_spec.rb +32 -0
- data/spec/app_archetype_spec.rb +65 -0
- metadata +79 -4
- data/lib/app_archetype/cli/presenters.rb +0 -106
- data/lib/app_archetype/cli/prompts.rb +0 -152
@@ -1,292 +1,292 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
1
|
+
# require 'spec_helper'
|
2
|
+
|
3
|
+
# RSpec.xdescribe AppArchetype::CLI::Prompts do
|
4
|
+
# let(:var_name) { 'foo' }
|
5
|
+
# let(:var_type) { 'string' }
|
6
|
+
# let(:var_desc) { 'a foo' }
|
7
|
+
# let(:var_default) { 'bar' }
|
8
|
+
# let(:var_value) { nil }
|
9
|
+
|
10
|
+
# let(:variable) do
|
11
|
+
# double(
|
12
|
+
# AppArchetype::Template::Variable,
|
13
|
+
# name: var_name,
|
14
|
+
# description: var_desc,
|
15
|
+
# type: var_type,
|
16
|
+
# default: var_default,
|
17
|
+
# value: var_value
|
18
|
+
# )
|
19
|
+
# end
|
20
|
+
|
21
|
+
# describe '::VAR_PROMPT_MESSAGE' do
|
22
|
+
# before do
|
23
|
+
# @prompt = described_class::VAR_PROMPT_MESSAGE.call(variable)
|
24
|
+
# end
|
25
|
+
|
26
|
+
# it 'displays prompt' do
|
27
|
+
# expect(
|
28
|
+
# @prompt.include?("Enter value for `#{var_name}` variable")
|
29
|
+
# ).to be true
|
30
|
+
# end
|
31
|
+
|
32
|
+
# it 'displays variable description' do
|
33
|
+
# expect(@prompt.include?("DESCRIPTION: #{var_desc}")).to be true
|
34
|
+
# end
|
35
|
+
|
36
|
+
# it 'displays variable type' do
|
37
|
+
# expect(@prompt.include?("TYPE: #{var_type}")).to be true
|
38
|
+
# end
|
39
|
+
|
40
|
+
# it 'displays variable default' do
|
41
|
+
# expect(@prompt.include?("DEFAULT: #{var_default}")).to be true
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
|
45
|
+
# describe '.prompt' do
|
46
|
+
# it 'returns a prompt' do
|
47
|
+
# expect(described_class.prompt).to be_a(HighLine)
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
|
51
|
+
# describe '.yes?' do
|
52
|
+
# let(:prompt) { double(HighLine) }
|
53
|
+
# let(:message) { 'Would you like to do stuff?' }
|
54
|
+
# let(:response) { 'Y' }
|
55
|
+
|
56
|
+
# before do
|
57
|
+
# allow(subject).to receive(:prompt).and_return(prompt)
|
58
|
+
# allow(prompt).to receive(:ask).and_yield(response)
|
59
|
+
|
60
|
+
# @resp = subject.yes?(message)
|
61
|
+
# end
|
62
|
+
|
63
|
+
# it 'asks question' do
|
64
|
+
# expect(prompt).to have_received(:ask).with("#{message} [Y/n]", String)
|
65
|
+
# end
|
66
|
+
|
67
|
+
# it 'returns true when user responds Y' do
|
68
|
+
# expect(@resp).to be true
|
69
|
+
# end
|
70
|
+
|
71
|
+
# context 'when user inputs anything other than Y' do
|
72
|
+
# let(:response) { 'Nope' }
|
73
|
+
|
74
|
+
# it 'returns false' do
|
75
|
+
# expect(@resp).to be false
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
|
80
|
+
# describe '.ask' do
|
81
|
+
# let(:prompt) { double(HighLine) }
|
82
|
+
|
83
|
+
# let(:message) { 'Give me some info' }
|
84
|
+
# let(:validator) { String }
|
85
|
+
# let(:default) { 'Default' }
|
86
|
+
|
87
|
+
# let(:response) { 'Sure here it is' }
|
88
|
+
|
89
|
+
# before do
|
90
|
+
# allow(subject).to receive(:prompt).and_return(prompt)
|
91
|
+
# allow(prompt).to receive(:ask).and_return(response)
|
92
|
+
|
93
|
+
# @resp = subject.ask(message, validator: validator, default: default)
|
94
|
+
# end
|
95
|
+
|
96
|
+
# it 'asks question with validator' do
|
97
|
+
# expect(prompt).to have_received(:ask).with(message, validator)
|
98
|
+
# end
|
99
|
+
|
100
|
+
# it 'returns user response as string' do
|
101
|
+
# expect(@resp).to eq response
|
102
|
+
# end
|
103
|
+
|
104
|
+
# context 'when default is specifed and empty response' do
|
105
|
+
# let(:response) { '' }
|
106
|
+
|
107
|
+
# it 'returns default' do
|
108
|
+
# expect(@resp).to eq default
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
|
112
|
+
# context 'when empty and no default specified' do
|
113
|
+
# let(:default) { nil }
|
114
|
+
# let(:response) { '' }
|
115
|
+
|
116
|
+
# it 'returns empty string' do
|
117
|
+
# expect(@resp).to eq ''
|
118
|
+
# end
|
119
|
+
# end
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
end
|
121
|
+
# context 'when asking for an integer' do
|
122
|
+
# let(:response) { 1 }
|
123
|
+
# let(:validator) { Integer }
|
124
|
+
|
125
|
+
# it 'returns user response as integer' do
|
126
|
+
# expect(@resp).to eq 1
|
127
|
+
# end
|
128
|
+
# end
|
129
|
+
# end
|
130
|
+
|
131
|
+
# describe '.delete_template' do
|
132
|
+
# let(:prompt) { double(HighLine) }
|
133
|
+
|
134
|
+
# let(:manifest_name) { 'test_manifest' }
|
135
|
+
# let(:manifest) do
|
136
|
+
# double(AppArchetype::Template::Manifest, name: manifest_name)
|
137
|
+
# end
|
138
|
+
|
139
|
+
# let(:choice) { false }
|
140
|
+
|
141
|
+
# before do
|
142
|
+
# allow(subject).to receive(:prompt).and_return(prompt)
|
143
|
+
# allow(subject).to receive(:yes?).and_return(choice)
|
144
|
+
|
145
|
+
# @result = described_class.delete_template(manifest)
|
146
|
+
# end
|
147
|
+
|
148
|
+
# it 'asks if it is okay to delete template' do
|
149
|
+
# expect(subject).to have_received(:yes?)
|
150
|
+
# .with('Are you sure you want to delete `test_manifest`?')
|
151
|
+
# end
|
152
|
+
|
153
|
+
# it 'returns user choice' do
|
154
|
+
# expect(@result).to eq choice
|
155
|
+
# end
|
156
|
+
# end
|
157
|
+
|
158
|
+
# describe '.variable_prompt_for' do
|
159
|
+
# let(:has_value) { false }
|
160
|
+
|
161
|
+
# before do
|
162
|
+
# allow(variable).to receive(:value?).and_return(has_value)
|
163
|
+
|
164
|
+
# allow(described_class).to receive(:boolean_variable_prompt)
|
165
|
+
# allow(described_class).to receive(:integer_variable_prompt)
|
166
|
+
# allow(described_class).to receive(:string_variable_prompt)
|
167
|
+
# end
|
168
|
+
|
169
|
+
# context 'when variable value is set' do
|
170
|
+
# let(:has_value) { true }
|
171
|
+
# let(:var_value) { 'some-value' }
|
172
|
+
|
173
|
+
# it 'returns value' do
|
174
|
+
# expect(
|
175
|
+
# described_class.variable_prompt_for(variable)
|
176
|
+
# ).to eq var_value
|
177
|
+
# end
|
178
|
+
# end
|
179
|
+
|
180
|
+
# context 'when variable type is a boolean' do
|
181
|
+
# let(:var_type) { 'boolean' }
|
182
|
+
|
183
|
+
# before { described_class.variable_prompt_for(variable) }
|
184
|
+
|
185
|
+
# it 'calls boolean variable prompt' do
|
186
|
+
# expect(described_class)
|
187
|
+
# .to have_received(:boolean_variable_prompt)
|
188
|
+
# .with(variable)
|
189
|
+
# end
|
190
|
+
# end
|
191
|
+
|
192
|
+
# context 'when variable type is an integer' do
|
193
|
+
# let(:var_type) { 'integer' }
|
194
|
+
|
195
|
+
# before { described_class.variable_prompt_for(variable) }
|
196
|
+
|
197
|
+
# it 'calls integer variable prompt' do
|
198
|
+
# expect(described_class)
|
199
|
+
# .to have_received(:integer_variable_prompt)
|
200
|
+
# .with(variable)
|
201
|
+
# end
|
202
|
+
# end
|
203
|
+
|
204
|
+
# context 'when variable type is a string' do
|
205
|
+
# let(:var_type) { 'string' }
|
206
|
+
|
207
|
+
# before { described_class.variable_prompt_for(variable) }
|
208
|
+
|
209
|
+
# it 'calls string variable prompt' do
|
210
|
+
# expect(described_class)
|
211
|
+
# .to have_received(:string_variable_prompt)
|
212
|
+
# .with(variable)
|
213
|
+
# end
|
214
|
+
# end
|
215
|
+
|
216
|
+
# context 'treats variables as strings by default' do
|
217
|
+
# let(:var_type) { nil }
|
218
|
+
|
219
|
+
# before { described_class.variable_prompt_for(variable) }
|
220
|
+
|
221
|
+
# it 'calls string variable prompt' do
|
222
|
+
# expect(described_class)
|
223
|
+
# .to have_received(:string_variable_prompt)
|
224
|
+
# .with(variable)
|
225
|
+
# end
|
226
|
+
# end
|
227
|
+
# end
|
228
|
+
|
229
|
+
# describe '.boolean_variable_prompt' do
|
230
|
+
# let(:choice) { false }
|
231
|
+
|
232
|
+
# before do
|
233
|
+
# allow(subject).to receive(:yes?).and_return(choice)
|
234
|
+
# @result = described_class.boolean_variable_prompt(variable)
|
235
|
+
# end
|
236
|
+
|
237
|
+
# it 'asks for boolean input' do
|
238
|
+
# expect(subject).to have_received(:yes?)
|
239
|
+
# .with(
|
240
|
+
# AppArchetype::CLI::Prompts::VAR_PROMPT_MESSAGE.call(variable)
|
241
|
+
# )
|
242
|
+
# end
|
243
|
+
|
244
|
+
# it 'returns user choice' do
|
245
|
+
# expect(@result).to eq choice
|
246
|
+
# end
|
247
|
+
# end
|
248
|
+
|
249
|
+
# describe '.integer_variable_prompt' do
|
250
|
+
# let(:choice) { 1 }
|
251
|
+
|
252
|
+
# before do
|
253
|
+
# allow(subject).to receive(:ask).and_return(choice)
|
254
|
+
# @result = described_class.integer_variable_prompt(variable)
|
255
|
+
# end
|
256
|
+
|
257
|
+
# it 'asks for boolean input' do
|
258
|
+
# expect(subject).to have_received(:ask)
|
259
|
+
# .with(
|
260
|
+
# AppArchetype::CLI::Prompts::VAR_PROMPT_MESSAGE.call(variable),
|
261
|
+
# default: variable.default,
|
262
|
+
# validator: Integer
|
263
|
+
# )
|
264
|
+
# end
|
265
|
+
|
266
|
+
# it 'returns user choice' do
|
267
|
+
# expect(@result).to eq choice
|
268
|
+
# end
|
269
|
+
# end
|
270
|
+
|
271
|
+
# describe '.string_variable_prompt' do
|
272
|
+
# let(:choice) { 'some string' }
|
273
|
+
|
274
|
+
# before do
|
275
|
+
# allow(subject).to receive(:ask).and_return(choice)
|
276
|
+
|
277
|
+
# @result = described_class.string_variable_prompt(variable)
|
278
|
+
# end
|
279
|
+
|
280
|
+
# it 'asks for boolean input' do
|
281
|
+
# expect(subject).to have_received(:ask)
|
282
|
+
# .with(
|
283
|
+
# AppArchetype::CLI::Prompts::VAR_PROMPT_MESSAGE.call(variable),
|
284
|
+
# default: variable.default
|
285
|
+
# )
|
286
|
+
# end
|
287
|
+
|
288
|
+
# it 'returns user choice' do
|
289
|
+
# expect(@result).to eq choice
|
290
|
+
# end
|
291
|
+
# end
|
292
|
+
# end
|