app_archetype 1.2.8 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -1
  3. data/Gemfile.lock +102 -73
  4. data/README.md +166 -29
  5. data/app_archetype.gemspec +22 -19
  6. data/bin/app_archetype +20 -0
  7. data/bin/archetype +1 -1
  8. data/lib/app_archetype/cli.rb +171 -139
  9. data/lib/app_archetype/commands/delete_template.rb +58 -0
  10. data/lib/app_archetype/commands/find_templates.rb +66 -0
  11. data/lib/app_archetype/commands/list_templates.rb +49 -0
  12. data/lib/app_archetype/commands/new_template.rb +42 -0
  13. data/lib/app_archetype/commands/open_manifest.rb +48 -0
  14. data/lib/app_archetype/commands/print_path.rb +20 -0
  15. data/lib/app_archetype/commands/print_template_variables.rb +67 -0
  16. data/lib/app_archetype/commands/print_version.rb +19 -0
  17. data/lib/app_archetype/commands/render_template.rb +178 -0
  18. data/lib/app_archetype/commands.rb +13 -0
  19. data/lib/app_archetype/generators.rb +4 -3
  20. data/lib/app_archetype/template/manifest.rb +17 -1
  21. data/lib/app_archetype/template_manager.rb +13 -6
  22. data/lib/app_archetype/version.rb +1 -1
  23. data/lib/app_archetype.rb +40 -23
  24. data/lib/core_ext/string.rb +18 -12
  25. data/scripts/create_new_command +32 -0
  26. data/scripts/generators/command/manifest.json +15 -0
  27. data/scripts/generators/command/template/lib/app_archetype/commands/{{command_name.snake_case}}.rb.hbs +17 -0
  28. data/spec/app_archetype/cli/presenters_spec.rb +99 -99
  29. data/spec/app_archetype/cli/prompts_spec.rb +291 -291
  30. data/spec/app_archetype/cli_spec.rb +296 -65
  31. data/spec/app_archetype/commands/delete_template_spec.rb +132 -0
  32. data/spec/app_archetype/commands/find_templates_spec.rb +130 -0
  33. data/spec/app_archetype/commands/list_templates_spec.rb +55 -0
  34. data/spec/app_archetype/commands/new_template_spec.rb +84 -0
  35. data/spec/app_archetype/commands/open_manifest_spec.rb +113 -0
  36. data/spec/app_archetype/commands/print_path_spec.rb +22 -0
  37. data/spec/app_archetype/commands/print_template_variables_spec.rb +158 -0
  38. data/spec/app_archetype/commands/print_version_spec.rb +21 -0
  39. data/spec/app_archetype/commands/render_template_spec.rb +479 -0
  40. data/spec/app_archetype/generators_spec.rb +1 -1
  41. data/spec/app_archetype/template/manifest_spec.rb +31 -1
  42. data/spec/app_archetype/template_manager_spec.rb +32 -0
  43. data/spec/app_archetype_spec.rb +65 -0
  44. metadata +155 -80
  45. data/lib/app_archetype/cli/presenters.rb +0 -106
  46. data/lib/app_archetype/cli/prompts.rb +0 -152
@@ -1,292 +1,292 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 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
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
- 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
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