trucker-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (294) hide show
  1. checksums.yaml +15 -0
  2. data/LICENSE +1277 -0
  3. data/Rakefile +13 -0
  4. data/bin/truck +18 -0
  5. data/lib/admin/README.md +30 -0
  6. data/lib/admin/curl.rb +59 -0
  7. data/lib/admin/guid.rb +89 -0
  8. data/lib/admin/plugin.rb +8 -0
  9. data/lib/admin/service_auth_token.rb +93 -0
  10. data/lib/admin/service_broker/add.rb +54 -0
  11. data/lib/admin/service_broker/remove.rb +33 -0
  12. data/lib/admin/service_broker/service_brokers.rb +29 -0
  13. data/lib/admin/service_broker/update.rb +60 -0
  14. data/lib/admin/set_quota.rb +44 -0
  15. data/lib/cf.rb +14 -0
  16. data/lib/cf/cli.rb +495 -0
  17. data/lib/cf/cli/app/app.rb +43 -0
  18. data/lib/cf/cli/app/apps.rb +87 -0
  19. data/lib/cf/cli/app/base.rb +72 -0
  20. data/lib/cf/cli/app/delete.rb +95 -0
  21. data/lib/cf/cli/app/deprecated.rb +11 -0
  22. data/lib/cf/cli/app/env.rb +99 -0
  23. data/lib/cf/cli/app/events.rb +45 -0
  24. data/lib/cf/cli/app/files.rb +137 -0
  25. data/lib/cf/cli/app/health.rb +26 -0
  26. data/lib/cf/cli/app/instances.rb +53 -0
  27. data/lib/cf/cli/app/logs.rb +76 -0
  28. data/lib/cf/cli/app/push.rb +104 -0
  29. data/lib/cf/cli/app/push/create.rb +108 -0
  30. data/lib/cf/cli/app/push/interactions.rb +90 -0
  31. data/lib/cf/cli/app/push/sync.rb +57 -0
  32. data/lib/cf/cli/app/rename.rb +35 -0
  33. data/lib/cf/cli/app/restart.rb +31 -0
  34. data/lib/cf/cli/app/scale.rb +63 -0
  35. data/lib/cf/cli/app/start.rb +175 -0
  36. data/lib/cf/cli/app/stats.rb +66 -0
  37. data/lib/cf/cli/app/stop.rb +27 -0
  38. data/lib/cf/cli/domain/base.rb +9 -0
  39. data/lib/cf/cli/domain/domains.rb +40 -0
  40. data/lib/cf/cli/domain/map.rb +55 -0
  41. data/lib/cf/cli/domain/unmap.rb +56 -0
  42. data/lib/cf/cli/help.rb +15 -0
  43. data/lib/cf/cli/interactive.rb +104 -0
  44. data/lib/cf/cli/login_requirements.rb +13 -0
  45. data/lib/cf/cli/organization/base.rb +12 -0
  46. data/lib/cf/cli/organization/create.rb +36 -0
  47. data/lib/cf/cli/organization/delete.rb +61 -0
  48. data/lib/cf/cli/organization/org.rb +45 -0
  49. data/lib/cf/cli/organization/orgs.rb +30 -0
  50. data/lib/cf/cli/organization/rename.rb +36 -0
  51. data/lib/cf/cli/populators/base.rb +16 -0
  52. data/lib/cf/cli/populators/organization.rb +32 -0
  53. data/lib/cf/cli/populators/populator_methods.rb +64 -0
  54. data/lib/cf/cli/populators/space.rb +33 -0
  55. data/lib/cf/cli/populators/target.rb +14 -0
  56. data/lib/cf/cli/route/base.rb +9 -0
  57. data/lib/cf/cli/route/delete.rb +28 -0
  58. data/lib/cf/cli/route/map.rb +68 -0
  59. data/lib/cf/cli/route/routes.rb +26 -0
  60. data/lib/cf/cli/route/unmap.rb +56 -0
  61. data/lib/cf/cli/service/base.rb +9 -0
  62. data/lib/cf/cli/service/bind.rb +43 -0
  63. data/lib/cf/cli/service/create.rb +158 -0
  64. data/lib/cf/cli/service/delete.rb +82 -0
  65. data/lib/cf/cli/service/rename.rb +35 -0
  66. data/lib/cf/cli/service/service.rb +40 -0
  67. data/lib/cf/cli/service/service_helper.rb +25 -0
  68. data/lib/cf/cli/service/service_instance_helper.rb +100 -0
  69. data/lib/cf/cli/service/services.rb +110 -0
  70. data/lib/cf/cli/service/unbind.rb +36 -0
  71. data/lib/cf/cli/space/base.rb +27 -0
  72. data/lib/cf/cli/space/create.rb +66 -0
  73. data/lib/cf/cli/space/delete.rb +55 -0
  74. data/lib/cf/cli/space/rename.rb +38 -0
  75. data/lib/cf/cli/space/space.rb +66 -0
  76. data/lib/cf/cli/space/spaces.rb +57 -0
  77. data/lib/cf/cli/space/switch.rb +18 -0
  78. data/lib/cf/cli/start/base.rb +35 -0
  79. data/lib/cf/cli/start/colors.rb +13 -0
  80. data/lib/cf/cli/start/login.rb +104 -0
  81. data/lib/cf/cli/start/logout.rb +17 -0
  82. data/lib/cf/cli/start/target.rb +50 -0
  83. data/lib/cf/cli/start/target_prettifier.rb +35 -0
  84. data/lib/cf/cli/start/targets.rb +16 -0
  85. data/lib/cf/cli/user/base.rb +29 -0
  86. data/lib/cf/cli/user/create.rb +51 -0
  87. data/lib/cf/cli/user/passwd.rb +36 -0
  88. data/lib/cf/cli/user/register.rb +42 -0
  89. data/lib/cf/cli/user/users.rb +32 -0
  90. data/lib/cf/constants.rb +10 -0
  91. data/lib/cf/errors.rb +19 -0
  92. data/lib/cf/plugin.rb +56 -0
  93. data/lib/cf/spacing.rb +89 -0
  94. data/lib/cf/spec_helper.rb +1 -0
  95. data/lib/cf/test_support.rb +6 -0
  96. data/lib/cf/version.rb +3 -0
  97. data/lib/console/README.md +16 -0
  98. data/lib/console/console.rb +187 -0
  99. data/lib/console/plugin.rb +32 -0
  100. data/lib/manifests/errors.rb +35 -0
  101. data/lib/manifests/loader.rb +31 -0
  102. data/lib/manifests/loader/builder.rb +39 -0
  103. data/lib/manifests/loader/normalizer.rb +145 -0
  104. data/lib/manifests/loader/resolver.rb +79 -0
  105. data/lib/manifests/manifests.rb +343 -0
  106. data/lib/manifests/plugin.rb +140 -0
  107. data/lib/micro/README.md +25 -0
  108. data/lib/micro/errors.rb +4 -0
  109. data/lib/micro/micro.rb +56 -0
  110. data/lib/micro/plugin.rb +197 -0
  111. data/lib/micro/switcher/base.rb +79 -0
  112. data/lib/micro/switcher/darwin.rb +21 -0
  113. data/lib/micro/switcher/dummy.rb +15 -0
  114. data/lib/micro/switcher/linux.rb +16 -0
  115. data/lib/micro/switcher/windows.rb +31 -0
  116. data/lib/micro/vmrun.rb +175 -0
  117. data/lib/tasks/gem_release.rake +56 -0
  118. data/lib/tasks/windows_build.rake +14 -0
  119. data/lib/tunnel/README.md +29 -0
  120. data/lib/tunnel/config/clients.yml +17 -0
  121. data/lib/tunnel/helper-app/Gemfile +10 -0
  122. data/lib/tunnel/helper-app/Gemfile.lock +48 -0
  123. data/lib/tunnel/helper-app/server.rb +43 -0
  124. data/lib/tunnel/plugin.rb +183 -0
  125. data/lib/tunnel/tunnel.rb +295 -0
  126. data/spec/admin/curl_spec.rb +52 -0
  127. data/spec/admin/guid_spec.rb +85 -0
  128. data/spec/admin/service_broker/add_spec.rb +64 -0
  129. data/spec/admin/service_broker/remove_spec.rb +46 -0
  130. data/spec/admin/service_broker/service_brokers_spec.rb +34 -0
  131. data/spec/admin/service_broker/update_spec.rb +51 -0
  132. data/spec/admin/set_quota_spec.rb +89 -0
  133. data/spec/assets/env/Gemfile +4 -0
  134. data/spec/assets/env/Gemfile.lock +20 -0
  135. data/spec/assets/env/env_test.rb +58 -0
  136. data/spec/assets/hello-sinatra/Gemfile +3 -0
  137. data/spec/assets/hello-sinatra/Gemfile.lock +17 -0
  138. data/spec/assets/hello-sinatra/config.ru +3 -0
  139. data/spec/assets/hello-sinatra/fat-cat-makes-app-larger.png +0 -0
  140. data/spec/assets/hello-sinatra/main.rb +8 -0
  141. data/spec/assets/rails328_ruby187_app/Gemfile +39 -0
  142. data/spec/assets/rails328_ruby187_app/README.rdoc +261 -0
  143. data/spec/assets/rails328_ruby187_app/Rakefile +7 -0
  144. data/spec/assets/rails328_ruby187_app/app/assets/images/rails.png +0 -0
  145. data/spec/assets/rails328_ruby187_app/app/assets/javascripts/application.js +15 -0
  146. data/spec/assets/rails328_ruby187_app/app/assets/stylesheets/application.css +13 -0
  147. data/spec/assets/rails328_ruby187_app/app/controllers/application_controller.rb +3 -0
  148. data/spec/assets/rails328_ruby187_app/app/helpers/application_helper.rb +2 -0
  149. data/spec/assets/rails328_ruby187_app/app/views/layouts/application.html.erb +14 -0
  150. data/spec/assets/rails328_ruby187_app/config.ru +4 -0
  151. data/spec/assets/rails328_ruby187_app/config/application.rb +62 -0
  152. data/spec/assets/rails328_ruby187_app/config/boot.rb +6 -0
  153. data/spec/assets/rails328_ruby187_app/config/database.yml +25 -0
  154. data/spec/assets/rails328_ruby187_app/config/environment.rb +5 -0
  155. data/spec/assets/rails328_ruby187_app/config/environments/development.rb +37 -0
  156. data/spec/assets/rails328_ruby187_app/config/environments/production.rb +67 -0
  157. data/spec/assets/rails328_ruby187_app/config/environments/test.rb +37 -0
  158. data/spec/assets/rails328_ruby187_app/config/initializers/backtrace_silencers.rb +7 -0
  159. data/spec/assets/rails328_ruby187_app/config/initializers/inflections.rb +15 -0
  160. data/spec/assets/rails328_ruby187_app/config/initializers/mime_types.rb +5 -0
  161. data/spec/assets/rails328_ruby187_app/config/initializers/secret_token.rb +7 -0
  162. data/spec/assets/rails328_ruby187_app/config/initializers/session_store.rb +8 -0
  163. data/spec/assets/rails328_ruby187_app/config/initializers/wrap_parameters.rb +14 -0
  164. data/spec/assets/rails328_ruby187_app/config/locales/en.yml +5 -0
  165. data/spec/assets/rails328_ruby187_app/config/routes.rb +58 -0
  166. data/spec/assets/rails328_ruby187_app/db/seeds.rb +7 -0
  167. data/spec/assets/rails328_ruby187_app/doc/README_FOR_APP +2 -0
  168. data/spec/assets/rails328_ruby187_app/manifest.yml +7 -0
  169. data/spec/assets/rails328_ruby187_app/public/404.html +26 -0
  170. data/spec/assets/rails328_ruby187_app/public/422.html +26 -0
  171. data/spec/assets/rails328_ruby187_app/public/500.html +25 -0
  172. data/spec/assets/rails328_ruby187_app/public/assets/application-7270767b2a9e9fff880aa5de378ca791.css +0 -0
  173. data/spec/assets/rails328_ruby187_app/public/assets/application-7270767b2a9e9fff880aa5de378ca791.css.gz +0 -0
  174. data/spec/assets/rails328_ruby187_app/public/assets/application-ccab98dc1abdf097c0af693e20aed861.js +17 -0
  175. data/spec/assets/rails328_ruby187_app/public/assets/application-ccab98dc1abdf097c0af693e20aed861.js.gz +0 -0
  176. data/spec/assets/rails328_ruby187_app/public/assets/application.css +0 -0
  177. data/spec/assets/rails328_ruby187_app/public/assets/application.css.gz +0 -0
  178. data/spec/assets/rails328_ruby187_app/public/assets/application.js +17 -0
  179. data/spec/assets/rails328_ruby187_app/public/assets/application.js.gz +0 -0
  180. data/spec/assets/rails328_ruby187_app/public/assets/manifest.yml +4 -0
  181. data/spec/assets/rails328_ruby187_app/public/assets/rails-be8732dac73d845ac5b142c8fb5f9fb0.png +0 -0
  182. data/spec/assets/rails328_ruby187_app/public/assets/rails.png +0 -0
  183. data/spec/assets/rails328_ruby187_app/public/favicon.ico +0 -0
  184. data/spec/assets/rails328_ruby187_app/public/index.html +241 -0
  185. data/spec/assets/rails328_ruby187_app/public/robots.txt +5 -0
  186. data/spec/assets/rails328_ruby187_app/script/rails +6 -0
  187. data/spec/assets/rails328_ruby187_app/test/performance/browsing_test.rb +12 -0
  188. data/spec/assets/rails328_ruby187_app/test/test_helper.rb +13 -0
  189. data/spec/cf/cli/app/base_spec.rb +17 -0
  190. data/spec/cf/cli/app/delete_spec.rb +197 -0
  191. data/spec/cf/cli/app/env_spec.rb +261 -0
  192. data/spec/cf/cli/app/events_spec.rb +72 -0
  193. data/spec/cf/cli/app/help_spec.rb +39 -0
  194. data/spec/cf/cli/app/instances_spec.rb +69 -0
  195. data/spec/cf/cli/app/push/create_spec.rb +444 -0
  196. data/spec/cf/cli/app/push/interactions_spec.rb +32 -0
  197. data/spec/cf/cli/app/push_spec.rb +332 -0
  198. data/spec/cf/cli/app/rename_spec.rb +108 -0
  199. data/spec/cf/cli/app/restart_spec.rb +47 -0
  200. data/spec/cf/cli/app/scale_spec.rb +63 -0
  201. data/spec/cf/cli/app/start_spec.rb +255 -0
  202. data/spec/cf/cli/app/stats_spec.rb +66 -0
  203. data/spec/cf/cli/domain/help_spec.rb +39 -0
  204. data/spec/cf/cli/domain/map_spec.rb +140 -0
  205. data/spec/cf/cli/domain/unmap_spec.rb +77 -0
  206. data/spec/cf/cli/help_spec.rb +21 -0
  207. data/spec/cf/cli/organization/create_spec.rb +121 -0
  208. data/spec/cf/cli/organization/delete_spec.rb +105 -0
  209. data/spec/cf/cli/organization/help_spec.rb +39 -0
  210. data/spec/cf/cli/organization/orgs_spec.rb +116 -0
  211. data/spec/cf/cli/organization/rename_spec.rb +116 -0
  212. data/spec/cf/cli/populators/organization_spec.rb +179 -0
  213. data/spec/cf/cli/populators/space_spec.rb +156 -0
  214. data/spec/cf/cli/populators/target_spec.rb +39 -0
  215. data/spec/cf/cli/route/delete_spec.rb +92 -0
  216. data/spec/cf/cli/route/help_spec.rb +32 -0
  217. data/spec/cf/cli/route/map_spec.rb +148 -0
  218. data/spec/cf/cli/route/unmap_spec.rb +114 -0
  219. data/spec/cf/cli/service/bind_spec.rb +25 -0
  220. data/spec/cf/cli/service/create_spec.rb +147 -0
  221. data/spec/cf/cli/service/delete_spec.rb +22 -0
  222. data/spec/cf/cli/service/help_spec.rb +39 -0
  223. data/spec/cf/cli/service/rename_spec.rb +103 -0
  224. data/spec/cf/cli/service/service_helper_spec.rb +66 -0
  225. data/spec/cf/cli/service/service_instance_helper_spec.rb +155 -0
  226. data/spec/cf/cli/service/service_spec.rb +23 -0
  227. data/spec/cf/cli/service/services_spec.rb +156 -0
  228. data/spec/cf/cli/service/unbind_spec.rb +25 -0
  229. data/spec/cf/cli/space/base_spec.rb +49 -0
  230. data/spec/cf/cli/space/create_spec.rb +144 -0
  231. data/spec/cf/cli/space/delete_spec.rb +109 -0
  232. data/spec/cf/cli/space/help_spec.rb +39 -0
  233. data/spec/cf/cli/space/rename_spec.rb +110 -0
  234. data/spec/cf/cli/space/space_spec.rb +80 -0
  235. data/spec/cf/cli/space/spaces_spec.rb +107 -0
  236. data/spec/cf/cli/space/switch_space_spec.rb +57 -0
  237. data/spec/cf/cli/start/help_spec.rb +39 -0
  238. data/spec/cf/cli/start/login_spec.rb +142 -0
  239. data/spec/cf/cli/start/logout_spec.rb +49 -0
  240. data/spec/cf/cli/start/target_prettifier_spec.rb +78 -0
  241. data/spec/cf/cli/start/target_spec.rb +123 -0
  242. data/spec/cf/cli/user/create_spec.rb +98 -0
  243. data/spec/cf/cli/user/help_spec.rb +32 -0
  244. data/spec/cf/cli/user/passwd_spec.rb +94 -0
  245. data/spec/cf/cli/user/register_spec.rb +145 -0
  246. data/spec/cf/cli_spec.rb +474 -0
  247. data/spec/console/console_spec.rb +189 -0
  248. data/spec/factories/cfoundry/v2/apps_factory.rb +12 -0
  249. data/spec/factories/cfoundry/v2/clients_factory.rb +7 -0
  250. data/spec/factories/cfoundry/v2/domains_factory.rb +8 -0
  251. data/spec/factories/cfoundry/v2/managed_service_instances_factory.rb +13 -0
  252. data/spec/factories/cfoundry/v2/organizations_factory.rb +14 -0
  253. data/spec/factories/cfoundry/v2/quota_definitions.rb +13 -0
  254. data/spec/factories/cfoundry/v2/routes_factory.rb +8 -0
  255. data/spec/factories/cfoundry/v2/service_bindings_factory.rb +11 -0
  256. data/spec/factories/cfoundry/v2/service_brokers_factory.rb +11 -0
  257. data/spec/factories/cfoundry/v2/service_plans_factory.rb +17 -0
  258. data/spec/factories/cfoundry/v2/services_factory.rb +14 -0
  259. data/spec/factories/cfoundry/v2/spaces_factory.rb +13 -0
  260. data/spec/factories/cfoundry/v2/stacks_factory.rb +11 -0
  261. data/spec/factories/cfoundry/v2/user_provided_service_instances_factory.rb +12 -0
  262. data/spec/factories/cfoundry/v2/users_factory.rb +7 -0
  263. data/spec/features/backspace_spec.rb +46 -0
  264. data/spec/features/create_user_spec.rb +74 -0
  265. data/spec/features/delete_orphaned_service_spec.rb +64 -0
  266. data/spec/features/login_spec.rb +65 -0
  267. data/spec/features/manifests_spec.rb +86 -0
  268. data/spec/features/org_spec.rb +50 -0
  269. data/spec/features/push_flow_spec.rb +169 -0
  270. data/spec/features/service_brokers_spec.rb +173 -0
  271. data/spec/features/services_spec.rb +122 -0
  272. data/spec/features/space_spec.rb +107 -0
  273. data/spec/features/switching_targets_spec.rb +70 -0
  274. data/spec/manifests/errors_spec.rb +43 -0
  275. data/spec/manifests/loader/builder_spec.rb +80 -0
  276. data/spec/manifests/loader/normalizer_spec.rb +158 -0
  277. data/spec/manifests/manifests_spec.rb +335 -0
  278. data/spec/manifests/plugin_spec.rb +410 -0
  279. data/spec/micro/plugin_spec.rb +64 -0
  280. data/spec/spec_helper.rb +69 -0
  281. data/spec/support/cli_helper.rb +87 -0
  282. data/spec/support/config_helper.rb +15 -0
  283. data/spec/support/factory_girl.rb +6 -0
  284. data/spec/support/fake_home_dir.rb +55 -0
  285. data/spec/support/features_helper.rb +99 -0
  286. data/spec/support/interact_helper.rb +27 -0
  287. data/spec/support/matchers.rb +16 -0
  288. data/spec/support/mock_commands/mock_restart.rb +16 -0
  289. data/spec/support/mock_commands/mock_start.rb +17 -0
  290. data/spec/support/shared_examples/errors.rb +40 -0
  291. data/spec/support/shared_examples/input.rb +14 -0
  292. data/spec/tunnel/plugin_spec.rb +31 -0
  293. data/spec/tunnel/tunnel_spec.rb +54 -0
  294. metadata +814 -0
@@ -0,0 +1,66 @@
1
+ require "cf/cli/app/base"
2
+
3
+ module CF::App
4
+ class Stats < Base
5
+ desc "Display application instance status"
6
+ group :apps, :info
7
+ input :app, :desc => "Application to get the stats for",
8
+ :argument => true, :from_given => by_name(:app)
9
+ def stats
10
+ app = input[:app]
11
+ stats =
12
+ with_progress("Getting stats for #{c(app.name, :name)}") do |s|
13
+ begin
14
+ app.stats
15
+ rescue CFoundry::StatsError
16
+ s.fail do
17
+ err "Application #{b(app.name)} is not running."
18
+ return
19
+ end
20
+ end
21
+ end
22
+
23
+ line unless quiet?
24
+
25
+ table(
26
+ %w{instance cpu memory disk},
27
+ stats.sort_by { |idx, _| idx.to_i }.collect { |idx, info|
28
+ idx = c("\##{idx}", :instance)
29
+
30
+ if info[:state] == "DOWN"
31
+ [idx, c("down", :bad)]
32
+ else
33
+ stats = info[:stats]
34
+ usage = stats[:usage]
35
+
36
+ if usage
37
+ [ idx,
38
+ "#{percentage(usage[:cpu])}",
39
+ "#{usage(usage[:mem], stats[:mem_quota])}",
40
+ "#{usage(usage[:disk], stats[:disk_quota])}"
41
+ ]
42
+ else
43
+ [idx, c("n/a", :neutral)]
44
+ end
45
+ end
46
+ })
47
+ end
48
+
49
+ def percentage(num, low = 50, mid = 70)
50
+ color =
51
+ if num <= low
52
+ :good
53
+ elsif num <= mid
54
+ :warning
55
+ else
56
+ :bad
57
+ end
58
+
59
+ c(format("%.1f\%", num), color)
60
+ end
61
+
62
+ def usage(used, limit)
63
+ "#{b(human_size(used))} of #{b(human_size(limit, 0))}"
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,27 @@
1
+ require "cf/cli/app/base"
2
+
3
+ module CF::App
4
+ class Stop < Base
5
+ desc "Stop an application"
6
+ group :apps, :manage
7
+ input :apps, :desc => "Applications to start", :argument => :splat,
8
+ :singular => :app, :from_given => by_name(:app)
9
+ input :all, :desc => "Stop all applications", :default => false
10
+ def stop
11
+ apps = input[:all] ? client.apps : input[:apps]
12
+ fail "No applications given." if apps.empty?
13
+
14
+ apps.each do |app|
15
+ with_progress("Stopping #{c(app.name, :name)}") do |s|
16
+ if app.stopped?
17
+ s.skip do
18
+ err "Application is not running."
19
+ end
20
+ end
21
+
22
+ app.stop!
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ require "cf/cli"
2
+
3
+ module CF
4
+ module Domain
5
+ class Base < CLI
6
+ include LoginRequirements
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,40 @@
1
+ require "cf/cli/domain/base"
2
+
3
+ module CF::Domain
4
+ class Domains < Base
5
+ desc "List domains in a space"
6
+ group :domains
7
+ input :space, :desc => "Space to list the domains from",
8
+ :argument => :optional, :default => proc { client.current_space },
9
+ :from_given => by_name(:space)
10
+ input :all, :desc => "List all domains", :default => false
11
+ def domains
12
+ space = input[:space]
13
+
14
+ domains =
15
+ if input[:all]
16
+ with_progress("Getting all domains") do
17
+ client.domains
18
+ end
19
+ else
20
+ with_progress("Getting domains in #{c(space.name, :name)}") do
21
+ space.domains
22
+ end
23
+ end
24
+
25
+ line unless quiet?
26
+
27
+ table(
28
+ %w{name owner},
29
+ domains.sort_by(&:name).collect { |r|
30
+ [c(r.name, :name),
31
+ if org = r.owning_organization
32
+ c(org.name, :name)
33
+ else
34
+ d("none")
35
+ end
36
+ ]
37
+ })
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,55 @@
1
+ require "cf/cli/domain/base"
2
+
3
+ module CF::Domain
4
+ class Map < Base
5
+ desc "Map a domain to an organization or space"
6
+ group :domains
7
+ input :name, :desc => "Domain to map", :argument => :required
8
+ input :organization, :desc => "Organization to map the domain to",
9
+ :aliases => %w{--org -o},
10
+ :default => proc { client.current_organization },
11
+ :from_given => by_name(:organization)
12
+ input :space, :desc => "Space to map the domain to",
13
+ :default => proc { client.current_space },
14
+ :from_given => by_name(:space)
15
+ input :shared, :desc => "Create a shared domain", :default => false
16
+ def map_domain
17
+ domain = client.domain_by_name(input[:name])
18
+
19
+ given_org = input.has?(:organization)
20
+ given_space = input.has?(:space)
21
+
22
+ org = input[:organization]
23
+ space = input[:space]
24
+
25
+ given_space = true unless given_org || given_space
26
+
27
+ unless domain
28
+ domain = client.domain
29
+ domain.name = input[:name]
30
+ domain.owning_organization = org unless input[:shared]
31
+ domain.wildcard = true
32
+
33
+ with_progress("Creating domain #{c(domain.name, :name)}") do
34
+ domain.create!
35
+ org.add_domain(domain) if org && !given_org && !given_space
36
+ end
37
+ end
38
+
39
+ if given_space
40
+ add_domain(domain, space.organization)
41
+ add_domain(domain, space)
42
+ elsif given_org
43
+ add_domain(domain, org)
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def add_domain(domain, target)
50
+ with_progress("Mapping #{c(domain.name, :name)} to #{c(target.name, :name)}") do
51
+ target.add_domain(domain)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,56 @@
1
+ require "cf/cli/domain/base"
2
+
3
+ module CF::Domain
4
+ class Unmap < Base
5
+ desc "Unmap a domain from an organization or space"
6
+ group :domains
7
+ input :domain, :desc => "Domain to unmap", :argument => :required,
8
+ :from_given => by_name("domain")
9
+ input :organization, :desc => "Organization to unmap the domain from",
10
+ :aliases => %w{--org -o},
11
+ :default => proc { client.current_organization },
12
+ :from_given => by_name(:organization)
13
+ input :space, :desc => "Space to unmap the domain from",
14
+ :default => proc { client.current_space },
15
+ :from_given => by_name(:space)
16
+ input :delete, :desc => "Delete domain", :type => :boolean
17
+ input :really, :type => :boolean, :forget => true, :hidden => true,
18
+ :default => proc { force? || interact }
19
+ def unmap_domain
20
+ domain = input[:domain]
21
+
22
+ given_org = input.has?(:organization)
23
+ given_space = input.has?(:space)
24
+
25
+ org = input[:organization]
26
+ space = input[:space]
27
+
28
+ if input[:delete]
29
+ return unless input[:really, domain.name, :name]
30
+
31
+ with_progress("Deleting domain #{c(domain.name, :name)}") do
32
+ domain.delete!
33
+ end
34
+
35
+ return
36
+ end
37
+
38
+ given_space = true unless given_org || given_space
39
+
40
+ remove_domain(domain, space) if given_space
41
+ remove_domain(domain, org) if given_org
42
+ end
43
+
44
+ private
45
+
46
+ def remove_domain(domain, target)
47
+ with_progress("Unmapping #{c(domain.name, :name)} from #{c(target.name, :name)}") do
48
+ target.remove_domain(domain)
49
+ end
50
+ end
51
+
52
+ def ask_really(name, color)
53
+ ask("Really delete #{c(name, color)}?", :default => false)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ require "mothership/help"
2
+
3
+ Mothership::Help.groups(
4
+ [:start, "Getting Started"],
5
+ [:apps, "Applications",
6
+ [:manage, "Management"],
7
+ [:info, "Information"]],
8
+ [:services, "Services",
9
+ [:manage, "Management"]],
10
+ [:organizations, "Organizations"],
11
+ [:spaces, "Spaces"],
12
+ [:routes, "Routes"],
13
+ [:domains, "Domains"],
14
+ [:admin, "Administration",
15
+ [:user, "User Management"]])
@@ -0,0 +1,104 @@
1
+ require "interact"
2
+ require "interact/pretty"
3
+ require "interact/progress"
4
+
5
+ module CF
6
+ module Interactive
7
+ include ::Interactive::Rewindable
8
+ include Interact::Pretty
9
+ include Interact::Progress
10
+
11
+ def ask(question, options = {})
12
+ if force? and options.key?(:default)
13
+ options[:default]
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ def list_choices(choices, options = {})
20
+ choices.each_with_index do |o, i|
21
+ puts "#{c(i + 1, :number)}: #{show_choice(o, options)}"
22
+ end
23
+ end
24
+
25
+ def input_state(options)
26
+ if options.key? :default
27
+ answer = show_default(options)
28
+ end
29
+
30
+ CFState.new(options, answer)
31
+ end
32
+
33
+ def show_default(options)
34
+ case options[:default]
35
+ when true
36
+ "y"
37
+ when false
38
+ "n"
39
+ when nil
40
+ ""
41
+ else
42
+ show_choice(options[:default], options)
43
+ end
44
+ end
45
+
46
+ def prompt(question, options)
47
+ value = show_default(options)
48
+
49
+ print "#{question}"
50
+ print c("> ", :prompt)
51
+
52
+ unless value.empty?
53
+ print "#{d(value) + "\b" * value.size}"
54
+ end
55
+ end
56
+
57
+ def handler(event, state)
58
+ ans = state.answer
59
+
60
+ exit if event == :eof
61
+
62
+ if state.default?
63
+ if event.is_a?(Array) and event[0] == :key
64
+ # initial non-movement keypress clears default answer
65
+ clear_input(state)
66
+ else
67
+ # wipe away any coloring
68
+ redraw_input(state)
69
+ end
70
+
71
+ state.clear_default! if event != :up
72
+
73
+ # tab with a default accepts it and moves to the end
74
+ if event == :tab
75
+ state.goto(ans.size)
76
+ else
77
+ super
78
+ end
79
+ else
80
+ super
81
+ end
82
+
83
+ print "\n" if event == :enter
84
+ end
85
+
86
+ class CFState < ::Interactive::InputState
87
+ def initialize(options = {}, answer = nil, position = 0)
88
+ @options = options
89
+ @answer = answer || ""
90
+ @default = options.key? :default
91
+ @position = position
92
+ @done = false
93
+ end
94
+
95
+ def clear_default!
96
+ @default = false
97
+ end
98
+
99
+ def default?
100
+ @default
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,13 @@
1
+ module LoginRequirements
2
+ def precondition
3
+ check_logged_in
4
+
5
+ unless client.current_organization
6
+ fail "Please select an organization with 'truck target --organization ORGANIZATION_NAME'. (Get organization names from 'truck orgs'.)"
7
+ end
8
+
9
+ unless client.current_space
10
+ fail "Please select a space with 'truck target --space SPACE_NAME'. (Get space names from 'truck spaces'.)"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ require "cf/cli"
2
+
3
+ module CF
4
+ module Organization
5
+ class Base < CLI
6
+ def precondition
7
+ check_target
8
+ check_logged_in
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ require "cf/cli/organization/base"
2
+
3
+ module CF::Organization
4
+ class Create < Base
5
+ desc "Create an organization"
6
+ group :organizations
7
+ input :name, :desc => "Organization name", :argument => :optional
8
+ input :target, :desc => "Switch to the organization after creation",
9
+ :alias => "-t", :default => true
10
+ input :add_self, :desc => "Add yourself to the organization",
11
+ :default => true
12
+ input :find_if_exists, :desc => "Use an existing organization if one already exists with the given name", :default => false
13
+ def create_org
14
+ org = client.organization
15
+ org.name = input[:name]
16
+ org.users = [client.current_user] if input[:add_self]
17
+
18
+ begin
19
+ with_progress("Creating organization #{c(org.name, :name)}") { org.create! }
20
+ rescue CFoundry::OrganizationNameTaken
21
+ raise unless input[:find_if_exists]
22
+ org = client.organization_by_name(input[:name])
23
+ end
24
+
25
+ if input[:target]
26
+ invoke :target, :organization => org
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def ask_name
33
+ ask("Name")
34
+ end
35
+ end
36
+ end