cf 0.1.5 → 0.6.0.rc1

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 (140) hide show
  1. data/LICENSE +1277 -30
  2. data/Rakefile +12 -1
  3. data/bin/cf +0 -3
  4. data/lib/cf.rb +6 -0
  5. data/lib/cf/cli.rb +389 -190
  6. data/lib/cf/cli/app/app.rb +45 -0
  7. data/lib/cf/cli/app/apps.rb +99 -0
  8. data/lib/cf/cli/app/base.rb +90 -0
  9. data/lib/cf/cli/app/crashes.rb +42 -0
  10. data/lib/cf/cli/app/delete.rb +95 -0
  11. data/lib/cf/cli/app/deprecated.rb +11 -0
  12. data/lib/cf/cli/app/env.rb +78 -0
  13. data/lib/cf/cli/app/files.rb +137 -0
  14. data/lib/cf/cli/app/health.rb +26 -0
  15. data/lib/cf/cli/app/instances.rb +53 -0
  16. data/lib/cf/cli/app/logs.rb +76 -0
  17. data/lib/cf/cli/app/push.rb +105 -0
  18. data/lib/cf/cli/app/push/create.rb +149 -0
  19. data/lib/cf/cli/app/push/interactions.rb +94 -0
  20. data/lib/cf/cli/app/push/sync.rb +64 -0
  21. data/lib/cf/cli/app/rename.rb +35 -0
  22. data/lib/cf/cli/app/restart.rb +20 -0
  23. data/lib/cf/cli/app/scale.rb +69 -0
  24. data/lib/cf/cli/app/start.rb +143 -0
  25. data/lib/cf/cli/app/stats.rb +67 -0
  26. data/lib/cf/cli/app/stop.rb +27 -0
  27. data/lib/cf/cli/domain/base.rb +8 -0
  28. data/lib/cf/cli/domain/domains.rb +40 -0
  29. data/lib/cf/cli/domain/map.rb +55 -0
  30. data/lib/cf/cli/domain/unmap.rb +56 -0
  31. data/lib/cf/cli/help.rb +15 -0
  32. data/lib/cf/cli/interactive.rb +105 -0
  33. data/lib/cf/cli/organization/base.rb +12 -0
  34. data/lib/cf/cli/organization/create.rb +32 -0
  35. data/lib/cf/cli/organization/delete.rb +73 -0
  36. data/lib/cf/cli/organization/org.rb +45 -0
  37. data/lib/cf/cli/organization/orgs.rb +35 -0
  38. data/lib/cf/cli/organization/rename.rb +36 -0
  39. data/lib/cf/cli/route/base.rb +8 -0
  40. data/lib/cf/cli/route/map.rb +70 -0
  41. data/lib/cf/cli/route/routes.rb +26 -0
  42. data/lib/cf/cli/route/unmap.rb +62 -0
  43. data/lib/cf/cli/service/base.rb +8 -0
  44. data/lib/cf/cli/service/bind.rb +44 -0
  45. data/lib/cf/cli/service/create.rb +107 -0
  46. data/lib/cf/cli/service/delete.rb +82 -0
  47. data/lib/cf/cli/service/rename.rb +35 -0
  48. data/lib/cf/cli/service/service.rb +40 -0
  49. data/lib/cf/cli/service/services.rb +99 -0
  50. data/lib/cf/cli/service/unbind.rb +38 -0
  51. data/lib/cf/cli/space/base.rb +19 -0
  52. data/lib/cf/cli/space/create.rb +63 -0
  53. data/lib/cf/cli/space/delete.rb +95 -0
  54. data/lib/cf/cli/space/rename.rb +39 -0
  55. data/lib/cf/cli/space/space.rb +64 -0
  56. data/lib/cf/cli/space/spaces.rb +55 -0
  57. data/lib/cf/cli/space/switch.rb +16 -0
  58. data/lib/cf/cli/start/base.rb +93 -0
  59. data/lib/cf/cli/start/colors.rb +13 -0
  60. data/lib/cf/cli/start/info.rb +124 -0
  61. data/lib/cf/cli/start/login.rb +94 -0
  62. data/lib/cf/cli/start/logout.rb +17 -0
  63. data/lib/cf/cli/start/target.rb +69 -0
  64. data/lib/cf/cli/start/target_interactions.rb +37 -0
  65. data/lib/cf/cli/start/targets.rb +16 -0
  66. data/lib/cf/cli/user/base.rb +29 -0
  67. data/lib/cf/cli/user/create.rb +39 -0
  68. data/lib/cf/cli/user/passwd.rb +43 -0
  69. data/lib/cf/cli/user/register.rb +42 -0
  70. data/lib/cf/cli/user/users.rb +32 -0
  71. data/lib/cf/constants.rb +10 -7
  72. data/lib/cf/detect.rb +113 -48
  73. data/lib/cf/errors.rb +17 -0
  74. data/lib/cf/plugin.rb +28 -12
  75. data/lib/cf/spacing.rb +89 -0
  76. data/lib/cf/spec_helper.rb +1 -0
  77. data/lib/cf/test_support.rb +6 -0
  78. data/lib/cf/version.rb +1 -1
  79. data/spec/assets/hello-sinatra/Gemfile +3 -0
  80. data/spec/assets/hello-sinatra/Gemfile.lock +17 -0
  81. data/spec/assets/hello-sinatra/config.ru +3 -0
  82. data/spec/assets/hello-sinatra/fat-cat-makes-app-larger.png +0 -0
  83. data/spec/assets/hello-sinatra/main.rb +6 -0
  84. data/spec/assets/specker_runner/specker_runner_input.rb +6 -0
  85. data/spec/assets/specker_runner/specker_runner_pause.rb +5 -0
  86. data/spec/cf/cli/app/base_spec.rb +17 -0
  87. data/spec/cf/cli/app/delete_spec.rb +188 -0
  88. data/spec/cf/cli/app/instances_spec.rb +65 -0
  89. data/spec/cf/cli/app/push/create_spec.rb +661 -0
  90. data/spec/cf/cli/app/push_spec.rb +369 -0
  91. data/spec/cf/cli/app/rename_spec.rb +104 -0
  92. data/spec/cf/cli/app/scale_spec.rb +75 -0
  93. data/spec/cf/cli/app/start_spec.rb +208 -0
  94. data/spec/cf/cli/app/stats_spec.rb +68 -0
  95. data/spec/cf/cli/domain/map_spec.rb +130 -0
  96. data/spec/cf/cli/domain/unmap_spec.rb +69 -0
  97. data/spec/cf/cli/organization/orgs_spec.rb +108 -0
  98. data/spec/cf/cli/organization/rename_spec.rb +113 -0
  99. data/spec/cf/cli/route/map_spec.rb +121 -0
  100. data/spec/cf/cli/route/unmap_spec.rb +155 -0
  101. data/spec/cf/cli/service/bind_spec.rb +25 -0
  102. data/spec/cf/cli/service/delete_spec.rb +22 -0
  103. data/spec/cf/cli/service/rename_spec.rb +105 -0
  104. data/spec/cf/cli/service/service_spec.rb +23 -0
  105. data/spec/cf/cli/service/unbind_spec.rb +25 -0
  106. data/spec/cf/cli/space/create_spec.rb +93 -0
  107. data/spec/cf/cli/space/rename_spec.rb +102 -0
  108. data/spec/cf/cli/space/spaces_spec.rb +104 -0
  109. data/spec/cf/cli/space/switch_space_spec.rb +55 -0
  110. data/spec/cf/cli/start/info_spec.rb +160 -0
  111. data/spec/cf/cli/start/login_spec.rb +142 -0
  112. data/spec/cf/cli/start/logout_spec.rb +50 -0
  113. data/spec/cf/cli/start/target_spec.rb +123 -0
  114. data/spec/cf/cli/user/create_spec.rb +54 -0
  115. data/spec/cf/cli/user/passwd_spec.rb +102 -0
  116. data/spec/cf/cli/user/register_spec.rb +140 -0
  117. data/spec/cf/cli_spec.rb +442 -0
  118. data/spec/cf/detect_spec.rb +54 -0
  119. data/spec/console_app_specker/console_app_specker_matchers_spec.rb +173 -0
  120. data/spec/console_app_specker/specker_runner_spec.rb +167 -0
  121. data/spec/features/account_lifecycle_spec.rb +85 -0
  122. data/spec/features/login_spec.rb +66 -0
  123. data/spec/features/push_flow_spec.rb +125 -0
  124. data/spec/features/switching_targets_spec.rb +32 -0
  125. data/spec/spec_helper.rb +72 -0
  126. data/spec/support/command_helper.rb +81 -0
  127. data/spec/support/config_helper.rb +15 -0
  128. data/spec/support/console_app_specker_matchers.rb +86 -0
  129. data/spec/support/fake_home_dir.rb +55 -0
  130. data/spec/support/interact_helper.rb +29 -0
  131. data/spec/support/shared_examples/errors.rb +40 -0
  132. data/spec/support/shared_examples/input.rb +14 -0
  133. data/spec/support/specker_runner.rb +80 -0
  134. data/spec/support/tracking_expector.rb +71 -0
  135. metadata +427 -66
  136. data/lib/cf/cli/app.rb +0 -595
  137. data/lib/cf/cli/command.rb +0 -444
  138. data/lib/cf/cli/dots.rb +0 -133
  139. data/lib/cf/cli/service.rb +0 -112
  140. data/lib/cf/cli/user.rb +0 -71
@@ -0,0 +1,35 @@
1
+ require "cf/cli/service/base"
2
+
3
+ module CF::Service
4
+ class Rename < Base
5
+ desc "Rename a service"
6
+ group :services, :manage, :hidden => true
7
+ input :service, :desc => "Service to rename", :argument => :optional,
8
+ :from_given => by_name(:service_instance, :service)
9
+ input :name, :desc => "New service name", :argument => :optional
10
+ def rename_service
11
+ service = input[:service]
12
+ name = input[:name]
13
+
14
+ service.name = name
15
+
16
+ with_progress("Renaming to #{c(name, :name)}") do
17
+ service.update!
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def ask_service
24
+ services = client.service_instances
25
+ fail "No services." if services.empty?
26
+
27
+ ask("Rename which service?", :choices => services.sort_by(&:name),
28
+ :display => proc(&:name))
29
+ end
30
+
31
+ def ask_name
32
+ ask("New name")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ require "cf/cli/service/base"
2
+
3
+ module CF::Service
4
+ class Service < Base
5
+ desc "Show service information"
6
+ group :services
7
+ input :service, :desc => "Service to show", :argument => :required,
8
+ :from_given => by_name(:service_instance, :service)
9
+ def service
10
+ display_service(input[:service])
11
+ end
12
+
13
+ private
14
+
15
+ def display_service(i)
16
+ if quiet?
17
+ line i.name
18
+ else
19
+ plan = i.service_plan
20
+ service = plan.service
21
+
22
+ apps = i.service_bindings.collect { |b|
23
+ c(b.app.name, :name)
24
+ }.join(", ")
25
+
26
+ line "#{c(i.name, :name)}: #{service.label} #{service.version}"
27
+
28
+ indented do
29
+ line "provider: #{c(service.provider, :name)}"
30
+ line "bound to: #{apps}" unless apps.empty?
31
+ line "plan: #{c(plan.name, :name)}"
32
+
33
+ indented do
34
+ line "description: #{plan.description}"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,99 @@
1
+ require "cf/cli/service/base"
2
+
3
+ module CF::Service
4
+ class Services < Base
5
+ desc "List your service"
6
+ group :services
7
+ input :space, :desc => "Show services in given space",
8
+ :from_given => by_name(:space),
9
+ :default => proc { client.current_space }
10
+ input :name, :desc => "Filter by name"
11
+ input :service, :desc => "Filter by service type"
12
+ input :plan, :desc => "Filter by service plan"
13
+ input :provider, :desc => "Filter by service provider"
14
+ input :version, :desc => "Filter by service version"
15
+ input :app, :desc => "Limit to application's service bindings",
16
+ :from_given => by_name(:app)
17
+ input :full, :desc => "Verbose output format", :default => false
18
+ def services
19
+ msg =
20
+ if space = input[:space]
21
+ "Getting services in #{c(space.name, :name)}"
22
+ else
23
+ "Getting services"
24
+ end
25
+
26
+ services =
27
+ with_progress(msg) do
28
+ client.service_instances(:depth => 2)
29
+ end
30
+
31
+ line unless quiet?
32
+
33
+ if services.empty? and !quiet?
34
+ line "No services."
35
+ return
36
+ end
37
+
38
+ services.reject! do |i|
39
+ !service_matches(i, input)
40
+ end
41
+
42
+ if input[:full]
43
+ spaced(services) do |s|
44
+ invoke :service, :service => s
45
+ end
46
+ else
47
+ table(
48
+ ["name", "service", "version", "plan", "bound apps"],
49
+ services.collect { |i|
50
+ plan = i.service_plan
51
+ service = plan.service
52
+
53
+ label = service.label
54
+ version = service.version
55
+ apps = name_list(i.service_bindings.collect(&:app))
56
+
57
+ [ c(i.name, :name),
58
+ label,
59
+ version,
60
+ plan.name,
61
+ apps
62
+ ]
63
+ })
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def service_matches(i, options)
70
+ if app = options[:app]
71
+ return false unless app.services.include? i
72
+ end
73
+
74
+ if name = options[:name]
75
+ return false unless File.fnmatch(name, i.name)
76
+ end
77
+
78
+ plan = i.service_plan
79
+
80
+ if service = options[:service]
81
+ return false unless File.fnmatch(service, plan.service.label)
82
+ end
83
+
84
+ if plan = options[:plan]
85
+ return false unless File.fnmatch(plan.upcase, plan.name.upcase)
86
+ end
87
+
88
+ if provider = options[:provider]
89
+ return false unless File.fnmatch(provider, plan.service.provider)
90
+ end
91
+
92
+ if version = options[:version]
93
+ return false unless File.fnmatch(version, plan.service.version)
94
+ end
95
+
96
+ true
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,38 @@
1
+ require "cf/detect"
2
+
3
+ require "cf/cli/service/base"
4
+
5
+ module CF::Service
6
+ class Unbind < Base
7
+ desc "Unbind a service from an application"
8
+ group :services, :manage
9
+ input :service, :desc => "Service to unbind", :argument => :optional,
10
+ :from_given => by_name(:service_instance, :service)
11
+ input :app, :desc => "Application to unbind from", :argument => :optional,
12
+ :from_given => by_name(:app)
13
+ def unbind_service
14
+ app = input[:app]
15
+ service = input[:service, app]
16
+
17
+ with_progress(
18
+ "Unbinding #{c(service.name, :name)} from #{c(app.name, :name)}") do
19
+ app.unbind(service)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def ask_service(app)
26
+ services = app.services
27
+ fail "No bound services." if services.empty?
28
+
29
+ ask "Which service?", :choices => services,
30
+ :display => proc(&:name)
31
+ end
32
+
33
+ def ask_app
34
+ ask "Which application?", :choices => client.apps,
35
+ :display => proc(&:name)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ require "cf/cli"
2
+
3
+ module CF
4
+ module Space
5
+ class Base < CLI
6
+ def precondition
7
+ check_target
8
+ check_logged_in
9
+ end
10
+
11
+ def self.space_by_name
12
+ proc { |name, org, *_|
13
+ org.space_by_name(name) ||
14
+ fail("Unknown space '#{name}'.")
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,63 @@
1
+ require "cf/cli/space/base"
2
+
3
+ module CF::Space
4
+ class Create < Base
5
+ desc "Create a space in an organization"
6
+ group :spaces
7
+ input :name, :desc => "Space name", :argument => :optional
8
+ input :organization, :desc => "Parent organization",
9
+ :argument => :optional, :aliases => ["--org", "-o"],
10
+ :from_given => by_name(:organization),
11
+ :default => proc { client.current_organization }
12
+ input :target, :desc => "Switch to the space after creation",
13
+ :alias => "-t", :default => false
14
+ input :manager, :desc => "Add yourself as manager", :default => true
15
+ input :developer, :desc => "Add yourself as developer", :default => true
16
+ input :auditor, :desc => "Add yourself as auditor", :default => false
17
+
18
+ def create_space
19
+ # TODO: ask org instead
20
+ return invoke :help,
21
+ :command => "create-space" if input[:organization].nil?
22
+
23
+ space = client.space
24
+ space.organization = input[:organization]
25
+ space.name = input[:name]
26
+
27
+ with_progress("Creating space #{c(space.name, :name)}") do
28
+ space.create!
29
+ end
30
+
31
+ if input[:manager]
32
+ with_progress("Adding you as a manager") do
33
+ space.add_manager client.current_user
34
+ end
35
+ end
36
+
37
+ if input[:developer]
38
+ with_progress("Adding you as a developer") do
39
+ space.add_developer client.current_user
40
+ end
41
+ end
42
+
43
+ if input[:auditor]
44
+ with_progress("Adding you as an auditor") do
45
+ space.add_auditor client.current_user
46
+ end
47
+ end
48
+
49
+ if input[:target]
50
+ invoke :target, :organization => space.organization,
51
+ :space => space
52
+ else
53
+ line c("Space created! Use #{b("switch-space #{space.name}")} to target it.", :good)
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def ask_name
60
+ ask("Name")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,95 @@
1
+ require "cf/cli/space/base"
2
+
3
+ module CF::Space
4
+ class Delete < Base
5
+ desc "Delete a space and its contents"
6
+ group :spaces
7
+ input :organization, :desc => "Space's organization",
8
+ :aliases => ["--org", "-o"], :from_given => by_name(:organization),
9
+ :default => proc { client.current_organization }
10
+ input :spaces, :desc => "Spaces to delete", :argument => :splat,
11
+ :singular => :space, :from_given => space_by_name
12
+ input :recursive, :desc => "Delete recursively", :alias => "-r",
13
+ :default => false, :forget => true
14
+ input :warn, :desc => "Show warning if it was the last space",
15
+ :default => true
16
+ input :really, :type => :boolean, :forget => true, :hidden => true,
17
+ :default => proc { force? || interact }
18
+ def delete_space
19
+ org = input[:organization]
20
+ spaces = input[:spaces, org]
21
+
22
+ deleted_current = false
23
+
24
+ spaces.each do |space|
25
+ next unless input[:really, space]
26
+
27
+ next unless clear_space(space)
28
+
29
+ deleted_current ||= space == client.current_space
30
+
31
+ with_progress("Deleting space #{c(space.name, :name)}") do
32
+ space.delete!
33
+ end
34
+ end
35
+
36
+ org.invalidate!
37
+
38
+ if org.spaces.empty?
39
+ return unless input[:warn]
40
+
41
+ line
42
+ line c("There are no longer any spaces in #{b(org.name)}.", :warning)
43
+ line "You may want to create one with #{c("create-space", :good)}."
44
+ elsif deleted_current
45
+ invalidate_client
46
+ invoke :target, :organization => client.current_organization
47
+ end
48
+ end
49
+
50
+ def clear_space(space)
51
+ apps = space.apps
52
+ services = space.service_instances
53
+
54
+ return true if apps.empty? && services.empty?
55
+
56
+ unless force?
57
+ line "This space is not empty!"
58
+ line
59
+ line "apps: #{name_list(apps)}"
60
+ line "service: #{name_list(services)}"
61
+ line
62
+
63
+ return unless input[:recursive]
64
+ end
65
+
66
+ apps.each do |a|
67
+ invoke :delete, :app => a, :really => true
68
+ end
69
+
70
+ services.each do |i|
71
+ invoke :delete_service, :service => i, :really => true
72
+ end
73
+
74
+ true
75
+ end
76
+
77
+ private
78
+
79
+ def ask_spaces(org)
80
+ spaces = org.spaces
81
+ fail "No spaces." if spaces.empty?
82
+
83
+ [ask("Which space in #{c(org.name, :name)}?", :choices => spaces,
84
+ :display => proc(&:name))]
85
+ end
86
+
87
+ def ask_really(space)
88
+ ask("Really delete #{c(space.name, :name)}?", :default => false)
89
+ end
90
+
91
+ def ask_recursive
92
+ ask "Delete #{c("EVERYTHING", :bad)}?", :default => false
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,39 @@
1
+ require "cf/cli/space/base"
2
+
3
+ module CF::Space
4
+ class Rename < Base
5
+ desc "Rename a space"
6
+ group :spaces, :hidden => true
7
+ input :organization, :desc => "Space's organization",
8
+ :aliases => ["--org", "-o"], :from_given => by_name(:organization),
9
+ :default => proc { client.current_organization }
10
+ input :space, :desc => "Space to rename", :argument => :optional,
11
+ :from_given => by_name(:space)
12
+ input :name, :desc => "New space name", :argument => :optional
13
+ def rename_space
14
+ org = input[:organization]
15
+ space = input[:space, org]
16
+ name = input[:name]
17
+
18
+ space.name = name
19
+
20
+ with_progress("Renaming to #{c(name, :name)}") do
21
+ space.update!
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def ask_space(org)
28
+ spaces = org.spaces
29
+ fail "No spaces." if spaces.empty?
30
+
31
+ ask("Rename which space?", :choices => spaces.sort_by(&:name),
32
+ :display => proc(&:name))
33
+ end
34
+
35
+ def ask_name
36
+ ask("New name")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,64 @@
1
+ require "cf/cli/space/base"
2
+
3
+ module CF::Space
4
+ class Space < Base
5
+ desc "Show space information"
6
+ group :spaces
7
+ input :organization, :desc => "Space's organization",
8
+ :aliases => %w{--org -o},
9
+ :default => proc { client.current_organization },
10
+ :from_given => by_name(:organization)
11
+ input :space, :desc => "Space to show", :argument => :optional,
12
+ :default => proc { client.current_space },
13
+ :from_given => space_by_name
14
+ input :full, :desc => "Show full information for apps, services, etc.",
15
+ :default => false
16
+ def space
17
+ org = input[:organization]
18
+ space = input[:space, org]
19
+
20
+ unless space
21
+ return if quiet?
22
+ fail "No current space."
23
+ end
24
+
25
+ if quiet?
26
+ puts space.name
27
+ return
28
+ end
29
+
30
+ line "#{c(space.name, :name)}:"
31
+
32
+ indented do
33
+ line "organization: #{c(space.organization.name, :name)}"
34
+
35
+ if input[:full]
36
+ line
37
+ line "apps:"
38
+
39
+ spaced(space.apps(:depth => 2)) do |a|
40
+ indented do
41
+ invoke :app, :app => a
42
+ end
43
+ end
44
+ else
45
+ line "apps: #{name_list(space.apps)}"
46
+ end
47
+
48
+ if input[:full]
49
+ line
50
+ line "services:"
51
+ spaced(space.service_instances(:depth => 2)) do |s|
52
+ indented do
53
+ invoke :service, :service => s
54
+ end
55
+ end
56
+ else
57
+ line "services: #{name_list(space.service_instances)}"
58
+ end
59
+
60
+ line "domains: #{name_list(space.domains)}"
61
+ end
62
+ end
63
+ end
64
+ end