cf_script 0.0.1.beta.1

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.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/CHANGELOG.md +0 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE +22 -0
  6. data/README.md +84 -0
  7. data/Rakefile +33 -0
  8. data/cf_script.gemspec +34 -0
  9. data/lib/cf_script/callbacks.rb +43 -0
  10. data/lib/cf_script/command/base.rb +57 -0
  11. data/lib/cf_script/command/cf/apps/app.rb +19 -0
  12. data/lib/cf_script/command/cf/apps/apps.rb +44 -0
  13. data/lib/cf_script/command/cf/apps/env.rb +20 -0
  14. data/lib/cf_script/command/cf/apps/push.rb +47 -0
  15. data/lib/cf_script/command/cf/apps/restage.rb +19 -0
  16. data/lib/cf_script/command/cf/apps/restart.rb +19 -0
  17. data/lib/cf_script/command/cf/apps/set_env.rb +18 -0
  18. data/lib/cf_script/command/cf/apps/start.rb +19 -0
  19. data/lib/cf_script/command/cf/apps/stop.rb +19 -0
  20. data/lib/cf_script/command/cf/apps/unset_env.rb +18 -0
  21. data/lib/cf_script/command/cf/apps.rb +55 -0
  22. data/lib/cf_script/command/cf/general/api.rb +36 -0
  23. data/lib/cf_script/command/cf/general/auth.rb +28 -0
  24. data/lib/cf_script/command/cf/general/login.rb +42 -0
  25. data/lib/cf_script/command/cf/general/logout.rb +15 -0
  26. data/lib/cf_script/command/cf/general/target.rb +64 -0
  27. data/lib/cf_script/command/cf/general.rb +15 -0
  28. data/lib/cf_script/command/cf/routes/check_route.rb +17 -0
  29. data/lib/cf_script/command/cf/routes/create_route.rb +19 -0
  30. data/lib/cf_script/command/cf/routes/delete_route.rb +19 -0
  31. data/lib/cf_script/command/cf/routes/map_route.rb +30 -0
  32. data/lib/cf_script/command/cf/routes/routes.rb +40 -0
  33. data/lib/cf_script/command/cf/routes/unmap_route.rb +30 -0
  34. data/lib/cf_script/command/cf/routes.rb +17 -0
  35. data/lib/cf_script/command/cf/spaces/space.rb +36 -0
  36. data/lib/cf_script/command/cf/spaces/spaces.rb +23 -0
  37. data/lib/cf_script/command/cf/spaces.rb +9 -0
  38. data/lib/cf_script/command/error.rb +5 -0
  39. data/lib/cf_script/command/line.rb +105 -0
  40. data/lib/cf_script/command/registry.rb +50 -0
  41. data/lib/cf_script/command/runner.rb +97 -0
  42. data/lib/cf_script/command.rb +44 -0
  43. data/lib/cf_script/config.rb +60 -0
  44. data/lib/cf_script/executor/non_blocking.rb +107 -0
  45. data/lib/cf_script/executor/recorder.rb +16 -0
  46. data/lib/cf_script/executor/simple.rb +17 -0
  47. data/lib/cf_script/executor.rb +5 -0
  48. data/lib/cf_script/manifest.rb +38 -0
  49. data/lib/cf_script/object/api_endpoint.rb +10 -0
  50. data/lib/cf_script/object/app_info.rb +69 -0
  51. data/lib/cf_script/object/app_list.rb +24 -0
  52. data/lib/cf_script/object/app_spec.rb +55 -0
  53. data/lib/cf_script/object/attribute.rb +18 -0
  54. data/lib/cf_script/object/attribute_list.rb +40 -0
  55. data/lib/cf_script/object/instance_status.rb +29 -0
  56. data/lib/cf_script/object/route_info.rb +14 -0
  57. data/lib/cf_script/object/space.rb +17 -0
  58. data/lib/cf_script/object/target.rb +23 -0
  59. data/lib/cf_script/object.rb +24 -0
  60. data/lib/cf_script/output/buffer.rb +74 -0
  61. data/lib/cf_script/output/parser/attributes.rb +44 -0
  62. data/lib/cf_script/output/parser/section.rb +15 -0
  63. data/lib/cf_script/output/parser/table.rb +46 -0
  64. data/lib/cf_script/output/parser.rb +15 -0
  65. data/lib/cf_script/output/tests.rb +51 -0
  66. data/lib/cf_script/output/utils.rb +13 -0
  67. data/lib/cf_script/output.rb +62 -0
  68. data/lib/cf_script/scope/app/env.rb +15 -0
  69. data/lib/cf_script/scope/app/routes.rb +21 -0
  70. data/lib/cf_script/scope/app/state.rb +33 -0
  71. data/lib/cf_script/scope/app/utils.rb +32 -0
  72. data/lib/cf_script/scope/app.rb +94 -0
  73. data/lib/cf_script/scope/proxy.rb +36 -0
  74. data/lib/cf_script/scope/script.rb +59 -0
  75. data/lib/cf_script/scope/space.rb +9 -0
  76. data/lib/cf_script/scope/target.rb +90 -0
  77. data/lib/cf_script/scope.rb +68 -0
  78. data/lib/cf_script/ui.rb +261 -0
  79. data/lib/cf_script/utils.rb +19 -0
  80. data/lib/cf_script/version.rb +3 -0
  81. data/lib/cf_script.rb +105 -0
  82. data/test/fixtures/commands/apps/app/good.yml +18 -0
  83. data/test/fixtures/commands/apps/app/not_found.yml +8 -0
  84. data/test/fixtures/commands/apps/app/running.yml +19 -0
  85. data/test/fixtures/commands/apps/apps/good.yml +14 -0
  86. data/test/fixtures/commands/apps/apps/no_apps.yml +10 -0
  87. data/test/fixtures/commands/apps/env/empty.yml +37 -0
  88. data/test/fixtures/commands/apps/env/good.yml +41 -0
  89. data/test/fixtures/commands/apps/push/good.yml +60 -0
  90. data/test/fixtures/commands/apps/restage/good.yml +48 -0
  91. data/test/fixtures/commands/apps/restage/not_found.yml +8 -0
  92. data/test/fixtures/commands/apps/restart/good.yml +35 -0
  93. data/test/fixtures/commands/apps/restart/not_found.yml +8 -0
  94. data/test/fixtures/commands/apps/set_env/empty.yml +5 -0
  95. data/test/fixtures/commands/apps/set_env/good.yml +9 -0
  96. data/test/fixtures/commands/apps/set_env/not_found.yml +8 -0
  97. data/test/fixtures/commands/apps/start/good.yml +32 -0
  98. data/test/fixtures/commands/apps/start/not_found.yml +8 -0
  99. data/test/fixtures/commands/apps/start/with_container.yml +98 -0
  100. data/test/fixtures/commands/apps/stop/good.yml +8 -0
  101. data/test/fixtures/commands/apps/stop/not_found.yml +8 -0
  102. data/test/fixtures/commands/apps/unset_env/empty.yml +5 -0
  103. data/test/fixtures/commands/apps/unset_env/good.yml +9 -0
  104. data/test/fixtures/commands/apps/unset_env/not_found.yml +8 -0
  105. data/test/fixtures/commands/common/fail.yml +5 -0
  106. data/test/fixtures/commands/common/no_endpoint.yml +11 -0
  107. data/test/fixtures/commands/common/no_login.yml +8 -0
  108. data/test/fixtures/commands/general/api/bad_argument.yml +9 -0
  109. data/test/fixtures/commands/general/api/bad_endpoint.yml +9 -0
  110. data/test/fixtures/commands/general/api/good.yml +7 -0
  111. data/test/fixtures/commands/general/api/not_set.yml +7 -0
  112. data/test/fixtures/commands/general/api/set.yml +7 -0
  113. data/test/fixtures/commands/general/auth/empty.yml +5 -0
  114. data/test/fixtures/commands/general/auth/good.yml +10 -0
  115. data/test/fixtures/commands/general/auth/rejected.yml +10 -0
  116. data/test/fixtures/commands/general/login/good.yml +8 -0
  117. data/test/fixtures/commands/general/login/rejected.yml +23 -0
  118. data/test/fixtures/commands/general/logout/good.yml +8 -0
  119. data/test/fixtures/commands/general/target/empty.yml +5 -0
  120. data/test/fixtures/commands/general/target/good.yml +11 -0
  121. data/test/fixtures/commands/general/target/no_space.yml +10 -0
  122. data/test/fixtures/commands/general/target/not_found.yml +9 -0
  123. data/test/fixtures/commands/general/target/production.yml +11 -0
  124. data/test/fixtures/commands/general/target/staging.yml +11 -0
  125. data/test/fixtures/commands/general/target/staging_org.yml +11 -0
  126. data/test/fixtures/commands/general/target/test.yml +11 -0
  127. data/test/fixtures/commands/routes/check_route/good.yml +9 -0
  128. data/test/fixtures/commands/routes/check_route/no_domain.yml +9 -0
  129. data/test/fixtures/commands/routes/check_route/no_route.yml +9 -0
  130. data/test/fixtures/commands/routes/create_route/exists.yml +9 -0
  131. data/test/fixtures/commands/routes/create_route/good.yml +8 -0
  132. data/test/fixtures/commands/routes/delete_route/good.yml +8 -0
  133. data/test/fixtures/commands/routes/delete_route/not_exist.yml +8 -0
  134. data/test/fixtures/commands/routes/map_route/good.yml +10 -0
  135. data/test/fixtures/commands/routes/map_route/host_taken.yml +10 -0
  136. data/test/fixtures/commands/routes/map_route/invalid.yml +9 -0
  137. data/test/fixtures/commands/routes/map_route/no_app.yml +8 -0
  138. data/test/fixtures/commands/routes/map_route/no_domain.yml +9 -0
  139. data/test/fixtures/commands/routes/routes/good.yml +14 -0
  140. data/test/fixtures/commands/routes/unmap_route/good.yml +8 -0
  141. data/test/fixtures/commands/routes/unmap_route/no_app.yml +8 -0
  142. data/test/fixtures/commands/routes/unmap_route/no_domain.yml +9 -0
  143. data/test/fixtures/commands/spaces/space/empty.yml +5 -0
  144. data/test/fixtures/commands/spaces/space/good.yml +16 -0
  145. data/test/fixtures/commands/spaces/space/staging.yml +16 -0
  146. data/test/fixtures/commands/spaces/spaces/empty.yml +5 -0
  147. data/test/fixtures/commands/spaces/spaces/good.yml +12 -0
  148. data/test/lib/cf_script/command/base_test.rb +21 -0
  149. data/test/lib/cf_script/command/cf/apps/app_test.rb +56 -0
  150. data/test/lib/cf_script/command/cf/apps/apps_test.rb +81 -0
  151. data/test/lib/cf_script/command/cf/apps/env_test.rb +55 -0
  152. data/test/lib/cf_script/command/cf/apps/push_test.rb +46 -0
  153. data/test/lib/cf_script/command/cf/apps/restage_test.rb +47 -0
  154. data/test/lib/cf_script/command/cf/apps/restart_test.rb +47 -0
  155. data/test/lib/cf_script/command/cf/apps/set_env_test.rb +38 -0
  156. data/test/lib/cf_script/command/cf/apps/start_test.rb +55 -0
  157. data/test/lib/cf_script/command/cf/apps/stop_test.rb +35 -0
  158. data/test/lib/cf_script/command/cf/apps/unset_env_test.rb +38 -0
  159. data/test/lib/cf_script/command/cf/general/api_test.rb +55 -0
  160. data/test/lib/cf_script/command/cf/general/auth_test.rb +76 -0
  161. data/test/lib/cf_script/command/cf/general/login_test.rb +80 -0
  162. data/test/lib/cf_script/command/cf/general/logout_test.rb +34 -0
  163. data/test/lib/cf_script/command/cf/general/target_test.rb +110 -0
  164. data/test/lib/cf_script/command/cf/routes/check_route_test.rb +31 -0
  165. data/test/lib/cf_script/command/cf/routes/create_route_test.rb +19 -0
  166. data/test/lib/cf_script/command/cf/routes/delete_route_test.rb +19 -0
  167. data/test/lib/cf_script/command/cf/routes/map_route_test.rb +56 -0
  168. data/test/lib/cf_script/command/cf/routes/routes_test.rb +24 -0
  169. data/test/lib/cf_script/command/cf/routes/unmap_route_test.rb +36 -0
  170. data/test/lib/cf_script/command/cf/spaces/space_test.rb +55 -0
  171. data/test/lib/cf_script/command/cf/spaces/spaces_test.rb +47 -0
  172. data/test/lib/cf_script/command/line_test.rb +59 -0
  173. data/test/lib/cf_script/object/api_endpoint_test.rb +19 -0
  174. data/test/lib/cf_script/object/app_info_test.rb +127 -0
  175. data/test/lib/cf_script/object/app_list_test.rb +51 -0
  176. data/test/lib/cf_script/object/attribute_list_test.rb +42 -0
  177. data/test/lib/cf_script/object/attribute_test.rb +29 -0
  178. data/test/lib/cf_script/object/instance_status_test.rb +37 -0
  179. data/test/lib/cf_script/object/space_test.rb +31 -0
  180. data/test/lib/cf_script/object/target_test.rb +41 -0
  181. data/test/lib/cf_script/output/buffer_test.rb +73 -0
  182. data/test/lib/cf_script/output/parser/attributes_test.rb +102 -0
  183. data/test/lib/cf_script/output/parser/section_test.rb +60 -0
  184. data/test/lib/cf_script/output/parser/table_test.rb +108 -0
  185. data/test/lib/cf_script/output/tests_test.rb +91 -0
  186. data/test/lib/cf_script/output_test.rb +134 -0
  187. data/test/lib/cf_script/scope/app/state_test.rb +61 -0
  188. data/test/lib/cf_script/scope/app_test.rb +101 -0
  189. data/test/lib/cf_script/scope/script_test.rb +88 -0
  190. data/test/lib/cf_script/scope/space_test.rb +27 -0
  191. data/test/lib/cf_script/scope/target_test.rb +158 -0
  192. data/test/lib/cf_script/scope_test.rb +41 -0
  193. data/test/lib/cf_script/utils_test.rb +20 -0
  194. data/test/lib/cf_script_test.rb +73 -0
  195. data/test/support/assertions.rb +14 -0
  196. data/test/support/helpers/config_context.rb +19 -0
  197. data/test/support/helpers/fixture_executor.rb +79 -0
  198. data/test/support/helpers/mock_execution.rb +58 -0
  199. data/test/support/helpers/object_helpers.rb +29 -0
  200. data/test/support/helpers/output_sink.rb +25 -0
  201. data/test/support/helpers.rb +3 -0
  202. data/test/support/shared_examples/command_object.rb +38 -0
  203. data/test/support/shared_examples.rb +30 -0
  204. data/test/test_helper.rb +34 -0
  205. metadata +321 -0
@@ -0,0 +1,68 @@
1
+ module CfScript::Scope
2
+ module Execution
3
+ module_function
4
+
5
+ def exec_in(inner, *args, &block)
6
+ outer = eval('self', block.binding)
7
+ outer = CfScript::Scope::Root.new if outer.class == Object
8
+
9
+ inner_proxy = CfScript::Scope::Proxy.new(inner, outer)
10
+
11
+ begin
12
+ outer.instance_variables.each do |var|
13
+ val = outer.instance_variable_get(var)
14
+ inner_proxy.instance_variable_set(var, val)
15
+ end
16
+
17
+ inner_proxy.instance_exec(*args, &block)
18
+ ensure
19
+ outer.instance_variables.each do |var|
20
+ val = inner_proxy.instance_variable_get(var)
21
+ outer.instance_variable_set(var, val)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ class Base
28
+ include Execution
29
+ include CfScript::UI
30
+
31
+ def initialize
32
+ enter_scope
33
+ end
34
+
35
+ def finalize
36
+ exit_scope
37
+ end
38
+
39
+ def spec_for(name)
40
+ CfScript.spec_for(name)
41
+ end
42
+
43
+ def method_missing(m, *args, &block)
44
+ CfScript::Command.run(m, *args, &block)
45
+ end
46
+
47
+ protected
48
+
49
+ def scope_name
50
+ self.class.name.split('::').last.downcase
51
+ end
52
+
53
+ def enter_scope
54
+ end
55
+
56
+ def exit_scope
57
+ end
58
+ end
59
+
60
+ class Root < Base
61
+ end
62
+ end
63
+
64
+ require 'cf_script/scope/proxy'
65
+ require 'cf_script/scope/target'
66
+ require 'cf_script/scope/script'
67
+ require 'cf_script/scope/space'
68
+ require 'cf_script/scope/app'
@@ -0,0 +1,261 @@
1
+ # encoding: utf-8
2
+
3
+ require 'colorize'
4
+
5
+ module CfScript::UI
6
+ TAGS = {
7
+ error: ['{', '}'],
8
+ trace: ['<', '>'],
9
+ debug: ['(', ')'],
10
+ other: ['[', ']'],
11
+ }
12
+
13
+ COLORS = {
14
+ success: { color: :green },
15
+ error: { color: :red },
16
+ alert: { color: :yellow },
17
+ info: { color: :cyan },
18
+
19
+ inactive: { color: :light_red },
20
+ active: { color: :light_green },
21
+
22
+ progress: { color: :blue },
23
+ step: { color: :light_blue },
24
+
25
+ title: { color: :magenta },
26
+ detail: { color: :light_magenta },
27
+
28
+ trace: { color: :light_black },
29
+ debug: { color: :white },
30
+
31
+ # NOTE: default != no color
32
+ default: { color: :default },
33
+ }
34
+
35
+ EMOJI = {
36
+ success: "\xE2\x9C\x85",
37
+ error: "\xE2\x9D\x8C",
38
+ alert: "\xE2\x9A\xA1",
39
+ info: "\xE2\x9D\x95",
40
+
41
+ trace: "\xE2\x86\xAA",
42
+ debug: "\xE2\x9A\xAA",
43
+
44
+ default: "\xE2\x9E\x96",
45
+
46
+ bisque: "🍲",
47
+ }
48
+
49
+ module_function
50
+
51
+ def puts_out(text)
52
+ CfScript.stdout.puts text
53
+ nil # Make it explicit
54
+ end
55
+
56
+ def print_out(text)
57
+ CfScript.stdout.print text
58
+ nil # Make it explicit
59
+ end
60
+
61
+ def puts_err(text)
62
+ CfScript.stderr.puts text
63
+ nil # Make it explicit
64
+ end
65
+
66
+ def print_err(text)
67
+ CfScript.stderr.print text
68
+ nil # Make it explicit
69
+ end
70
+
71
+ def with_color_of(type = :default)
72
+ COLORS[CfScript.config.ui.color ? type : :default]
73
+ end
74
+
75
+ def ui_style(text, type = :default)
76
+ text.colorize with_color_of(type)
77
+ end
78
+
79
+ def emoji(type)
80
+ "#{(EMOJI.key?(type) ? EMOJI[type] : EMOJI[:default])} "
81
+ end
82
+
83
+ def emoji_for(type)
84
+ emoji(type) if CfScript.config.ui.emoji
85
+ end
86
+
87
+ def tag_style(type = :default)
88
+ type
89
+ end
90
+
91
+ def tag_color(type = :default)
92
+ type
93
+ end
94
+
95
+ def tag_char(type, which)
96
+ (TAGS.key?(type) ? TAGS[type] : TAGS[:other]).send(which)
97
+ end
98
+
99
+ def tag_open(type = :default)
100
+ tag_char(tag_style(type), :first)
101
+ end
102
+
103
+ def tag_close(type = :default)
104
+ tag_char(tag_style(type), :last)
105
+ end
106
+
107
+ def tag_format(tag, type = :default)
108
+ if tag and CfScript.config.ui.tags
109
+ list = []
110
+
111
+ list << tag_open(type)
112
+ list << tag
113
+ list << tag_close(type)
114
+
115
+ list.join.colorize with_color_of(tag_color(type))
116
+ end
117
+ end
118
+
119
+ def ui_format(type, tag, message, tag_type = nil)
120
+ list = []
121
+
122
+ list << emoji_for(type)
123
+ list << tag_format(tag, tag_type ? tag_type : type)
124
+ list << message.colorize(with_color_of(type))
125
+
126
+ list.compact.reject(&:empty?).join(' ')
127
+ end
128
+
129
+ def call_type(callee)
130
+ callee.to_s =~ /\Aui_(.+)\z/ ? $1.to_sym : callee
131
+ end
132
+
133
+ def success(tag, message)
134
+ puts_out ui_format(call_type(__callee__), tag, message)
135
+ end
136
+
137
+ def error(tag, message)
138
+ puts_err ui_format(call_type(__callee__), tag, message)
139
+ end
140
+
141
+ def alert(tag, message)
142
+ puts_out ui_format(call_type(__callee__), tag, message)
143
+ end
144
+
145
+ def info(tag, message)
146
+ puts_out ui_format(call_type(__callee__), tag, message)
147
+ end
148
+
149
+ def progress(tag, message)
150
+ puts_out ui_format(call_type(__callee__), tag, message)
151
+ end
152
+
153
+ def step(tag, message)
154
+ puts_out ui_format(call_type(__callee__), tag, message)
155
+ end
156
+
157
+ def title(tag, message, indent = 0)
158
+ puts_out ui_format(call_type(__callee__), tag, "#{' ' * indent}#{message}")
159
+ end
160
+
161
+ def detail(tag, message, indent = 1)
162
+ puts_out ui_format(call_type(__callee__), tag, "#{' ' * indent}#{message}")
163
+ end
164
+
165
+ def trace(tag, message, use_print = false)
166
+ if CfScript.config.runtime.trace
167
+ text = ui_format(call_type(__callee__), tag, message)
168
+ use_print ? print_out(text) : puts_out(text)
169
+ end
170
+ end
171
+
172
+ def debug(tag, message)
173
+ puts_err ui_format(call_type(__callee__), tag, message.inspect)
174
+ #binding.pry; __pry__.???
175
+ end
176
+
177
+ # For overriding to use a default tag
178
+ alias :ui_tag_format :tag_format
179
+ alias :ui_success :success
180
+ alias :ui_error :error
181
+ alias :ui_alert :alert
182
+ alias :ui_info :info
183
+ alias :ui_progress :progress
184
+ alias :ui_step :step
185
+ alias :ui_title :title
186
+ alias :ui_detail :detail
187
+ alias :ui_trace :trace
188
+ alias :ui_debug :debug
189
+ end
190
+
191
+ module CfScript::UI::NilTag
192
+ def success(message)
193
+ ui_success nil, message
194
+ end
195
+
196
+ def error(message)
197
+ ui_error nil, message
198
+ end
199
+
200
+ def alert(message)
201
+ ui_alert nil, message
202
+ end
203
+
204
+ def info(message)
205
+ ui_info nil, message
206
+ end
207
+
208
+ def progress(message)
209
+ ui_progress nil, message
210
+ end
211
+
212
+ def step(message)
213
+ ui_step nil, message
214
+ end
215
+
216
+ def title(message, indent = 0)
217
+ ui_title nil, message, indent
218
+ end
219
+
220
+ def detail(message, indent = 1)
221
+ ui_detail nil, message, indent
222
+ end
223
+ end
224
+
225
+ module CfScript::UI::NameTag
226
+ def name_tag
227
+ name
228
+ end
229
+
230
+ def success(message)
231
+ ui_success name_tag, message
232
+ end
233
+
234
+ def error(message)
235
+ ui_error name_tag, message
236
+ end
237
+
238
+ def alert(message)
239
+ ui_alert name_tag, message
240
+ end
241
+
242
+ def info(message)
243
+ ui_info name_tag, message
244
+ end
245
+
246
+ def progress(message)
247
+ ui_progress name_tag, message
248
+ end
249
+
250
+ def step(message)
251
+ ui_step name_tag, message
252
+ end
253
+
254
+ def title(message, indent = 0)
255
+ ui_title name_tag, message, indent
256
+ end
257
+
258
+ def detail(message, indent = 1)
259
+ ui_detail name_tag, message, indent
260
+ end
261
+ end
@@ -0,0 +1,19 @@
1
+ module CfScript::Utils
2
+ module_function
3
+
4
+ def symbolize(name)
5
+ return name if name.is_a?(Symbol)
6
+
7
+ name.downcase.gsub(/[ .-]/, '_').to_sym
8
+ end
9
+
10
+ def symbolize_keys(hash)
11
+ out = {}
12
+
13
+ hash.each do |key, value|
14
+ out[symbolize(key)] = value
15
+ end
16
+
17
+ out
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module CfScript
2
+ VERSION = '0.0.1.beta.1'
3
+ end
data/lib/cf_script.rb ADDED
@@ -0,0 +1,105 @@
1
+ require_relative './cf_script/version'
2
+ require_relative './cf_script/config'
3
+ require_relative './cf_script/callbacks'
4
+ require_relative './cf_script/utils'
5
+ require_relative './cf_script/ui'
6
+ require_relative './cf_script/output'
7
+ require_relative './cf_script/executor'
8
+ require_relative './cf_script/scope'
9
+ require_relative './cf_script/command'
10
+ require_relative './cf_script/object'
11
+ require_relative './cf_script/manifest'
12
+
13
+ module CfScript
14
+ class << self
15
+ attr_accessor :configuration
16
+
17
+ attr_accessor :definitions
18
+
19
+ attr_accessor :cf_call_count
20
+ attr_accessor :cf_call_stack
21
+ end
22
+
23
+ #extend CfScript::Context
24
+ extend CfScript::Scope::Execution
25
+ extend CfScript::UI
26
+
27
+ module_function
28
+
29
+ def config
30
+ @configuration ||= Config.new
31
+ end
32
+
33
+ def configure
34
+ block_given? ? yield(config) : config
35
+ end
36
+
37
+ def stdout
38
+ config.io.stdout
39
+ end
40
+
41
+ def stderr
42
+ config.io.stderr
43
+ end
44
+
45
+ def manifest(path = nil)
46
+ @manifest ||= CfScript::Manifest.new(path)
47
+ end
48
+
49
+ def define(app_name, &block)
50
+ @definitions ||= {}
51
+ @definitions[app_name] = AppSpec.new(name: app_name).tap do |spec|
52
+ spec.instance_exec(&block)
53
+ end
54
+ end
55
+
56
+ def spec_for(app_name)
57
+ @definitions ||= {}
58
+ @definitions[app_name]
59
+ end
60
+
61
+ def cf(options = {}, &block)
62
+ @cf_call_count ||= 0
63
+ @cf_call_stack ||= []
64
+
65
+ if @cf_call_count == 0
66
+ info :cf, CfScript::Command::Runner.cf_id
67
+ end
68
+
69
+ @cf_call_count += 1
70
+ @cf_call_stack.push CfScript::Scope::Script.new(options)
71
+ @cf_call_stack.last.run(&block)
72
+ rescue StandardError => e
73
+ print_error(e)
74
+ ensure
75
+ @cf_call_stack.last.finalize if @cf_call_stack.last
76
+ @cf_call_stack.pop
77
+ end
78
+
79
+ def stack_level
80
+ @cf_call_stack.length - 1
81
+ end
82
+
83
+ def print_error(e)
84
+ error "cf:#{stack_level}", e.message
85
+ e.backtrace.each do |line|
86
+ error "cf:#{stack_level}", line
87
+ end
88
+
89
+ if stdout.is_a?(StringIO)
90
+ STDOUT.puts "cf:#{stack_level} #{e.message}"
91
+ e.backtrace.each do |line|
92
+ STDOUT.puts "cf:#{stack_level} #{line}"
93
+ end
94
+ end
95
+ end
96
+
97
+ class << self
98
+ private :stack_level
99
+ private :print_error
100
+ end
101
+ end
102
+
103
+ def cf(options = {}, &block)
104
+ CfScript.cf(options, &block)
105
+ end
@@ -0,0 +1,18 @@
1
+ ---
2
+ stdout: |
3
+ Showing health and status for app email-worker in org ACME / space staging as user@example.com...
4
+ OK
5
+
6
+ requested state: stopped
7
+ instances: 0/1
8
+ usage: 32M x 1 instances
9
+ urls:
10
+ last uploaded: Fri Dec 25 00:00:00 UTC 2015
11
+ stack: cflinuxfs2
12
+ buildpack: https://github.com/cloudfoundry/binary-buildpack.git
13
+
14
+ There are no running instances of this app.
15
+
16
+ stderr: ''
17
+ status:
18
+ exitstatus: 0
@@ -0,0 +1,8 @@
1
+ ---
2
+ stdout: |
3
+ FAILED
4
+ App app-name not found
5
+
6
+ stderr: ''
7
+ status:
8
+ exitstatus: 0
@@ -0,0 +1,19 @@
1
+ ---
2
+ stdout: |
3
+ Showing health and status for app email-worker in org ACME / space staging as user@example.com...
4
+ OK
5
+
6
+ requested state: started
7
+ instances: 1/1
8
+ usage: 32M x 1 instances
9
+ urls:
10
+ last uploaded: Tue Dec 15 22:22:28 UTC 2015
11
+ stack: cflinuxfs2
12
+ buildpack: https://github.com/cloudfoundry/binary-buildpack.git
13
+
14
+ state since cpu memory disk details
15
+ #0 running 2015-12-22 08:49:38 AM 0.0% 2M of 32M 27.8M of 1G
16
+
17
+ stderr: ''
18
+ status:
19
+ exitstatus: 0
@@ -0,0 +1,14 @@
1
+ ---
2
+ stdout: |
3
+ Getting apps in org ACME / space test as user@example.com...
4
+ OK
5
+
6
+ name requested state instances memory disk urls
7
+ org-one-api stopped 0/1 256M 1G example.com, example.net
8
+ org-one-worker started 1/3 1G 2G
9
+ org-two-api stopped 0/2 256M 3G example.io, example.org
10
+ org-two-worker started 1/1 2G 4G
11
+
12
+ stderr: ''
13
+ status:
14
+ exitstatus: 0
@@ -0,0 +1,10 @@
1
+ ---
2
+ stdout: |
3
+ Getting apps in org ACME / space development as user@example.com...
4
+ OK
5
+
6
+ No apps found
7
+
8
+ stderr: ''
9
+ status:
10
+ exitstatus: 0
@@ -0,0 +1,37 @@
1
+ ---
2
+ stdout: |
3
+ Getting env variables for app email-worker in org ACME / space staging as user@example.com...
4
+ OK
5
+
6
+ System-Provided:
7
+
8
+
9
+ {
10
+ "VCAP_APPLICATION": {
11
+ "application_id": "00000000-0000-0000-0000-000000000000",
12
+ "application_name": "email-worker",
13
+ "application_uris": [],
14
+ "application_version": "00000000-0000-0000-0000-000000000000",
15
+ "limits": {
16
+ "disk": 1024,
17
+ "fds": 16384,
18
+ "mem": 4
19
+ },
20
+ "name": "email-worker",
21
+ "space_id": "00000000-0000-0000-0000-000000000000",
22
+ "space_name": "staging",
23
+ "uris": [],
24
+ "users": null,
25
+ "version": "00000000-0000-0000-0000-000000000000"
26
+ }
27
+ }
28
+
29
+ No user-defined env variables have been set
30
+
31
+ No running env variables have been set
32
+
33
+ No staging env variables have been set
34
+
35
+ stderr: ''
36
+ status:
37
+ exitstatus: 0
@@ -0,0 +1,41 @@
1
+ ---
2
+ stdout: |
3
+ Getting env variables for app email-worker in org ACME / space development as user@example.com...
4
+ OK
5
+
6
+ System-Provided:
7
+
8
+
9
+ {
10
+ "VCAP_APPLICATION": {
11
+ "application_id": "00000000-0000-0000-0000-000000000000",
12
+ "application_name": "email-worker",
13
+ "application_uris": [],
14
+ "application_version": "00000000-0000-0000-0000-000000000000",
15
+ "limits": {
16
+ "disk": 1024,
17
+ "fds": 16384,
18
+ "mem": 8
19
+ },
20
+ "name": "email-worker",
21
+ "space_id": "00000000-0000-0000-0000-000000000000",
22
+ "space_name": "development",
23
+ "uris": [],
24
+ "users": null,
25
+ "version": "00000000-0000-0000-0000-000000000000"
26
+ }
27
+ }
28
+
29
+ User-Provided:
30
+ SERVER_HOSTNAME: host.example.com
31
+ SERVER_HOSTPORT: 1234
32
+ SERVER_PASSWORD: word
33
+ SERVER_USERNAME: name
34
+
35
+ No running env variables have been set
36
+
37
+ No staging env variables have been set
38
+
39
+ stderr: ''
40
+ status:
41
+ exitstatus: 0
@@ -0,0 +1,60 @@
1
+ ---
2
+ stdout: |
3
+ Updating app development-worker in org ACME / space development as user@example.com...
4
+ OK
5
+
6
+ App development-worker is a worker, skipping route creation
7
+ Uploading development-worker...
8
+ Uploading app files from: /path/to/app
9
+ Uploading 12M, 345 files
10
+ Done uploading
11
+ OK
12
+
13
+ Stopping app development-worker in org ACME / space development as user@example.com...
14
+ OK
15
+
16
+ Starting app development-worker in org ACME / space development as user@example.com...
17
+ Creating container
18
+ Successfully created container
19
+ Downloading app package...
20
+ Downloaded app package (411B)
21
+ Downloading buildpacks (https://github.com/cloudfoundry/binary-buildpack.git), build artifacts cache...
22
+ Downloading build artifacts cache...
23
+ Downloaded build artifacts cache (108B)
24
+ Downloaded buildpacks
25
+ Staging...
26
+ Exit status 0
27
+ Staging complete
28
+ Uploading droplet, build artifacts cache...
29
+ Uploading droplet...
30
+ Uploading build artifacts cache...
31
+ Uploaded build artifacts cache (108B)
32
+ Uploaded droplet (401B)
33
+ Uploading complete
34
+
35
+ 1 of 1 instances running
36
+
37
+ App started
38
+
39
+
40
+ OK
41
+
42
+ App development-worker was started using this command `./worker`
43
+
44
+ Showing health and status for app development-worker in org ACME / space development as user@example.com...
45
+ OK
46
+
47
+ requested state: started
48
+ instances: 1/1
49
+ usage: 8M x 1 instances
50
+ urls:
51
+ last uploaded: Wed Dec 23 03:07:26 UTC 2015
52
+ stack: cflinuxfs2
53
+ buildpack: https://github.com/cloudfoundry/binary-buildpack.git
54
+
55
+ state since cpu memory disk details
56
+ \#0 running 2015-12-23 05:07:42 AM 0.0% 2.2M of 8M 27.8M of 1G
57
+
58
+ stderr: ''
59
+ status:
60
+ exitstatus: 0