wip-runner 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,28 +5,24 @@ module WIP
5
5
  module Runner
6
6
  module Workflow
7
7
  class Runner
8
- def initialize(io, workflow)
9
- @io = io
8
+ def initialize(ui, workflow)
9
+ @ui = ui
10
10
  @workflow = workflow
11
11
  end
12
12
 
13
13
  def run(options)
14
- indent_size = @io.indent_size
15
- @io.indent_size = 2
16
14
  @options = options
17
15
  @context = []
18
16
  @env = {}
19
17
 
20
18
  process_overview
21
19
  process_workflow unless @options.overview
22
-
23
- @io.indent_size = indent_size
24
20
  end
25
21
 
26
22
  private
27
23
 
28
24
  def stylize(text, style)
29
- stylize? ? @io.color(text, style) : text
25
+ stylize? ? @ui.out { @ui.color(text, style) } : text
30
26
  end
31
27
 
32
28
  def stylize?
@@ -34,37 +30,41 @@ module WIP
34
30
  end
35
31
 
36
32
  def process_overview
37
- @io.newline
38
- @io.indent do
39
- @io.say "# #{stylize(@workflow.heading, :underline)}"
40
-
41
- unless @workflow.overview.nil?
42
- @io.newline
43
- @io.say @workflow.overview
44
- end
33
+ @ui.out {
34
+ @ui.newline
35
+ @ui.indent do
36
+ @ui.say "# #{stylize(@workflow.heading, :underline)}"
37
+
38
+ unless @workflow.overview.nil?
39
+ @ui.newline
40
+ @ui.say @workflow.overview
41
+ end
45
42
 
46
- unless @workflow.prologue.nil?
47
- @io.newline
48
- @io.say @workflow.prologue
43
+ unless @workflow.prologue.nil?
44
+ @ui.newline
45
+ @ui.say @workflow.prologue
46
+ end
49
47
  end
50
- end
48
+ }
51
49
  end
52
50
 
53
51
  def process_workflow
54
52
  @context.push({ sources: [] })
55
53
 
56
- @io.indent do
57
- process_configs unless @options.preview
58
- process_guards unless @options.preview
54
+ @ui.out {
55
+ @ui.indent do
56
+ process_configs unless @options.preview
57
+ process_guards unless @options.preview
59
58
 
60
- @workflow.shells.each do |mode, content|
61
- process_shell(content, mode)
62
- end
59
+ @workflow.shells.each do |mode, content|
60
+ process_shell(content, mode)
61
+ end
63
62
 
64
- @workflow.tasks.each do |task|
65
- process_task(task)
63
+ @workflow.tasks.each do |task|
64
+ process_task(task)
65
+ end
66
66
  end
67
- end
67
+ }
68
68
 
69
69
  @context.pop
70
70
  rescue GuardError, HaltSignal
@@ -74,8 +74,10 @@ module WIP
74
74
  def process_task(task, overview = true)
75
75
  process_block('##', task, overview, :underline) do
76
76
  if overview && ! (task.shells.empty? && task.steps.empty?)
77
- @io.newline
78
- @io.say 'Steps...'
77
+ @ui.out {
78
+ @ui.newline
79
+ @ui.say 'Steps...'
80
+ }
79
81
  end
80
82
 
81
83
  if @options.preview
@@ -87,58 +89,62 @@ module WIP
87
89
  process_step(step)
88
90
  end
89
91
  else
90
- if overview
91
- @options.preview = true
92
- task.shells.each do |mode, content|
93
- process_shell(content, mode)
94
- end
95
- @options.preview = false
96
-
97
- task.steps.each do |step|
98
- @io.newline
99
- @io.say("- [ ] #{step.heading}")
100
- end
101
- end
102
-
103
- @io.newline
104
- choice = @io.choose('yes', 'no', 'skip', 'step', 'preview') do |menu|
105
- menu.header = 'Continue?'
106
- menu.flow = :inline
107
- menu.index = :none
108
- end
92
+ @ui.out {
93
+ if overview
94
+ @options.preview = true
95
+ task.shells.each do |mode, content|
96
+ process_shell(content, mode)
97
+ end
98
+ @options.preview = false
109
99
 
110
- case choice
111
- when 'yes'
112
- proceed_with_task(task)
113
- when 'no'
114
- raise HaltSignal
115
- when 'skip'
116
- @io.indent_level -= 1
117
- return
118
- when 'step'
119
- @options.stepwise = true
120
- task.shells.each do |mode, content|
121
- process_shell(content, mode)
100
+ task.steps.each do |step|
101
+ @ui.newline
102
+ @ui.say("- [ ] #{step.heading}")
103
+ end
122
104
  end
123
105
 
124
- task.steps.each do |step|
125
- process_step(step)
126
- end
127
- @options.stepwise = false
128
- when 'preview'
129
- @options.preview = true
130
- task.shells.each do |mode, content|
131
- process_shell(content, mode)
132
- end
133
- task.steps.each do |step|
134
- process_step(step)
135
- end
136
- @options.preview = false
106
+ @ui.newline
107
+ @ui.err {
108
+ choice = @ui.choose('yes', 'no', 'skip', 'step', 'preview') do |menu|
109
+ menu.header = 'Continue?'
110
+ menu.flow = :inline
111
+ menu.index = :none
112
+ end
137
113
 
138
- @io.indent(-1) do
139
- process_task(task, false)
140
- end
141
- end
114
+ case choice
115
+ when 'yes'
116
+ proceed_with_task(task)
117
+ when 'no'
118
+ raise HaltSignal
119
+ when 'skip'
120
+ @ui.indent_level -= 1
121
+ return
122
+ when 'step'
123
+ @options.stepwise = true
124
+ task.shells.each do |mode, content|
125
+ process_shell(content, mode)
126
+ end
127
+
128
+ task.steps.each do |step|
129
+ process_step(step)
130
+ end
131
+ @options.stepwise = false
132
+ when 'preview'
133
+ @options.preview = true
134
+ task.shells.each do |mode, content|
135
+ process_shell(content, mode)
136
+ end
137
+ task.steps.each do |step|
138
+ process_step(step)
139
+ end
140
+ @options.preview = false
141
+
142
+ @ui.indent(-1) do
143
+ process_task(task, false)
144
+ end
145
+ end
146
+ }
147
+ }
142
148
  end
143
149
  end
144
150
  end
@@ -157,24 +163,24 @@ module WIP
157
163
  end
158
164
  @options.preview = false
159
165
 
160
- @io.newline
161
- choice = @io.choose('yes', 'no', 'skip') do |menu|
162
- menu.header = 'Continue?'
163
- menu.flow = :inline
164
- menu.index = :none
165
- end
166
-
167
- case choice
168
- when 'yes'
169
- proceed_with_step(step)
170
- when 'no'
171
- raise HaltSignal
172
- when 'skip'
173
- @io.indent_level -= 1
174
- return
175
- end
176
-
166
+ @ui.err {
167
+ @ui.newline
168
+ choice = @ui.choose('yes', 'no', 'skip') do |menu|
169
+ menu.header = 'Continue?'
170
+ menu.flow = :inline
171
+ menu.index = :none
172
+ end
177
173
 
174
+ case choice
175
+ when 'yes'
176
+ proceed_with_step(step)
177
+ when 'no'
178
+ raise HaltSignal
179
+ when 'skip'
180
+ @ui.indent_level -= 1
181
+ return
182
+ end
183
+ }
178
184
  else
179
185
  proceed_with_step(step)
180
186
  end
@@ -184,23 +190,25 @@ module WIP
184
190
 
185
191
  def process_configs
186
192
  unless @workflow.configs.empty?
187
- @io.newline
188
- @io.say "## #{stylize('Configuration', :underline)}"
189
- @io.indent do
190
- @io.newline
191
- @io.say 'Please provide values for the following...'
192
-
193
- @workflow.configs.each do |key, options|
194
- answer = @io.ask("- #{key}: ") do |q|
195
- q.default = (options[:default] || ENV[key])
196
- if options[:required]
197
- # q.validate = Proc.new { |a| ! a.empty? }
198
- q.validate = /^.+$/
193
+ @ui.err {
194
+ @ui.newline
195
+ @ui.say "## #{stylize('Configuration', :underline)}"
196
+ @ui.indent do
197
+ @ui.newline
198
+ @ui.say 'Please provide values for the following...'
199
+
200
+ @workflow.configs.each do |key, options|
201
+ answer = @ui.ask("- #{key}: ") do |q|
202
+ q.default = (options[:default] || ENV[key])
203
+ if options[:required]
204
+ # q.validate = Proc.new { |a| ! a.empty? }
205
+ q.validate = /^.+$/
206
+ end
199
207
  end
208
+ @env[key] = answer unless answer.empty?
200
209
  end
201
- @env[key] = answer unless answer.empty?
202
210
  end
203
- end
211
+ }
204
212
  end
205
213
  end
206
214
 
@@ -233,23 +241,25 @@ module WIP
233
241
  end
234
242
 
235
243
  def process_block(prefix, component, overview = true, style = nil)
236
- @context.push({ sources: [] })
244
+ @ui.out {
245
+ @context.push({ sources: [] })
237
246
 
238
- if overview
239
- @io.newline
240
- @io.say("#{prefix} #{stylize(component.heading, style)}")
241
- end
247
+ if overview
248
+ @ui.newline
249
+ @ui.say("#{prefix} #{stylize(component.heading, style)}")
250
+ end
242
251
 
243
- @io.indent do
244
- unless component.prologue.nil?
245
- @io.newline
246
- @io.say component.prologue
247
- end if overview
252
+ @ui.indent do
253
+ unless component.prologue.nil?
254
+ @ui.newline
255
+ @ui.say component.prologue
256
+ end if overview
248
257
 
249
- yield if block_given?
250
- end
258
+ yield if block_given?
259
+ end
251
260
 
252
- @context.pop
261
+ @context.pop
262
+ }
253
263
  end
254
264
 
255
265
  def process_shell(content, mode)
@@ -270,14 +280,16 @@ module WIP
270
280
  prefix = '→ '
271
281
  end
272
282
 
273
- @io.newline
274
- content.split("\n").each do |action|
275
- if action.empty?
276
- @io.newline
277
- else
278
- @io.say("#{prefix}#{stylize(action, :bold)}")
283
+ @ui.out {
284
+ @ui.newline
285
+ content.split("\n").each do |action|
286
+ if action.empty?
287
+ @ui.newline
288
+ else
289
+ @ui.say("#{prefix}#{stylize(action, :bold)}")
290
+ end
279
291
  end
280
- end
292
+ }
281
293
  end
282
294
 
283
295
  # ---
@@ -327,22 +339,24 @@ module WIP
327
339
  preview(content, :script)
328
340
 
329
341
  if @options.stepwise
330
- @io.newline
331
- choice = @io.choose('yes', 'no', 'skip') do |menu|
332
- menu.header = 'Continue?'
333
- menu.flow = :inline
334
- menu.index = :none
335
- end
342
+ @ui.err {
343
+ @ui.newline
344
+ choice = @ui.choose('yes', 'no', 'skip') do |menu|
345
+ menu.header = 'Continue?'
346
+ menu.flow = :inline
347
+ menu.index = :none
348
+ end
336
349
 
337
- case choice
338
- when 'yes'
339
- @io.newline
340
- proceed_with_script(content)
341
- when 'no'
342
- raise HaltSignal
343
- when 'skip'
344
- @io.newline
345
- end
350
+ case choice
351
+ when 'yes'
352
+ @ui.newline
353
+ proceed_with_script(content)
354
+ when 'no'
355
+ raise HaltSignal
356
+ when 'skip'
357
+ @ui.newline
358
+ end
359
+ }
346
360
  else
347
361
  proceed_with_script(content)
348
362
  end
@@ -354,24 +368,26 @@ module WIP
354
368
  preview(action, :lines)
355
369
 
356
370
  if @options.stepwise
357
- @io.newline
358
- choice = @io.choose('yes', 'no', 'skip') do |menu|
359
- menu.header = 'Continue?'
360
- menu.flow = :inline
361
- menu.index = :none
362
- end
371
+ @ui.err {
372
+ @ui.newline
373
+ choice = @ui.choose('yes', 'no', 'skip') do |menu|
374
+ menu.header = 'Continue?'
375
+ menu.flow = :inline
376
+ menu.index = :none
377
+ end
363
378
 
364
- case choice
365
- when 'yes'
366
- @io.newline
367
- proceed_with_line(action)
368
- next
369
- when 'no'
370
- raise HaltSignal
371
- when 'skip'
372
- @io.newline
373
- next
374
- end
379
+ case choice
380
+ when 'yes'
381
+ @ui.newline
382
+ proceed_with_line(action)
383
+ next
384
+ when 'no'
385
+ raise HaltSignal
386
+ when 'skip'
387
+ @ui.newline
388
+ next
389
+ end
390
+ }
375
391
  else
376
392
  proceed_with_line(action)
377
393
  end
@@ -389,11 +405,13 @@ module WIP
389
405
  command = %Q{bash -c "#{command} 2>&1"}
390
406
 
391
407
  IO.popen(@env, command) do |pipe|
392
- @io.indent do
393
- pipe.each do |line|
394
- @io.say(line)
408
+ @ui.out {
409
+ @ui.indent do
410
+ pipe.each do |line|
411
+ @ui.say(line)
412
+ end
395
413
  end
396
- end
414
+ }
397
415
  end
398
416
 
399
417
  exit 1 unless $?.success?
@@ -431,13 +449,15 @@ module WIP
431
449
  Open3.popen2e(@env, script) do |stdin, stdoe, wait_thread|
432
450
  status = wait_thread.value
433
451
 
434
- @io.indent do
435
- while line = stdoe.gets
436
- @io.say("⫶ #{line}")
452
+ @ui.out {
453
+ @ui.indent do
454
+ while line = stdoe.gets
455
+ @ui.say("⫶ #{line}")
456
+ end
437
457
  end
438
- end
439
458
 
440
- exit 1 unless status.success?
459
+ exit 1 unless status.success?
460
+ }
441
461
  end
442
462
  end
443
463
 
@@ -449,13 +469,15 @@ module WIP
449
469
  Open3.popen2e(@env, command) do |stdin, stdoe, wait_thread|
450
470
  status = wait_thread.value
451
471
 
452
- @io.indent do
453
- while line = stdoe.gets
454
- @io.say("⫶ #{line}")
472
+ @ui.out {
473
+ @ui.indent do
474
+ while line = stdoe.gets
475
+ @ui.say("⫶ #{line}")
476
+ end
455
477
  end
456
- end
457
478
 
458
- exit 1 unless status.success?
479
+ exit 1 unless status.success?
480
+ }
459
481
  end
460
482
  end
461
483
 
@@ -473,7 +495,7 @@ module WIP
473
495
  end
474
496
 
475
497
  def error(message)
476
- @io.say stylize(message, :red)
498
+ @ui.err { @ui.say stylize(message, :red) }
477
499
  end
478
500
 
479
501
  def guard_error(description, command, check, actual)
@@ -486,29 +508,31 @@ module WIP
486
508
  message = ['Output did not match expected', check.inspect, actual]
487
509
  end
488
510
 
489
- @io.newline
490
- error "Guard failed: '#{description}'"
491
- @io.indent do
492
- error "→ #{command}"
493
- end
511
+ @ui.err {
512
+ @ui.newline
513
+ error "Guard failed: '#{description}'"
514
+ @ui.indent do
515
+ error "→ #{command}"
516
+ end
494
517
 
495
- if message.is_a?(Array)
496
- error message[0]
518
+ if message.is_a?(Array)
519
+ error message[0]
497
520
 
498
- @io.newline
499
- @io.say stylize('Expected:', :bold)
500
- @io.indent do
501
- @io.say message[1]
502
- end
521
+ @ui.newline
522
+ @ui.say stylize('Expected:', :bold)
523
+ @ui.indent do
524
+ @ui.say message[1]
525
+ end
503
526
 
504
- @io.newline
505
- @io.say stylize('Actual:', :bold)
506
- @io.indent do
507
- @io.say message[2]
527
+ @ui.newline
528
+ @ui.say stylize('Actual:', :bold)
529
+ @ui.indent do
530
+ @ui.say message[2]
531
+ end
532
+ else
533
+ error message
508
534
  end
509
- else
510
- error message
511
- end
535
+ }
512
536
 
513
537
  raise GuardError, message[0]
514
538
  end
@@ -40,7 +40,7 @@ module WIP
40
40
  module InstanceMethods
41
41
  def execute(arguments, options)
42
42
  workflow = builder.build(arguments, options)
43
- runner = Runner.new(@io, workflow)
43
+ runner = Runner.new(@ui, workflow)
44
44
  runner.run(options)
45
45
  end
46
46
  end
data/lib/wip/runner.rb CHANGED
@@ -3,6 +3,7 @@ require 'wip/runner/errors'
3
3
  require 'wip/runner/command'
4
4
  require 'wip/runner/options'
5
5
  require 'wip/runner/parser'
6
+ require 'wip/runner/ui'
6
7
 
7
8
  require 'wip/runner/cli'
8
9
  require 'wip/runner/cli/help'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wip-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Innis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-11 00:00:00.000000000 Z
11
+ date: 2016-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -110,9 +110,10 @@ files:
110
110
  - lib/wip/runner/shell/task.rb
111
111
  - lib/wip/runner/spec/helpers.rb
112
112
  - lib/wip/runner/spec/helpers/command_helpers.rb
113
- - lib/wip/runner/spec/helpers/io_helpers.rb
114
113
  - lib/wip/runner/spec/helpers/matchers.rb
115
114
  - lib/wip/runner/spec/helpers/string_helpers.rb
115
+ - lib/wip/runner/spec/helpers/ui_helpers.rb
116
+ - lib/wip/runner/ui.rb
116
117
  - lib/wip/runner/version.rb
117
118
  - lib/wip/runner/workflow.rb
118
119
  - lib/wip/runner/workflow/builder.rb
@@ -143,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
144
  version: '0'
144
145
  requirements: []
145
146
  rubyforge_project:
146
- rubygems_version: 2.2.3
147
+ rubygems_version: 2.2.2
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: wip-runner is a generic CLI stand-alone and library.