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,172 @@
1
+ class Thor
2
+ module Invocation
3
+ def self.included(base) #:nodoc:
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ # This method is responsible for receiving a name and find the proper
9
+ # class and command for it. The key is an optional parameter which is
10
+ # available only in class methods invocations (i.e. in Thor::Group).
11
+ def prepare_for_invocation(key, name) #:nodoc:
12
+ case name
13
+ when Symbol, String
14
+ Thor::Util.find_class_and_command_by_namespace(name.to_s, !key)
15
+ else
16
+ name
17
+ end
18
+ end
19
+ end
20
+
21
+ # Make initializer aware of invocations and the initialization args.
22
+ def initialize(args=[], options={}, config={}, &block) #:nodoc:
23
+ @_invocations = config[:invocations] || Hash.new { |h,k| h[k] = [] }
24
+ @_initializer = [ args, options, config ]
25
+ super
26
+ end
27
+
28
+ # Receives a name and invokes it. The name can be a string (either "command" or
29
+ # "namespace:command"), a Thor::Command, a Class or a Thor instance. If the
30
+ # command cannot be guessed by name, it can also be supplied as second argument.
31
+ #
32
+ # You can also supply the arguments, options and configuration values for
33
+ # the command to be invoked, if none is given, the same values used to
34
+ # initialize the invoker are used to initialize the invoked.
35
+ #
36
+ # When no name is given, it will invoke the default command of the current class.
37
+ #
38
+ # ==== Examples
39
+ #
40
+ # class A < Thor
41
+ # def foo
42
+ # invoke :bar
43
+ # invoke "b:hello", ["José"]
44
+ # end
45
+ #
46
+ # def bar
47
+ # invoke "b:hello", ["José"]
48
+ # end
49
+ # end
50
+ #
51
+ # class B < Thor
52
+ # def hello(name)
53
+ # puts "hello #{name}"
54
+ # end
55
+ # end
56
+ #
57
+ # You can notice that the method "foo" above invokes two commands: "bar",
58
+ # which belongs to the same class and "hello" which belongs to the class B.
59
+ #
60
+ # By using an invocation system you ensure that a command is invoked only once.
61
+ # In the example above, invoking "foo" will invoke "b:hello" just once, even
62
+ # if it's invoked later by "bar" method.
63
+ #
64
+ # When class A invokes class B, all arguments used on A initialization are
65
+ # supplied to B. This allows lazy parse of options. Let's suppose you have
66
+ # some rspec commands:
67
+ #
68
+ # class Rspec < Thor::Group
69
+ # class_option :mock_framework, :type => :string, :default => :rr
70
+ #
71
+ # def invoke_mock_framework
72
+ # invoke "rspec:#{options[:mock_framework]}"
73
+ # end
74
+ # end
75
+ #
76
+ # As you noticed, it invokes the given mock framework, which might have its
77
+ # own options:
78
+ #
79
+ # class Rspec::RR < Thor::Group
80
+ # class_option :style, :type => :string, :default => :mock
81
+ # end
82
+ #
83
+ # Since it's not rspec concern to parse mock framework options, when RR
84
+ # is invoked all options are parsed again, so RR can extract only the options
85
+ # that it's going to use.
86
+ #
87
+ # If you want Rspec::RR to be initialized with its own set of options, you
88
+ # have to do that explicitly:
89
+ #
90
+ # invoke "rspec:rr", [], :style => :foo
91
+ #
92
+ # Besides giving an instance, you can also give a class to invoke:
93
+ #
94
+ # invoke Rspec::RR, [], :style => :foo
95
+ #
96
+ def invoke(name=nil, *args)
97
+ if name.nil?
98
+ warn "[Thor] Calling invoke() without argument is deprecated. Please use invoke_all instead.\n#{caller.join("\n")}"
99
+ return invoke_all
100
+ end
101
+
102
+ args.unshift(nil) if Array === args.first || NilClass === args.first
103
+ command, args, opts, config = args
104
+
105
+ klass, command = _retrieve_class_and_command(name, command)
106
+ raise "Expected Thor class, got #{klass}" unless klass <= Thor::Base
107
+
108
+ args, opts, config = _parse_initialization_options(args, opts, config)
109
+ klass.send(:dispatch, command, args, opts, config) do |instance|
110
+ instance.parent_options = options
111
+ end
112
+ end
113
+
114
+ # Invoke the given command if the given args.
115
+ def invoke_command(command, *args) #:nodoc:
116
+ current = @_invocations[self.class]
117
+
118
+ unless current.include?(command.name)
119
+ current << command.name
120
+ command.run(self, *args)
121
+ end
122
+ end
123
+ alias invoke_task invoke_command
124
+
125
+ # Invoke all commands for the current instance.
126
+ def invoke_all #:nodoc:
127
+ self.class.all_commands.map { |_, command| invoke_command(command) }
128
+ end
129
+
130
+ # Invokes using shell padding.
131
+ def invoke_with_padding(*args)
132
+ with_padding { invoke(*args) }
133
+ end
134
+
135
+ protected
136
+
137
+ # Configuration values that are shared between invocations.
138
+ def _shared_configuration #:nodoc:
139
+ { :invocations => @_invocations }
140
+ end
141
+
142
+ # This method simply retrieves the class and command to be invoked.
143
+ # If the name is nil or the given name is a command in the current class,
144
+ # use the given name and return self as class. Otherwise, call
145
+ # prepare_for_invocation in the current class.
146
+ def _retrieve_class_and_command(name, sent_command=nil) #:nodoc:
147
+ case
148
+ when name.nil?
149
+ [self.class, nil]
150
+ when self.class.all_commands[name.to_s]
151
+ [self.class, name.to_s]
152
+ else
153
+ klass, command = self.class.prepare_for_invocation(nil, name)
154
+ [klass, command || sent_command]
155
+ end
156
+ end
157
+ alias _retrieve_class_and_task _retrieve_class_and_command
158
+
159
+ # Initialize klass using values stored in the @_initializer.
160
+ def _parse_initialization_options(args, opts, config) #:nodoc:
161
+ stored_args, stored_opts, stored_config = @_initializer
162
+
163
+ args ||= stored_args.dup
164
+ opts ||= stored_opts.dup
165
+
166
+ config ||= {}
167
+ config = stored_config.merge(_shared_configuration).merge!(config)
168
+
169
+ [ args, opts, config ]
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,4 @@
1
+ require 'thor/parser/argument'
2
+ require 'thor/parser/arguments'
3
+ require 'thor/parser/option'
4
+ require 'thor/parser/options'
@@ -0,0 +1,74 @@
1
+ class Thor
2
+ class Argument #:nodoc:
3
+ VALID_TYPES = [ :numeric, :hash, :array, :string ]
4
+
5
+ attr_reader :name, :description, :enum, :required, :type, :default, :banner
6
+ alias :human_name :name
7
+
8
+ def initialize(name, options={})
9
+ class_name = self.class.name.split("::").last
10
+
11
+ type = options[:type]
12
+
13
+ raise ArgumentError, "#{class_name} name can't be nil." if name.nil?
14
+ raise ArgumentError, "Type :#{type} is not valid for #{class_name.downcase}s." if type && !valid_type?(type)
15
+
16
+ @name = name.to_s
17
+ @description = options[:desc]
18
+ @required = options.key?(:required) ? options[:required] : true
19
+ @type = (type || :string).to_sym
20
+ @default = options[:default]
21
+ @banner = options[:banner] || default_banner
22
+ @enum = options[:enum]
23
+
24
+ validate! # Trigger specific validations
25
+ end
26
+
27
+ def usage
28
+ required? ? banner : "[#{banner}]"
29
+ end
30
+
31
+ def required?
32
+ required
33
+ end
34
+
35
+ def show_default?
36
+ case default
37
+ when Array, String, Hash
38
+ !default.empty?
39
+ else
40
+ default
41
+ end
42
+ end
43
+
44
+ protected
45
+
46
+ def validate!
47
+ if required? && !default.nil?
48
+ raise ArgumentError, "An argument cannot be required and have default value."
49
+ elsif @enum && !@enum.is_a?(Array)
50
+ raise ArgumentError, "An argument cannot have an enum other than an array."
51
+ end
52
+ end
53
+
54
+ def valid_type?(type)
55
+ self.class::VALID_TYPES.include?(type.to_sym)
56
+ end
57
+
58
+ def default_banner
59
+ case type
60
+ when :boolean
61
+ nil
62
+ when :string, :default
63
+ human_name.upcase
64
+ when :numeric
65
+ "N"
66
+ when :hash
67
+ "key:value"
68
+ when :array
69
+ "one two three"
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,171 @@
1
+ class Thor
2
+ class Arguments #:nodoc:
3
+ NUMERIC = /(\d*\.\d+|\d+)/
4
+
5
+ # Receives an array of args and returns two arrays, one with arguments
6
+ # and one with switches.
7
+ #
8
+ def self.split(args)
9
+ arguments = []
10
+
11
+ args.each do |item|
12
+ break if item =~ /^-/
13
+ arguments << item
14
+ end
15
+
16
+ return arguments, args[Range.new(arguments.size, -1)]
17
+ end
18
+
19
+ def self.parse(*args)
20
+ to_parse = args.pop
21
+ new(*args).parse(to_parse)
22
+ end
23
+
24
+ # Takes an array of Thor::Argument objects.
25
+ #
26
+ def initialize(arguments=[])
27
+ @assigns, @non_assigned_required = {}, []
28
+ @switches = arguments
29
+
30
+ arguments.each do |argument|
31
+ if argument.default != nil
32
+ @assigns[argument.human_name] = argument.default
33
+ elsif argument.required?
34
+ @non_assigned_required << argument
35
+ end
36
+ end
37
+ end
38
+
39
+ def parse(args)
40
+ @pile = args.dup
41
+
42
+ @switches.each do |argument|
43
+ break unless peek
44
+ @non_assigned_required.delete(argument)
45
+ @assigns[argument.human_name] = send(:"parse_#{argument.type}", argument.human_name)
46
+ end
47
+
48
+ check_requirement!
49
+ @assigns
50
+ end
51
+
52
+ def remaining
53
+ @pile
54
+ end
55
+
56
+ private
57
+
58
+ def no_or_skip?(arg)
59
+ arg =~ /^--(no|skip)-([-\w]+)$/
60
+ $2
61
+ end
62
+
63
+ def last?
64
+ @pile.empty?
65
+ end
66
+
67
+ def peek
68
+ @pile.first
69
+ end
70
+
71
+ def shift
72
+ @pile.shift
73
+ end
74
+
75
+ def unshift(arg)
76
+ unless arg.kind_of?(Array)
77
+ @pile.unshift(arg)
78
+ else
79
+ @pile = arg + @pile
80
+ end
81
+ end
82
+
83
+ def current_is_value?
84
+ peek && peek.to_s !~ /^-/
85
+ end
86
+
87
+ # Runs through the argument array getting strings that contains ":" and
88
+ # mark it as a hash:
89
+ #
90
+ # [ "name:string", "age:integer" ]
91
+ #
92
+ # Becomes:
93
+ #
94
+ # { "name" => "string", "age" => "integer" }
95
+ #
96
+ def parse_hash(name)
97
+ return shift if peek.is_a?(Hash)
98
+ hash = {}
99
+
100
+ while current_is_value? && peek.include?(?:)
101
+ key, value = shift.split(':',2)
102
+ hash[key] = value
103
+ end
104
+ hash
105
+ end
106
+
107
+ # Runs through the argument array getting all strings until no string is
108
+ # found or a switch is found.
109
+ #
110
+ # ["a", "b", "c"]
111
+ #
112
+ # And returns it as an array:
113
+ #
114
+ # ["a", "b", "c"]
115
+ #
116
+ def parse_array(name)
117
+ return shift if peek.is_a?(Array)
118
+ array = []
119
+
120
+ while current_is_value?
121
+ array << shift
122
+ end
123
+ array
124
+ end
125
+
126
+ # Check if the peek is numeric format and return a Float or Integer.
127
+ # Otherwise raises an error.
128
+ #
129
+ def parse_numeric(name)
130
+ return shift if peek.is_a?(Numeric)
131
+
132
+ unless peek =~ NUMERIC && $& == peek
133
+ raise MalformattedArgumentError, "Expected numeric value for '#{name}'; got #{peek.inspect}"
134
+ end
135
+
136
+ $&.index('.') ? shift.to_f : shift.to_i
137
+ end
138
+
139
+ # Parse string:
140
+ # for --string-arg, just return the current value in the pile
141
+ # for --no-string-arg, nil
142
+ #
143
+ def parse_string(name)
144
+ if no_or_skip?(name)
145
+ nil
146
+ else
147
+ value = shift
148
+ if @switches.is_a?(Hash) && switch = @switches[name]
149
+ if switch.enum && !switch.enum.include?(value)
150
+ raise MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}"
151
+ end
152
+ end
153
+ value
154
+ end
155
+ end
156
+
157
+ # Raises an error if @non_assigned_required array is not empty.
158
+ #
159
+ def check_requirement!
160
+ unless @non_assigned_required.empty?
161
+ names = @non_assigned_required.map do |o|
162
+ o.respond_to?(:switch_name) ? o.switch_name : o.human_name
163
+ end.join("', '")
164
+
165
+ class_name = self.class.name.split('::').last.downcase
166
+ raise RequiredArgumentMissingError, "No value provided for required #{class_name} '#{names}'"
167
+ end
168
+ end
169
+
170
+ end
171
+ end
@@ -0,0 +1,121 @@
1
+ class Thor
2
+ class Option < Argument #:nodoc:
3
+ attr_reader :aliases, :group, :lazy_default, :hide
4
+
5
+ VALID_TYPES = [:boolean, :numeric, :hash, :array, :string]
6
+
7
+ def initialize(name, options={})
8
+ options[:required] = false unless options.key?(:required)
9
+ super
10
+ @lazy_default = options[:lazy_default]
11
+ @group = options[:group].to_s.capitalize if options[:group]
12
+ @aliases = Array(options[:aliases])
13
+ @hide = options[:hide]
14
+ end
15
+
16
+ # This parse quick options given as method_options. It makes several
17
+ # assumptions, but you can be more specific using the option method.
18
+ #
19
+ # parse :foo => "bar"
20
+ # #=> Option foo with default value bar
21
+ #
22
+ # parse [:foo, :baz] => "bar"
23
+ # #=> Option foo with default value bar and alias :baz
24
+ #
25
+ # parse :foo => :required
26
+ # #=> Required option foo without default value
27
+ #
28
+ # parse :foo => 2
29
+ # #=> Option foo with default value 2 and type numeric
30
+ #
31
+ # parse :foo => :numeric
32
+ # #=> Option foo without default value and type numeric
33
+ #
34
+ # parse :foo => true
35
+ # #=> Option foo with default value true and type boolean
36
+ #
37
+ # The valid types are :boolean, :numeric, :hash, :array and :string. If none
38
+ # is given a default type is assumed. This default type accepts arguments as
39
+ # string (--foo=value) or booleans (just --foo).
40
+ #
41
+ # By default all options are optional, unless :required is given.
42
+ #
43
+ def self.parse(key, value)
44
+ if key.is_a?(Array)
45
+ name, *aliases = key
46
+ else
47
+ name, aliases = key, []
48
+ end
49
+
50
+ name = name.to_s
51
+ default = value
52
+
53
+ type = case value
54
+ when Symbol
55
+ default = nil
56
+ if VALID_TYPES.include?(value)
57
+ value
58
+ elsif required = (value == :required)
59
+ :string
60
+ end
61
+ when TrueClass, FalseClass
62
+ :boolean
63
+ when Numeric
64
+ :numeric
65
+ when Hash, Array, String
66
+ value.class.name.downcase.to_sym
67
+ end
68
+ self.new(name.to_s, :required => required, :type => type, :default => default, :aliases => aliases)
69
+ end
70
+
71
+ def switch_name
72
+ @switch_name ||= dasherized? ? name : dasherize(name)
73
+ end
74
+
75
+ def human_name
76
+ @human_name ||= dasherized? ? undasherize(name) : name
77
+ end
78
+
79
+ def usage(padding=0)
80
+ sample = if banner && !banner.to_s.empty?
81
+ "#{switch_name}=#{banner}"
82
+ else
83
+ switch_name
84
+ end
85
+
86
+ sample = "[#{sample}]" unless required?
87
+
88
+ if aliases.empty?
89
+ (" " * padding) << sample
90
+ else
91
+ "#{aliases.join(', ')}, #{sample}"
92
+ end
93
+ end
94
+
95
+ VALID_TYPES.each do |type|
96
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
97
+ def #{type}?
98
+ self.type == #{type.inspect}
99
+ end
100
+ RUBY
101
+ end
102
+
103
+ protected
104
+
105
+ def validate!
106
+ raise ArgumentError, "An option cannot be boolean and required." if boolean? && required?
107
+ end
108
+
109
+ def dasherized?
110
+ name.index('-') == 0
111
+ end
112
+
113
+ def undasherize(str)
114
+ str.sub(/^-{1,2}/, '')
115
+ end
116
+
117
+ def dasherize(str)
118
+ (str.length > 1 ? "--" : "-") + str.gsub('_', '-')
119
+ end
120
+ end
121
+ end