chaperone 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/examples/deploy.rb +4 -6
- data/lib/chaperone/guide.rb +23 -27
- data/lib/chaperone/prompt.rb +20 -8
- data/lib/chaperone/version.rb +1 -1
- data/lib/chaperone.rb +0 -4
- data/spec/models/guide_spec.rb +2 -3
- data/spec/models/prompt_spec.rb +4 -3
- metadata +2 -8
data/README.md
CHANGED
@@ -94,6 +94,15 @@ a user can update in another terminal and confirm the change is recognized.
|
|
94
94
|
p.code = 'rvm use 1.9.3'
|
95
95
|
p.question = 'Using the right version?'
|
96
96
|
end
|
97
|
+
|
98
|
+
# Output:
|
99
|
+
Ruby Version Check
|
100
|
+
Required: ruby 1.9.3[Any Patch Level]
|
101
|
+
Current: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.2.0]
|
102
|
+
|
103
|
+
rvm use 1.9.3
|
104
|
+
|
105
|
+
Using the right version? [c]ontinue, [r]etry, e[x]it
|
97
106
|
|
98
107
|
To see a full guide example, see the [`deploy.rb`](https://github.com/mwerner/chaperone/blob/master/examples/deploy.rb) file in the repository's `examples` dir
|
99
108
|
|
data/examples/deploy.rb
CHANGED
@@ -17,7 +17,7 @@ class Deploy < Chaperone::Guide
|
|
17
17
|
version = CommandLine.new('ruby', '-v').run.gsub("\n",'')
|
18
18
|
|
19
19
|
prompt do |p|
|
20
|
-
p.title = 'Ruby Version Check'
|
20
|
+
p.title = '==> Ruby Version Check'
|
21
21
|
p.needs = 'ruby 1.9.3[Any Patch Level]'
|
22
22
|
p.current = version
|
23
23
|
p.code = 'rvm use 1.9.3'
|
@@ -26,11 +26,9 @@ class Deploy < Chaperone::Guide
|
|
26
26
|
|
27
27
|
def execute_capistrano
|
28
28
|
prompt do |p|
|
29
|
-
p.title = 'Run capistrano task'
|
29
|
+
p.title = '==> Run capistrano task'
|
30
30
|
p.code = 'bundle exec cap production deploy'
|
31
|
-
p.notes
|
32
|
-
The script can be found in config/deploy/production.rb
|
33
|
-
}
|
31
|
+
p.notes = "The script can be found in config/deploy/production.rb"
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
@@ -38,7 +36,7 @@ class Deploy < Chaperone::Guide
|
|
38
36
|
latest = CommandLine.new('git describe --abbrev=0 --tags').run.gsub("\n",'') rescue 'Unable to determine'
|
39
37
|
|
40
38
|
prompt(question: false) do |p|
|
41
|
-
p.title = 'Tagging the release'
|
39
|
+
p.title = '==> Tagging the release'
|
42
40
|
p.notes = %{
|
43
41
|
- This should be the next unreleased tag in the current Changelog.md
|
44
42
|
Latest Deployed Version: #{status(latest)}
|
data/lib/chaperone/guide.rb
CHANGED
@@ -4,7 +4,7 @@ module Chaperone
|
|
4
4
|
include Output
|
5
5
|
include HighlineConfig
|
6
6
|
|
7
|
-
attr_accessor :steps, :current_step, :iteration, :url
|
7
|
+
attr_accessor :steps, :current_step, :iteration, :url, :debug
|
8
8
|
|
9
9
|
STEPS = ['no_steps_defined']
|
10
10
|
URL = 'https://github.com/mwerner/chaperone'
|
@@ -17,31 +17,22 @@ module Chaperone
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def start
|
20
|
-
welcome
|
20
|
+
welcome
|
21
21
|
|
22
22
|
(0..steps.length-1).each do |step|
|
23
23
|
@iteration = step
|
24
|
-
|
25
|
-
if current_step > iteration
|
26
|
-
skip_step!
|
27
|
-
next
|
28
|
-
end
|
29
|
-
|
24
|
+
skip_step! and next if current_step > iteration
|
30
25
|
break unless execute_step(steps[iteration].to_sym)
|
31
26
|
complete_step!
|
32
27
|
end
|
33
|
-
|
34
|
-
complete!
|
35
28
|
end
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
def no_steps_defined
|
40
|
-
prompt(question: false) do |p|
|
41
|
-
p.title = "No Steps are defined for #{self.class.to_s}"
|
42
|
-
end
|
30
|
+
def debug?
|
31
|
+
self.debug == true
|
43
32
|
end
|
44
33
|
|
34
|
+
private
|
35
|
+
|
45
36
|
def execute_step(step, proceed=true)
|
46
37
|
unless self.respond_to?(step)
|
47
38
|
output "WARNING: #{step} is not defined"
|
@@ -49,9 +40,15 @@ module Chaperone
|
|
49
40
|
end
|
50
41
|
|
51
42
|
loop do
|
52
|
-
|
43
|
+
result = send(step)
|
44
|
+
@debug = false
|
45
|
+
|
46
|
+
case result
|
53
47
|
when 'r'; next
|
54
|
-
when '
|
48
|
+
when 'd'
|
49
|
+
@debug = true
|
50
|
+
next
|
51
|
+
when 'x', 'q'; proceed = false
|
55
52
|
end
|
56
53
|
|
57
54
|
break
|
@@ -60,29 +57,28 @@ module Chaperone
|
|
60
57
|
proceed
|
61
58
|
end
|
62
59
|
|
63
|
-
|
60
|
+
def no_steps_defined
|
61
|
+
prompt(question: false) do |p|
|
62
|
+
p.title = "No Steps are defined for #{self.class.to_s}"
|
63
|
+
end
|
64
|
+
end
|
64
65
|
|
65
66
|
def prompt(opts={}, &config)
|
66
|
-
Prompt.new(opts, &config).render
|
67
|
+
Prompt.new(opts, self, &config).render
|
67
68
|
end
|
68
69
|
|
69
|
-
def welcome
|
70
|
-
output '==> Begin'
|
70
|
+
def welcome
|
71
71
|
output "==> Reference: #{url}" if url
|
72
72
|
end
|
73
73
|
|
74
74
|
def complete_step!
|
75
75
|
@current_step += 1
|
76
|
-
output notice("==> [#{iteration}] Completed Step")
|
76
|
+
#output notice("==> [#{iteration}] Completed Step")
|
77
77
|
end
|
78
78
|
|
79
79
|
def skip_step!
|
80
80
|
output notice("==> Skipping [#{iteration}] #{steps[iteration].gsub('_',' ')}")
|
81
81
|
end
|
82
82
|
|
83
|
-
def complete!
|
84
|
-
output "==> Finished"
|
85
|
-
end
|
86
|
-
|
87
83
|
end
|
88
84
|
end
|
data/lib/chaperone/prompt.rb
CHANGED
@@ -3,17 +3,19 @@ module Chaperone
|
|
3
3
|
include Output
|
4
4
|
include HighlineConfig
|
5
5
|
|
6
|
-
attr_accessor :title, :notes, :needs, :current, :code, :question, :config
|
6
|
+
attr_accessor :guide, :title, :notes, :needs, :current, :code, :question, :config, :debug
|
7
7
|
|
8
|
-
def initialize(config={})
|
9
|
-
@
|
8
|
+
def initialize(config={}, guide=nil)
|
9
|
+
@guide = guide || Guide.new
|
10
|
+
@config = {padding: false, question: true}.merge(config)
|
10
11
|
yield(self) if block_given?
|
11
12
|
end
|
12
13
|
|
13
14
|
def render
|
14
|
-
output body
|
15
|
+
output(guide.debug? ? debugging : body)
|
16
|
+
|
15
17
|
return unless has_question?
|
16
|
-
ask strong("#{question}
|
18
|
+
ask strong("\n#{question}[C]ontinue, #{'[d]ebug, ' if debug}[r]etry, e[x]it")
|
17
19
|
end
|
18
20
|
|
19
21
|
def lines
|
@@ -22,14 +24,24 @@ module Chaperone
|
|
22
24
|
sections << notes if notes
|
23
25
|
sections << "#{requirement('Required:')} #{needs}" if needs
|
24
26
|
sections << "#{status('Current:')} #{current}" if current
|
25
|
-
sections << direction("
|
27
|
+
sections << direction("#{code}") if code
|
26
28
|
sections
|
27
29
|
end
|
28
30
|
|
29
31
|
def body
|
30
|
-
text = lines.join("\n
|
32
|
+
text = lines.map{|t| t.gsub(/^#{t.scan(/^\s*/).min_by{|l|l.length}}/, "") }.join("\n")
|
33
|
+
text = "\n#{text}\n\n" if has_padding?
|
34
|
+
text
|
35
|
+
end
|
36
|
+
|
37
|
+
def debugging
|
38
|
+
sections = []
|
39
|
+
sections << action( "DEBUG: #{title}" ) if title
|
40
|
+
sections << debug if debug
|
41
|
+
|
42
|
+
text = sections.map{|t| t.gsub(/^#{t.scan(/^\s*/).min_by{|l|l.length}}/, "") }.join("\n")
|
31
43
|
text = "\n#{text}\n\n" if has_padding?
|
32
|
-
text
|
44
|
+
text
|
33
45
|
end
|
34
46
|
|
35
47
|
def has_padding?
|
data/lib/chaperone/version.rb
CHANGED
data/lib/chaperone.rb
CHANGED
data/spec/models/guide_spec.rb
CHANGED
@@ -17,9 +17,8 @@ describe Guide do
|
|
17
17
|
context '#start' do
|
18
18
|
let(:guide){Guide.new}
|
19
19
|
|
20
|
-
it 'calls welcome
|
21
|
-
Guide.any_instance.expects(:welcome
|
22
|
-
Guide.any_instance.expects(:complete!).once
|
20
|
+
it 'calls welcome' do
|
21
|
+
Guide.any_instance.expects(:welcome).once
|
23
22
|
guide.start
|
24
23
|
end
|
25
24
|
|
data/spec/models/prompt_spec.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Prompt do
|
4
4
|
let(:attrs){%w(title notes needs current code)}
|
5
|
+
let(:guide){ Guide.new }
|
5
6
|
context '#initialize' do
|
6
7
|
it 'defaults config' do
|
7
|
-
Prompt.new.config.should eq({padding:
|
8
|
+
Prompt.new.config.should eq({padding: false, question: true})
|
8
9
|
end
|
9
10
|
|
10
11
|
it 'allows config' do
|
11
|
-
params = {padding:
|
12
|
+
params = {padding: true, question: false}
|
12
13
|
Prompt.new(params).config.should eq(params)
|
13
14
|
end
|
14
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chaperone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -158,18 +158,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
158
|
- - ! '>='
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
|
-
segments:
|
162
|
-
- 0
|
163
|
-
hash: -1260887828363319748
|
164
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
162
|
none: false
|
166
163
|
requirements:
|
167
164
|
- - ! '>='
|
168
165
|
- !ruby/object:Gem::Version
|
169
166
|
version: '0'
|
170
|
-
segments:
|
171
|
-
- 0
|
172
|
-
hash: -1260887828363319748
|
173
167
|
requirements: []
|
174
168
|
rubyforge_project:
|
175
169
|
rubygems_version: 1.8.24
|