giddyup-deploy 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,9 @@ class Giddyup::CommandWrapper
36
36
  # Giddyup::CommandWrapper::CommandFailed exception is raised containing
37
37
  # the status of the failed command and all output.
38
38
  #
39
+ # If a block is passed, it will be called for each line of output, and
40
+ # pass two arguments: `<stream>` and `<line>`.
41
+ #
39
42
  def self.run_command(cmd)
40
43
  output = []
41
44
  rv = nil
@@ -70,7 +73,9 @@ class Giddyup::CommandWrapper
70
73
  stdout.close
71
74
  fds.delete(stdout)
72
75
  else
73
- output << [:stdout, stdout.readline.chomp]
76
+ l = stdout.readline.chomp
77
+ yield :stdout, l if block_given?
78
+ output << [:stdout, l]
74
79
  end
75
80
  end
76
81
 
@@ -79,7 +84,9 @@ class Giddyup::CommandWrapper
79
84
  stderr.close
80
85
  fds.delete(stderr)
81
86
  else
82
- output << [:stderr, stderr.readline.chomp]
87
+ l = stderr.readline.chomp
88
+ yield :stderr, l if block_given?
89
+ output << [:stderr, l]
83
90
  end
84
91
  end
85
92
  end
@@ -51,6 +51,11 @@ class Giddyup::GitDeploy
51
51
  "No environment given to deploy to"
52
52
  end
53
53
 
54
+ unless valid_environment?
55
+ raise RuntimeError,
56
+ "Unknown or unconfigured environment '#{@env}'"
57
+ end
58
+
54
59
  @stdout.puts "Deploying to environment '#{@env}'"
55
60
 
56
61
  do_push
@@ -60,6 +65,10 @@ class Giddyup::GitDeploy
60
65
  end
61
66
 
62
67
  private
68
+ def valid_environment?
69
+ !config_list('(pushTo|target(Enumerator)?)$').empty?
70
+ end
71
+
63
72
  def do_push
64
73
  config_item("pushTo", true).each do |t|
65
74
  run_command "Pushing HEAD to remote '#{t}'",
@@ -81,25 +90,23 @@ class Giddyup::GitDeploy
81
90
  # array of strings containing the names of all machines to deploy to.
82
91
  #
83
92
  def targets
84
- @targets ||= enumerate_targets
85
- end
86
-
87
- def enumerate_targets
88
- config_list('target(Enumerator)?$').map do |li|
89
- if li[0].downcase == 'target'
90
- li[1]
91
- elsif li[0].downcase == 'targetenumerator'
92
- rv = run_command("Enumerating targets using '#{li[1]}'", li[1]).split(/\s+/)
93
- if $?.exitstatus != 0
93
+ @targets ||= begin
94
+ config_list('target(Enumerator)?$').map do |li|
95
+ if li[0].downcase == 'target'
96
+ li[1]
97
+ elsif li[0].downcase == 'targetenumerator'
98
+ rv = run_command("Enumerating targets using '#{li[1]}'", li[1]).split(/\s+/)
99
+ if $?.exitstatus != 0
100
+ raise RuntimeError,
101
+ "Target enumeration failed. Aborting."
102
+ end
103
+ rv
104
+ else
94
105
  raise RuntimeError,
95
- "Target enumeration failed. Aborting."
106
+ "Unknown target expansion option: #{li[0]}"
96
107
  end
97
- rv
98
- else
99
- raise RuntimeError,
100
- "Unknown target expansion option: #{li[0]}"
101
- end
102
- end.flatten
108
+ end.flatten
109
+ end
103
110
  end
104
111
 
105
112
  # Get the value(s) of a configuration item from the config file.
@@ -178,12 +185,18 @@ class Giddyup::GitDeploy
178
185
  # as a string.
179
186
  #
180
187
  def run_command(desc, cmdline)
181
- @stdout.print "[....] #{desc}"
188
+ in_progress = "[....] #{desc}"
189
+
190
+ $stdout.print in_progress
182
191
 
183
192
  output = nil
184
193
  failed = false
185
194
  begin
186
- output = @command.run_command(cmdline)
195
+ output = @command.run_command(cmdline) do |fd, l|
196
+ next unless @verbose
197
+ @stdout.puts "\x0d\x1b[K#{fd.to_s.send(fd == :stderr ? :cyan : purple)}: #{l}"
198
+ @stdout.print in_progress
199
+ end
187
200
  rescue Giddyup::CommandWrapper::CommandFailed => e
188
201
  @stdout.puts "\x0d["+"FAIL".red+"] #{desc}"
189
202
  output = e.output
@@ -192,7 +205,7 @@ class Giddyup::GitDeploy
192
205
  @stdout.puts "\x0d["+" OK ".green+"] #{desc}"
193
206
  end
194
207
 
195
- if @verbose or failed
208
+ if failed and !@verbose
196
209
  @stdout.puts cmdline
197
210
  @stdout.puts output.map { |l| "#{l[0].to_s.send(l[0] == :stderr ? :cyan : :purple)}: #{l[1]}" }.join("\n")
198
211
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: giddyup-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.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: 2014-09-22 00:00:00.000000000 Z
12
+ date: 2015-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: git-version-bump
@@ -197,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
197
  version: '0'
198
198
  segments:
199
199
  - 0
200
- hash: 3538091426769745759
200
+ hash: -1324647467486882675
201
201
  required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  none: false
203
203
  requirements:
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  segments:
208
208
  - 0
209
- hash: 3538091426769745759
209
+ hash: -1324647467486882675
210
210
  requirements: []
211
211
  rubyforge_project:
212
212
  rubygems_version: 1.8.23