steps 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,2 +1,7 @@
1
+ = 1.1.0
2
+ * Add debug mode to steps
3
+ * Add multi-line report capability
4
+ * Fix bug with retrieve as first step output
5
+
1
6
  = 1.0
2
7
  * Initial Release
data/README.md CHANGED
@@ -77,6 +77,7 @@ Nested steps are supported
77
77
  # do more stuff
78
78
  end
79
79
  ```
80
+
80
81
  ### Getting User Feedback (highline integration)
81
82
 
82
83
  #### confirm
@@ -104,6 +105,19 @@ The retrieve function is essentially a shadow of the highline ask function, exce
104
105
  end
105
106
  ```
106
107
 
108
+ ### Print stacktraces for errors - Debug Mode
109
+
110
+ To get more information while debugging you may activate the debug mode. The gem will print the stacktraces for exceptions while in debug mode.
111
+
112
+ ```ruby
113
+ step "Do something", :debug => true do
114
+ # ...
115
+ end
116
+ ```
117
+
118
+ Debug mode is inherited by all nested steps.
119
+
120
+
107
121
  ### Capistrano Deployment Integration
108
122
 
109
123
  If you want to quiet down your Capistrano output and use this to provide the output, you can manually quiet the Capistrano logger and use this gem in the following way.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -29,7 +29,7 @@ def error_and_exit(message)
29
29
  Steps::Output.error_and_exit(message)
30
30
  end
31
31
 
32
- def report(message)
33
- step message.bold.blue do " " end
32
+ def report(message, color="blue", bold=true)
33
+ Steps::Output.report(message, color, bold)
34
34
  end
35
35
 
@@ -11,17 +11,33 @@ module Steps
11
11
  @task_depth = 0
12
12
  @stacked_result = false
13
13
  @highline = HighLine.new
14
+ @debug_depth = nil
14
15
 
15
- def self.step(desc, options)
16
+ def self.step(desc, options={}, &block)
16
17
  self.start_to desc
18
+
19
+ # Set debug depth if specified
20
+ if options[:debug] and @debug_depth.nil?
21
+ @debug_depth = @task_depth
22
+ end
23
+
17
24
  begin
18
- smessage = yield
25
+ smessage = block.call()
19
26
  smessage = "✔" unless smessage.is_a? String
20
27
  self.success smessage
21
28
  rescue Exception => e
22
29
  message = e.message.empty? ? "X" : e.message
23
30
 
31
+ unless e.is_a?(SystemExit) or @debug_depth.nil?
32
+ if @task_depth >= @debug_depth
33
+ self.report message, "red", false
34
+ e.backtrace.each { |c| self.report("(debug) #{c}", "red") }
35
+ message = "X"
36
+ end
37
+ end
38
+
24
39
  self.error(message)
40
+
25
41
  if options[:vital]
26
42
  if @task_depth > 1
27
43
  raise "X"
@@ -88,6 +104,18 @@ module Steps
88
104
  self.result message.blue
89
105
  end
90
106
 
107
+ def self.report message, color, bold
108
+ message = message.to_s # try and make sure we're dealing with a string
109
+ message.each_line do |line|
110
+ unless line.empty?
111
+ line.strip!
112
+ line = line.send("bold") if bold
113
+ line = line.send(color) if ['red', 'blue', 'yellow', 'green'].include? color
114
+ self.step line do " " end
115
+ end
116
+ end
117
+ end
118
+
91
119
  def self.confirm(message, options={})
92
120
  message = message + " (y|n) > "
93
121
  message = (options[:vital] ? message.red : message.blue) + " "
@@ -119,11 +147,16 @@ module Steps
119
147
  message = message.blue + " "
120
148
  message = "├── ".yellow + message if @task_depth > 0
121
149
  @spinner.stop
150
+ if @task_depth > 0 and not @stacked_result
151
+ print "\n" + ("| ".yellow * (@task_depth - 1))
152
+ end
122
153
  result = @highline.ask(message, answer_type, &block)
123
154
  if @task_depth > 0
124
155
  print "| ".yellow * (@task_depth - 1)
125
156
  @spinner.start
126
157
  end
158
+
159
+ @stacked_result = true
127
160
  return result
128
161
  end
129
162
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "steps"
8
- s.version = "1.0.1"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Crowd Favorite"]
12
- s.date = "2013-07-11"
12
+ s.date = "2013-09-30"
13
13
  s.description = "A way to simplify the output of shell scripting written in ruby.\n\nIntegrates with Capistrano and Rake tasks.\n"
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
data/test.rb CHANGED
@@ -24,7 +24,10 @@ step "Do Something else" do
24
24
  end
25
25
  step "Double! Nested Something" do
26
26
  step "Triple (and vital)! Nested Something", :vital => true do
27
- report "this is something important"
27
+ answer = retrieve "What is your favorite color?"
28
+ report "this is something important
29
+ Another Line
30
+ A third line"
28
31
  report "Something else important"
29
32
  step "Quad! Nested Something" do
30
33
  sleep 1
@@ -35,7 +38,6 @@ step "Do Something else" do
35
38
  end
36
39
  end
37
40
  sleep 1
38
- answer = retrieve "What is your favorite color?"
39
41
  step "favorite color" do
40
42
  sleep 1
41
43
  answer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steps
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
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-07-11 00:00:00.000000000 Z
12
+ date: 2013-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored