crazy-yard 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +19 -0
  3. data/README.md +438 -0
  4. data/bin/ey +9 -0
  5. data/lib/engineyard.rb +9 -0
  6. data/lib/engineyard/cli.rb +816 -0
  7. data/lib/engineyard/cli/api.rb +98 -0
  8. data/lib/engineyard/cli/recipes.rb +129 -0
  9. data/lib/engineyard/cli/ui.rb +275 -0
  10. data/lib/engineyard/cli/web.rb +85 -0
  11. data/lib/engineyard/config.rb +158 -0
  12. data/lib/engineyard/deploy_config.rb +65 -0
  13. data/lib/engineyard/deploy_config/ref.rb +56 -0
  14. data/lib/engineyard/error.rb +82 -0
  15. data/lib/engineyard/eyrc.rb +59 -0
  16. data/lib/engineyard/repo.rb +105 -0
  17. data/lib/engineyard/serverside_runner.rb +159 -0
  18. data/lib/engineyard/templates.rb +6 -0
  19. data/lib/engineyard/templates/ey.yml.erb +196 -0
  20. data/lib/engineyard/templates/ey_yml.rb +119 -0
  21. data/lib/engineyard/thor.rb +215 -0
  22. data/lib/engineyard/version.rb +4 -0
  23. data/lib/vendor/thor/Gemfile +15 -0
  24. data/lib/vendor/thor/LICENSE.md +20 -0
  25. data/lib/vendor/thor/README.md +35 -0
  26. data/lib/vendor/thor/lib/thor.rb +473 -0
  27. data/lib/vendor/thor/lib/thor/actions.rb +318 -0
  28. data/lib/vendor/thor/lib/thor/actions/create_file.rb +105 -0
  29. data/lib/vendor/thor/lib/thor/actions/create_link.rb +60 -0
  30. data/lib/vendor/thor/lib/thor/actions/directory.rb +119 -0
  31. data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +137 -0
  32. data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +314 -0
  33. data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
  34. data/lib/vendor/thor/lib/thor/base.rb +652 -0
  35. data/lib/vendor/thor/lib/thor/command.rb +136 -0
  36. data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
  37. data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  38. data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
  39. data/lib/vendor/thor/lib/thor/error.rb +28 -0
  40. data/lib/vendor/thor/lib/thor/group.rb +282 -0
  41. data/lib/vendor/thor/lib/thor/invocation.rb +172 -0
  42. data/lib/vendor/thor/lib/thor/parser.rb +4 -0
  43. data/lib/vendor/thor/lib/thor/parser/argument.rb +74 -0
  44. data/lib/vendor/thor/lib/thor/parser/arguments.rb +171 -0
  45. data/lib/vendor/thor/lib/thor/parser/option.rb +121 -0
  46. data/lib/vendor/thor/lib/thor/parser/options.rb +218 -0
  47. data/lib/vendor/thor/lib/thor/rake_compat.rb +72 -0
  48. data/lib/vendor/thor/lib/thor/runner.rb +322 -0
  49. data/lib/vendor/thor/lib/thor/shell.rb +88 -0
  50. data/lib/vendor/thor/lib/thor/shell/basic.rb +393 -0
  51. data/lib/vendor/thor/lib/thor/shell/color.rb +148 -0
  52. data/lib/vendor/thor/lib/thor/shell/html.rb +127 -0
  53. data/lib/vendor/thor/lib/thor/util.rb +270 -0
  54. data/lib/vendor/thor/lib/thor/version.rb +3 -0
  55. data/lib/vendor/thor/thor.gemspec +24 -0
  56. data/spec/engineyard/cli/api_spec.rb +50 -0
  57. data/spec/engineyard/cli_spec.rb +28 -0
  58. data/spec/engineyard/config_spec.rb +61 -0
  59. data/spec/engineyard/deploy_config_spec.rb +194 -0
  60. data/spec/engineyard/eyrc_spec.rb +76 -0
  61. data/spec/engineyard/repo_spec.rb +83 -0
  62. data/spec/engineyard_spec.rb +7 -0
  63. data/spec/ey/console_spec.rb +57 -0
  64. data/spec/ey/deploy_spec.rb +435 -0
  65. data/spec/ey/ey_spec.rb +23 -0
  66. data/spec/ey/init_spec.rb +123 -0
  67. data/spec/ey/list_environments_spec.rb +120 -0
  68. data/spec/ey/login_spec.rb +33 -0
  69. data/spec/ey/logout_spec.rb +24 -0
  70. data/spec/ey/logs_spec.rb +36 -0
  71. data/spec/ey/rebuild_spec.rb +18 -0
  72. data/spec/ey/recipes/apply_spec.rb +29 -0
  73. data/spec/ey/recipes/download_spec.rb +43 -0
  74. data/spec/ey/recipes/upload_spec.rb +99 -0
  75. data/spec/ey/rollback_spec.rb +73 -0
  76. data/spec/ey/scp_spec.rb +176 -0
  77. data/spec/ey/servers_spec.rb +209 -0
  78. data/spec/ey/ssh_spec.rb +273 -0
  79. data/spec/ey/status_spec.rb +45 -0
  80. data/spec/ey/timeout_deploy_spec.rb +18 -0
  81. data/spec/ey/web/disable_spec.rb +21 -0
  82. data/spec/ey/web/enable_spec.rb +26 -0
  83. data/spec/ey/web/restart_spec.rb +21 -0
  84. data/spec/ey/whoami_spec.rb +30 -0
  85. data/spec/spec_helper.rb +84 -0
  86. data/spec/support/bundled_ey +7 -0
  87. data/spec/support/fixture_recipes.tgz +0 -0
  88. data/spec/support/git_repos.rb +115 -0
  89. data/spec/support/helpers.rb +330 -0
  90. data/spec/support/matchers.rb +16 -0
  91. data/spec/support/ruby_ext.rb +13 -0
  92. data/spec/support/shared_behavior.rb +278 -0
  93. metadata +411 -0
@@ -0,0 +1,88 @@
1
+ require 'rbconfig'
2
+
3
+ class Thor
4
+ module Base
5
+ # Returns the shell used in all Thor classes. If you are in a Unix platform
6
+ # it will use a colored log, otherwise it will use a basic one without color.
7
+ #
8
+ def self.shell
9
+ @shell ||= if ENV['THOR_SHELL'] && ENV['THOR_SHELL'].size > 0
10
+ Thor::Shell.const_get(ENV['THOR_SHELL'])
11
+ elsif ((RbConfig::CONFIG['host_os'] =~ /mswin|mingw/) && !(ENV['ANSICON']))
12
+ Thor::Shell::Basic
13
+ else
14
+ Thor::Shell::Color
15
+ end
16
+ end
17
+
18
+ # Sets the shell used in all Thor classes.
19
+ #
20
+ def self.shell=(klass)
21
+ @shell = klass
22
+ end
23
+ end
24
+
25
+ module Shell
26
+ SHELL_DELEGATED_METHODS = [:ask, :error, :set_color, :yes?, :no?, :say, :say_status, :print_in_columns, :print_table, :print_wrapped, :file_collision, :terminal_width]
27
+
28
+ autoload :Basic, 'thor/shell/basic'
29
+ autoload :Color, 'thor/shell/color'
30
+ autoload :HTML, 'thor/shell/html'
31
+
32
+ # Add shell to initialize config values.
33
+ #
34
+ # ==== Configuration
35
+ # shell<Object>:: An instance of the shell to be used.
36
+ #
37
+ # ==== Examples
38
+ #
39
+ # class MyScript < Thor
40
+ # argument :first, :type => :numeric
41
+ # end
42
+ #
43
+ # MyScript.new [1.0], { :foo => :bar }, :shell => Thor::Shell::Basic.new
44
+ #
45
+ def initialize(args=[], options={}, config={})
46
+ super
47
+ self.shell = config[:shell]
48
+ self.shell.base ||= self if self.shell.respond_to?(:base)
49
+ end
50
+
51
+ # Holds the shell for the given Thor instance. If no shell is given,
52
+ # it gets a default shell from Thor::Base.shell.
53
+ def shell
54
+ @shell ||= Thor::Base.shell.new
55
+ end
56
+
57
+ # Sets the shell for this thor class.
58
+ def shell=(shell)
59
+ @shell = shell
60
+ end
61
+
62
+ # Common methods that are delegated to the shell.
63
+ SHELL_DELEGATED_METHODS.each do |method|
64
+ module_eval <<-METHOD, __FILE__, __LINE__
65
+ def #{method}(*args,&block)
66
+ shell.#{method}(*args,&block)
67
+ end
68
+ METHOD
69
+ end
70
+
71
+ # Yields the given block with padding.
72
+ def with_padding
73
+ shell.padding += 1
74
+ yield
75
+ ensure
76
+ shell.padding -= 1
77
+ end
78
+
79
+ protected
80
+
81
+ # Allow shell to be shared between invocations.
82
+ #
83
+ def _shared_configuration #:nodoc:
84
+ super.merge!(:shell => self.shell)
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,393 @@
1
+ require 'tempfile'
2
+
3
+ class Thor
4
+ module Shell
5
+ class Basic
6
+ attr_accessor :base
7
+ attr_reader :padding
8
+
9
+ # Initialize base, mute and padding to nil.
10
+ #
11
+ def initialize #:nodoc:
12
+ @base, @mute, @padding = nil, false, 0
13
+ end
14
+
15
+ # Mute everything that's inside given block
16
+ #
17
+ def mute
18
+ @mute = true
19
+ yield
20
+ ensure
21
+ @mute = false
22
+ end
23
+
24
+ # Check if base is muted
25
+ #
26
+ def mute?
27
+ @mute
28
+ end
29
+
30
+ # Sets the output padding, not allowing less than zero values.
31
+ #
32
+ def padding=(value)
33
+ @padding = [0, value].max
34
+ end
35
+
36
+ # Asks something to the user and receives a response.
37
+ #
38
+ # If asked to limit the correct responses, you can pass in an
39
+ # array of acceptable answers. If one of those is not supplied,
40
+ # they will be shown a message stating that one of those answers
41
+ # must be given and re-asked the question.
42
+ #
43
+ # ==== Example
44
+ # ask("What is your name?")
45
+ #
46
+ # ask("What is your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])
47
+ #
48
+ def ask(statement, *args)
49
+ options = args.last.is_a?(Hash) ? args.pop : {}
50
+
51
+ options[:limited_to] ? ask_filtered(statement, options[:limited_to], *args) : ask_simply(statement, *args)
52
+ end
53
+
54
+ # Say (print) something to the user. If the sentence ends with a whitespace
55
+ # or tab character, a new line is not appended (print + flush). Otherwise
56
+ # are passed straight to puts (behavior got from Highline).
57
+ #
58
+ # ==== Example
59
+ # say("I know you knew that.")
60
+ #
61
+ def say(message="", color=nil, force_new_line=(message.to_s !~ /( |\t)\Z/))
62
+ message = message.to_s
63
+
64
+ message = set_color(message, *color) if color && can_display_colors?
65
+
66
+ spaces = " " * padding
67
+
68
+ if force_new_line
69
+ stdout.puts(spaces + message)
70
+ else
71
+ stdout.print(spaces + message)
72
+ end
73
+ stdout.flush
74
+ end
75
+
76
+ # Say a status with the given color and appends the message. Since this
77
+ # method is used frequently by actions, it allows nil or false to be given
78
+ # in log_status, avoiding the message from being shown. If a Symbol is
79
+ # given in log_status, it's used as the color.
80
+ #
81
+ def say_status(status, message, log_status=true)
82
+ return if quiet? || log_status == false
83
+ spaces = " " * (padding + 1)
84
+ color = log_status.is_a?(Symbol) ? log_status : :green
85
+
86
+ status = status.to_s.rjust(12)
87
+ status = set_color status, color, true if color
88
+
89
+ stdout.puts "#{status}#{spaces}#{message}"
90
+ stdout.flush
91
+ end
92
+
93
+ # Make a question the to user and returns true if the user replies "y" or
94
+ # "yes".
95
+ #
96
+ def yes?(statement, color=nil)
97
+ !!(ask(statement, color) =~ is?(:yes))
98
+ end
99
+
100
+ # Make a question the to user and returns true if the user replies "n" or
101
+ # "no".
102
+ #
103
+ def no?(statement, color=nil)
104
+ !yes?(statement, color)
105
+ end
106
+
107
+ # Prints values in columns
108
+ #
109
+ # ==== Parameters
110
+ # Array[String, String, ...]
111
+ #
112
+ def print_in_columns(array)
113
+ return if array.empty?
114
+ colwidth = (array.map{|el| el.to_s.size}.max || 0) + 2
115
+ array.each_with_index do |value, index|
116
+ # Don't output trailing spaces when printing the last column
117
+ if ((((index + 1) % (terminal_width / colwidth))).zero? && !index.zero?) || index + 1 == array.length
118
+ stdout.puts value
119
+ else
120
+ stdout.printf("%-#{colwidth}s", value)
121
+ end
122
+ end
123
+ end
124
+
125
+ # Prints a table.
126
+ #
127
+ # ==== Parameters
128
+ # Array[Array[String, String, ...]]
129
+ #
130
+ # ==== Options
131
+ # indent<Integer>:: Indent the first column by indent value.
132
+ # colwidth<Integer>:: Force the first column to colwidth spaces wide.
133
+ #
134
+ def print_table(array, options={})
135
+ return if array.empty?
136
+
137
+ formats, indent, colwidth = [], options[:indent].to_i, options[:colwidth]
138
+ options[:truncate] = terminal_width if options[:truncate] == true
139
+
140
+ formats << "%-#{colwidth + 2}s" if colwidth
141
+ start = colwidth ? 1 : 0
142
+
143
+ colcount = array.max{|a,b| a.size <=> b.size }.size
144
+
145
+ maximas = []
146
+
147
+ start.upto(colcount - 1) do |index|
148
+ maxima = array.map {|row| row[index] ? row[index].to_s.size : 0 }.max
149
+ maximas << maxima
150
+ if index == colcount - 1
151
+ # Don't output 2 trailing spaces when printing the last column
152
+ formats << "%-s"
153
+ else
154
+ formats << "%-#{maxima + 2}s"
155
+ end
156
+ end
157
+
158
+ formats[0] = formats[0].insert(0, " " * indent)
159
+ formats << "%s"
160
+
161
+ array.each do |row|
162
+ sentence = ""
163
+
164
+ row.each_with_index do |column, index|
165
+ maxima = maximas[index]
166
+
167
+ if column.is_a?(Numeric)
168
+ if index == row.size - 1
169
+ # Don't output 2 trailing spaces when printing the last column
170
+ f = "%#{maxima}s"
171
+ else
172
+ f = "%#{maxima}s "
173
+ end
174
+ else
175
+ f = formats[index]
176
+ end
177
+ sentence << f % column.to_s
178
+ end
179
+
180
+ sentence = truncate(sentence, options[:truncate]) if options[:truncate]
181
+ stdout.puts sentence
182
+ end
183
+ end
184
+
185
+ # Prints a long string, word-wrapping the text to the current width of the
186
+ # terminal display. Ideal for printing heredocs.
187
+ #
188
+ # ==== Parameters
189
+ # String
190
+ #
191
+ # ==== Options
192
+ # indent<Integer>:: Indent each line of the printed paragraph by indent value.
193
+ #
194
+ def print_wrapped(message, options={})
195
+ indent = options[:indent] || 0
196
+ width = terminal_width - indent
197
+ paras = message.split("\n\n")
198
+
199
+ paras.map! do |unwrapped|
200
+ unwrapped.strip.gsub(/\n/, " ").squeeze(" ").
201
+ gsub(/.{1,#{width}}(?:\s|\Z)/){($& + 5.chr).
202
+ gsub(/\n\005/,"\n").gsub(/\005/,"\n")}
203
+ end
204
+
205
+ paras.each do |para|
206
+ para.split("\n").each do |line|
207
+ stdout.puts line.insert(0, " " * indent)
208
+ end
209
+ stdout.puts unless para == paras.last
210
+ end
211
+ end
212
+
213
+ # Deals with file collision and returns true if the file should be
214
+ # overwritten and false otherwise. If a block is given, it uses the block
215
+ # response as the content for the diff.
216
+ #
217
+ # ==== Parameters
218
+ # destination<String>:: the destination file to solve conflicts
219
+ # block<Proc>:: an optional block that returns the value to be used in diff
220
+ #
221
+ def file_collision(destination)
222
+ return true if @always_force
223
+ options = block_given? ? "[Ynaqdh]" : "[Ynaqh]"
224
+
225
+ while true
226
+ answer = ask %[Overwrite #{destination}? (enter "h" for help) #{options}]
227
+
228
+ case answer
229
+ when is?(:yes), is?(:force), ""
230
+ return true
231
+ when is?(:no), is?(:skip)
232
+ return false
233
+ when is?(:always)
234
+ return @always_force = true
235
+ when is?(:quit)
236
+ say 'Aborting...'
237
+ raise SystemExit
238
+ when is?(:diff)
239
+ show_diff(destination, yield) if block_given?
240
+ say 'Retrying...'
241
+ else
242
+ say file_collision_help
243
+ end
244
+ end
245
+ end
246
+
247
+ # This code was copied from Rake, available under MIT-LICENSE
248
+ # Copyright (c) 2003, 2004 Jim Weirich
249
+ def terminal_width
250
+ if ENV['THOR_COLUMNS']
251
+ result = ENV['THOR_COLUMNS'].to_i
252
+ else
253
+ result = unix? ? dynamic_width : 80
254
+ end
255
+ (result < 10) ? 80 : result
256
+ rescue
257
+ 80
258
+ end
259
+
260
+ # Called if something goes wrong during the execution. This is used by Thor
261
+ # internally and should not be used inside your scripts. If something went
262
+ # wrong, you can always raise an exception. If you raise a Thor::Error, it
263
+ # will be rescued and wrapped in the method below.
264
+ #
265
+ def error(statement)
266
+ stderr.puts statement
267
+ end
268
+
269
+ # Apply color to the given string with optional bold. Disabled in the
270
+ # Thor::Shell::Basic class.
271
+ #
272
+ def set_color(string, *args) #:nodoc:
273
+ string
274
+ end
275
+
276
+ protected
277
+
278
+ def can_display_colors?
279
+ false
280
+ end
281
+
282
+ def lookup_color(color)
283
+ return color unless color.is_a?(Symbol)
284
+ self.class.const_get(color.to_s.upcase)
285
+ end
286
+
287
+ def stdout
288
+ $stdout
289
+ end
290
+
291
+ def stdin
292
+ $stdin
293
+ end
294
+
295
+ def stderr
296
+ $stderr
297
+ end
298
+
299
+ def is?(value) #:nodoc:
300
+ value = value.to_s
301
+
302
+ if value.size == 1
303
+ /\A#{value}\z/i
304
+ else
305
+ /\A(#{value}|#{value[0,1]})\z/i
306
+ end
307
+ end
308
+
309
+ def file_collision_help #:nodoc:
310
+ <<HELP
311
+ Y - yes, overwrite
312
+ n - no, do not overwrite
313
+ a - all, overwrite this and all others
314
+ q - quit, abort
315
+ d - diff, show the differences between the old and the new
316
+ h - help, show this help
317
+ HELP
318
+ end
319
+
320
+ def show_diff(destination, content) #:nodoc:
321
+ diff_cmd = ENV['THOR_DIFF'] || ENV['RAILS_DIFF'] || 'diff -u'
322
+
323
+ Tempfile.open(File.basename(destination), File.dirname(destination)) do |temp|
324
+ temp.write content
325
+ temp.rewind
326
+ system %(#{diff_cmd} "#{destination}" "#{temp.path}")
327
+ end
328
+ end
329
+
330
+ def quiet? #:nodoc:
331
+ mute? || (base && base.options[:quiet])
332
+ end
333
+
334
+ # Calculate the dynamic width of the terminal
335
+ def dynamic_width
336
+ @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
337
+ end
338
+
339
+ def dynamic_width_stty
340
+ %x{stty size 2>/dev/null}.split[1].to_i
341
+ end
342
+
343
+ def dynamic_width_tput
344
+ %x{tput cols 2>/dev/null}.to_i
345
+ end
346
+
347
+ def unix?
348
+ RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
349
+ end
350
+
351
+ def truncate(string, width)
352
+ as_unicode do
353
+ chars = string.chars.to_a
354
+ if chars.length <= width
355
+ chars.join
356
+ else
357
+ ( chars[0, width-3].join ) + "..."
358
+ end
359
+ end
360
+ end
361
+
362
+ if "".respond_to?(:encode)
363
+ def as_unicode
364
+ yield
365
+ end
366
+ else
367
+ def as_unicode
368
+ old, $KCODE = $KCODE, "U"
369
+ yield
370
+ ensure
371
+ $KCODE = old
372
+ end
373
+ end
374
+
375
+ def ask_simply(statement, color=nil)
376
+ say("#{statement} ", color)
377
+ stdin.gets.tap{|text| text.strip! if text}
378
+ end
379
+
380
+ def ask_filtered(statement, answer_set, *args)
381
+ correct_answer = nil
382
+ until correct_answer
383
+ answer = ask_simply("#{statement} #{answer_set.inspect}", *args)
384
+ correct_answer = answer_set.include?(answer) ? answer : nil
385
+ answers = answer_set.map(&:inspect).join(", ")
386
+ say("Your response must be one of: [#{answers}]. Please try again.") unless correct_answer
387
+ end
388
+ correct_answer
389
+ end
390
+
391
+ end
392
+ end
393
+ end