af 0.3.22 → 0.5.0.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 (157) hide show
  1. checksums.yaml +14 -6
  2. data/LICENSE +1277 -24
  3. data/Rakefile +24 -87
  4. data/bin/af +7 -2
  5. data/lib/af/version.rb +3 -0
  6. data/lib/vmc.rb +7 -2
  7. data/lib/vmc/cli.rb +475 -0
  8. data/lib/vmc/cli/app/app.rb +45 -0
  9. data/lib/vmc/cli/app/apps.rb +105 -0
  10. data/lib/vmc/cli/app/base.rb +82 -0
  11. data/lib/vmc/cli/app/crashes.rb +46 -0
  12. data/lib/vmc/cli/app/delete.rb +95 -0
  13. data/lib/vmc/cli/app/deprecated.rb +11 -0
  14. data/lib/vmc/cli/app/env.rb +78 -0
  15. data/lib/vmc/cli/app/files.rb +137 -0
  16. data/lib/vmc/cli/app/health.rb +26 -0
  17. data/lib/vmc/cli/app/instances.rb +53 -0
  18. data/lib/vmc/cli/app/logs.rb +76 -0
  19. data/lib/vmc/cli/app/push.rb +107 -0
  20. data/lib/vmc/cli/app/push/create.rb +150 -0
  21. data/lib/vmc/cli/app/push/interactions.rb +100 -0
  22. data/lib/vmc/cli/app/push/sync.rb +64 -0
  23. data/lib/vmc/cli/app/rename.rb +39 -0
  24. data/lib/vmc/cli/app/restart.rb +20 -0
  25. data/lib/vmc/cli/app/scale.rb +71 -0
  26. data/lib/vmc/cli/app/start.rb +93 -0
  27. data/lib/vmc/cli/app/stats.rb +67 -0
  28. data/lib/vmc/cli/app/stop.rb +27 -0
  29. data/lib/vmc/cli/domain/base.rb +12 -0
  30. data/lib/vmc/cli/domain/domains.rb +40 -0
  31. data/lib/vmc/cli/domain/map.rb +55 -0
  32. data/lib/vmc/cli/domain/unmap.rb +56 -0
  33. data/lib/vmc/cli/help.rb +16 -0
  34. data/lib/vmc/cli/interactive.rb +105 -0
  35. data/lib/vmc/cli/organization/base.rb +14 -0
  36. data/lib/vmc/cli/organization/create.rb +32 -0
  37. data/lib/vmc/cli/organization/delete.rb +73 -0
  38. data/lib/vmc/cli/organization/org.rb +45 -0
  39. data/lib/vmc/cli/organization/orgs.rb +35 -0
  40. data/lib/vmc/cli/organization/rename.rb +36 -0
  41. data/lib/vmc/cli/route/base.rb +12 -0
  42. data/lib/vmc/cli/route/map.rb +80 -0
  43. data/lib/vmc/cli/route/routes.rb +26 -0
  44. data/lib/vmc/cli/route/unmap.rb +94 -0
  45. data/lib/vmc/cli/service/base.rb +8 -0
  46. data/lib/vmc/cli/service/bind.rb +44 -0
  47. data/lib/vmc/cli/service/create.rb +126 -0
  48. data/lib/vmc/cli/service/delete.rb +86 -0
  49. data/lib/vmc/cli/service/rename.rb +35 -0
  50. data/lib/vmc/cli/service/service.rb +42 -0
  51. data/lib/vmc/cli/service/services.rb +115 -0
  52. data/lib/vmc/cli/service/unbind.rb +38 -0
  53. data/lib/vmc/cli/space/base.rb +21 -0
  54. data/lib/vmc/cli/space/create.rb +56 -0
  55. data/lib/vmc/cli/space/delete.rb +95 -0
  56. data/lib/vmc/cli/space/rename.rb +39 -0
  57. data/lib/vmc/cli/space/space.rb +64 -0
  58. data/lib/vmc/cli/space/spaces.rb +55 -0
  59. data/lib/vmc/cli/space/take.rb +16 -0
  60. data/lib/vmc/cli/start/base.rb +80 -0
  61. data/lib/vmc/cli/start/colors.rb +13 -0
  62. data/lib/vmc/cli/start/info.rb +122 -0
  63. data/lib/vmc/cli/start/login.rb +92 -0
  64. data/lib/vmc/cli/start/logout.rb +13 -0
  65. data/lib/vmc/cli/start/target.rb +64 -0
  66. data/lib/vmc/cli/start/target_interactions.rb +37 -0
  67. data/lib/vmc/cli/start/targets.rb +16 -0
  68. data/lib/vmc/cli/user/base.rb +29 -0
  69. data/lib/vmc/cli/user/create.rb +39 -0
  70. data/lib/vmc/cli/user/delete.rb +25 -0
  71. data/lib/vmc/cli/user/passwd.rb +50 -0
  72. data/lib/vmc/cli/user/register.rb +42 -0
  73. data/lib/vmc/cli/user/users.rb +32 -0
  74. data/lib/vmc/constants.rb +13 -0
  75. data/lib/vmc/detect.rb +134 -0
  76. data/lib/vmc/errors.rb +17 -0
  77. data/lib/vmc/plugin.rb +56 -0
  78. data/lib/vmc/spacing.rb +89 -0
  79. data/lib/vmc/spec_helper.rb +1 -0
  80. data/lib/vmc/test_support.rb +4 -0
  81. data/lib/vmc/test_support/command_helper.rb +32 -0
  82. data/lib/vmc/test_support/common_input_examples.rb +14 -0
  83. data/lib/vmc/test_support/fake_home_dir.rb +16 -0
  84. data/lib/vmc/test_support/interact_helper.rb +29 -0
  85. data/lib/vmc/version.rb +3 -0
  86. data/spec/assets/hello-sinatra/Gemfile +3 -0
  87. data/spec/assets/hello-sinatra/main.rb +6 -0
  88. data/spec/features/new_user_flow_spec.rb +71 -0
  89. data/spec/spec_helper.rb +63 -0
  90. data/spec/vmc/cli/app/base_spec.rb +17 -0
  91. data/spec/vmc/cli/app/delete_spec.rb +188 -0
  92. data/spec/vmc/cli/app/instances_spec.rb +65 -0
  93. data/spec/vmc/cli/app/push/create_spec.rb +571 -0
  94. data/spec/vmc/cli/app/push_spec.rb +369 -0
  95. data/spec/vmc/cli/app/rename_spec.rb +104 -0
  96. data/spec/vmc/cli/app/scale_spec.rb +81 -0
  97. data/spec/vmc/cli/app/stats_spec.rb +62 -0
  98. data/spec/vmc/cli/domain/map_spec.rb +140 -0
  99. data/spec/vmc/cli/domain/unmap_spec.rb +73 -0
  100. data/spec/vmc/cli/organization/orgs_spec.rb +108 -0
  101. data/spec/vmc/cli/organization/rename_spec.rb +113 -0
  102. data/spec/vmc/cli/route/map_spec.rb +138 -0
  103. data/spec/vmc/cli/route/unmap_spec.rb +215 -0
  104. data/spec/vmc/cli/service/bind_spec.rb +25 -0
  105. data/spec/vmc/cli/service/delete_spec.rb +22 -0
  106. data/spec/vmc/cli/service/rename_spec.rb +105 -0
  107. data/spec/vmc/cli/service/service_spec.rb +23 -0
  108. data/spec/vmc/cli/service/unbind_spec.rb +25 -0
  109. data/spec/vmc/cli/space/rename_spec.rb +102 -0
  110. data/spec/vmc/cli/space/spaces_spec.rb +104 -0
  111. data/spec/vmc/cli/start/info_spec.rb +153 -0
  112. data/spec/vmc/cli/start/login_spec.rb +71 -0
  113. data/spec/vmc/cli/user/create_spec.rb +54 -0
  114. data/spec/vmc/cli/user/passwd_spec.rb +102 -0
  115. data/spec/vmc/cli/user/register_spec.rb +148 -0
  116. data/spec/vmc/cli_spec.rb +448 -0
  117. data/spec/vmc/detect_spec.rb +54 -0
  118. metadata +231 -124
  119. data/README.md +0 -155
  120. data/caldecott_helper/Gemfile +0 -10
  121. data/caldecott_helper/Gemfile.lock +0 -48
  122. data/caldecott_helper/server.rb +0 -43
  123. data/config/clients.yml +0 -17
  124. data/config/micro/offline.conf +0 -2
  125. data/config/micro/paths.yml +0 -22
  126. data/config/micro/refresh_ip.rb +0 -20
  127. data/lib/cli.rb +0 -48
  128. data/lib/cli/commands/admin.rb +0 -81
  129. data/lib/cli/commands/apps.rb +0 -1358
  130. data/lib/cli/commands/base.rb +0 -233
  131. data/lib/cli/commands/manifest.rb +0 -56
  132. data/lib/cli/commands/micro.rb +0 -115
  133. data/lib/cli/commands/misc.rb +0 -147
  134. data/lib/cli/commands/services.rb +0 -217
  135. data/lib/cli/commands/user.rb +0 -70
  136. data/lib/cli/config.rb +0 -176
  137. data/lib/cli/console_helper.rb +0 -163
  138. data/lib/cli/core_ext.rb +0 -122
  139. data/lib/cli/errors.rb +0 -19
  140. data/lib/cli/file_helper.rb +0 -123
  141. data/lib/cli/frameworks.rb +0 -265
  142. data/lib/cli/manifest_helper.rb +0 -316
  143. data/lib/cli/runner.rb +0 -633
  144. data/lib/cli/services_helper.rb +0 -104
  145. data/lib/cli/tunnel_helper.rb +0 -336
  146. data/lib/cli/usage.rb +0 -129
  147. data/lib/cli/version.rb +0 -7
  148. data/lib/cli/zip_util.rb +0 -102
  149. data/lib/vmc/client.rb +0 -574
  150. data/lib/vmc/const.rb +0 -27
  151. data/lib/vmc/micro.rb +0 -56
  152. data/lib/vmc/micro/switcher/base.rb +0 -97
  153. data/lib/vmc/micro/switcher/darwin.rb +0 -19
  154. data/lib/vmc/micro/switcher/dummy.rb +0 -15
  155. data/lib/vmc/micro/switcher/linux.rb +0 -16
  156. data/lib/vmc/micro/switcher/windows.rb +0 -31
  157. data/lib/vmc/micro/vmrun.rb +0 -158
@@ -0,0 +1,39 @@
1
+ require "vmc/cli/space/base"
2
+
3
+ module VMC::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 "vmc/cli/space/base"
2
+
3
+ module VMC::Space
4
+ class Space < Base
5
+ desc "Show space information"
6
+ group :spaces, :hidden => true
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
@@ -0,0 +1,55 @@
1
+ require "vmc/cli/space/base"
2
+
3
+ module VMC::Space
4
+ class Spaces < Base
5
+ desc "List spaces in an organization"
6
+ group :spaces, :hidden => true
7
+ input :organization, :desc => "Organization to list spaces from",
8
+ :aliases => %w{--org -o}, :argument => :optional,
9
+ :from_given => by_name(:organization),
10
+ :default => proc { client.current_organization }
11
+ input :name, :desc => "Filter by name"
12
+ input :full, :desc => "Show full information for apps, services, etc.",
13
+ :default => false
14
+ def spaces
15
+ org = input[:organization]
16
+ spaces =
17
+ with_progress("Getting spaces in #{c(org.name, :name)}") do
18
+ org.spaces(:depth => quiet? ? 0 : 1).sort_by(&:name)
19
+ end
20
+
21
+ return if spaces.empty?
22
+
23
+ line unless quiet?
24
+
25
+ spaces.reject! do |s|
26
+ !space_matches?(s, input)
27
+ end
28
+
29
+ if input[:full]
30
+ spaced(spaces) do |s|
31
+ invoke :space, :space => s, :full => input[:full]
32
+ end
33
+ else
34
+ table(
35
+ %w{name apps services},
36
+ spaces.collect { |s|
37
+ [ c(s.name, :name),
38
+ name_list(s.apps),
39
+ name_list(s.service_instances)
40
+ ]
41
+ })
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def space_matches?(s, options)
48
+ if name = options[:name]
49
+ return false if s.name !~ /#{name}/
50
+ end
51
+
52
+ true
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,16 @@
1
+ require "vmc/cli/space/base"
2
+
3
+ module VMC::Space
4
+ class Take < Base
5
+ desc "Switch to a space, creating it if it doesn't exist"
6
+ group :spaces, :hidden => true
7
+ input :name, :desc => "Space name", :argument => true
8
+ def take_space
9
+ if space = client.space_by_name(input[:name])
10
+ invoke :target, :space => space
11
+ else
12
+ invoke :create_space, :name => input[:name], :target => true
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,80 @@
1
+ require "vmc/cli"
2
+
3
+ module VMC
4
+ module Start
5
+ class Base < CLI
6
+ # Make sure we only show the target once
7
+ @@displayed_target = false
8
+
9
+ def displayed_target?
10
+ @@displayed_target
11
+ end
12
+
13
+
14
+ # These commands don't require authentication.
15
+ def precondition; end
16
+
17
+ private
18
+
19
+ def show_context
20
+ return if quiet? || displayed_target?
21
+
22
+ display_target
23
+
24
+ line
25
+
26
+ @@displayed_target = true
27
+ end
28
+
29
+ def display_target
30
+ if quiet?
31
+ line client.target
32
+ else
33
+ line "target: #{c(client.target, :name)}"
34
+ end
35
+ end
36
+
37
+ def select_org_and_space(input, info)
38
+ changed_org = false
39
+
40
+ if input.has?(:organization) || !org_valid?(info[:organization])
41
+ org = input[:organization]
42
+ return unless org
43
+
44
+ with_progress("Switching to organization #{c(org.name, :name)}") do
45
+ info[:organization] = org.guid
46
+ changed_org = true
47
+ end
48
+ else
49
+ org = client.current_organization
50
+ end
51
+
52
+ # switching org means switching space
53
+ if changed_org || input.has?(:space) || !space_valid?(info[:space])
54
+ line if changed_org && !quiet?
55
+
56
+ space = input[:space, org]
57
+ return unless space
58
+
59
+ with_progress("Switching to space #{c(space.name, :name)}") do
60
+ info[:space] = space.guid
61
+ end
62
+ end
63
+ end
64
+
65
+ def org_valid?(guid, user = client.current_user)
66
+ return false unless guid
67
+ client.organization(guid).users.include? user
68
+ rescue CFoundry::APIError
69
+ false
70
+ end
71
+
72
+ def space_valid?(guid, user = client.current_user)
73
+ return false unless guid
74
+ client.space(guid).developers.include? user
75
+ rescue CFoundry::APIError
76
+ false
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,13 @@
1
+ require "vmc/cli/start/base"
2
+
3
+ module VMC::Start
4
+ class Colors < Base
5
+ desc "Show color configuration"
6
+ group :start, :hidden => true
7
+ def colors
8
+ user_colors.each do |n, c|
9
+ line "#{n}: #{c(c.to_s, n)}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,122 @@
1
+ require "vmc/cli/start/base"
2
+
3
+ module VMC::Start
4
+ class Info < Base
5
+ desc "Display information on the current target, user, etc."
6
+ group :start
7
+ input :runtimes, :desc => "List supported runtimes", :alias => "-r",
8
+ :default => false
9
+ input :frameworks, :desc => "List supported frameworks", :alias => "-f",
10
+ :default => false
11
+ input :services, :desc => "List supported services", :alias => "-s",
12
+ :default => false
13
+ input :all, :desc => "Show all information", :alias => "-a",
14
+ :default => false
15
+ def info
16
+ all = input[:all]
17
+
18
+ if all || input[:runtimes]
19
+ runtimes =
20
+ with_progress("Getting runtimes") do
21
+ client.runtimes
22
+ end
23
+ end
24
+
25
+ if all || input[:frameworks]
26
+ frameworks =
27
+ with_progress("Getting frameworks") do
28
+ client.frameworks
29
+ end
30
+ end
31
+
32
+ if all || input[:services]
33
+ services =
34
+ with_progress("Getting services") do
35
+ client.services
36
+ end
37
+ end
38
+
39
+ showing_any = runtimes || services || frameworks
40
+
41
+ unless !all && showing_any
42
+ info = client.info
43
+
44
+ line if showing_any
45
+ line info[:description]
46
+ line
47
+ line "target: #{b(client.target)}"
48
+
49
+ indented do
50
+ line "version: #{info[:version]}"
51
+ line "support: #{info[:support]}"
52
+ end
53
+
54
+ if user = client.current_user
55
+ line
56
+ line "user: #{b(user.email || user.guid)}"
57
+ end
58
+ end
59
+
60
+ if runtimes
61
+ line unless quiet?
62
+
63
+ if runtimes.empty? && !quiet?
64
+ line "#{d("none")}"
65
+ elsif input[:quiet]
66
+ runtimes.each do |r|
67
+ line r.name
68
+ end
69
+ else
70
+ table(
71
+ %w{runtime description},
72
+ runtimes.sort_by(&:name).collect { |r|
73
+ [c(r.name, :name), r.description]
74
+ })
75
+ end
76
+ end
77
+
78
+ if frameworks
79
+ line unless quiet?
80
+
81
+ if frameworks.empty? && !quiet?
82
+ line "#{d("none")}"
83
+ elsif input[:quiet]
84
+ frameworks.each do |f|
85
+ line f.name
86
+ end
87
+ else
88
+ table(
89
+ %w{framework description},
90
+ frameworks.sort_by(&:name).collect { |f|
91
+ [c(f.name, :name), f.description]
92
+ })
93
+ end
94
+ end
95
+
96
+ if services
97
+ line unless quiet?
98
+
99
+ if services.empty? && !quiet?
100
+ line "#{d("none")}"
101
+ elsif input[:quiet]
102
+ services.each do |s|
103
+ line s.label
104
+ end
105
+ else
106
+ table(
107
+ ["service", "version", "provider", v2? && "plans", "description"],
108
+ services.sort_by(&:label).collect { |s|
109
+ next if !v2? && s.deprecated?
110
+
111
+ [c(s.label, :name),
112
+ s.version,
113
+ s.provider,
114
+ v2? && s.service_plans.collect(&:name).join(", "),
115
+ s.description
116
+ ]
117
+ })
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,92 @@
1
+ require "vmc/cli/start/base"
2
+ require "vmc/cli/start/target_interactions"
3
+
4
+ module VMC::Start
5
+ class Login < Base
6
+ desc "Authenticate with the target"
7
+ group :start
8
+ input :username, :value => :email, :desc => "Account email",
9
+ :alias => "--email", :argument => :optional
10
+ input :password, :desc => "Account password"
11
+ input :organization, :desc => "Organization" , :aliases => %w{--org -o},
12
+ :from_given => by_name(:organization)
13
+ input :space, :desc => "Space", :alias => "-s",
14
+ :from_given => by_name(:space)
15
+ interactions TargetInteractions
16
+ def login
17
+ show_context
18
+
19
+ credentials =
20
+ { :username => input[:username],
21
+ :password => input[:password]
22
+ }
23
+
24
+ prompts = client.login_prompts
25
+
26
+ # ask username first
27
+ if prompts.key? :username
28
+ type, label = prompts.delete :username
29
+ credentials[:username] ||= ask_prompt(type, label)
30
+ end
31
+
32
+ info = target_info
33
+
34
+ auth_token = nil
35
+ authenticated = false
36
+ failed = false
37
+ remaining_attempts = 3
38
+ until authenticated || remaining_attempts <= 0
39
+ remaining_attempts -= 1
40
+ unless force?
41
+ ask_prompts(credentials, prompts)
42
+ end
43
+
44
+ with_progress("Authenticating") do |s|
45
+ begin
46
+ auth_token = client.login(credentials[:username], credentials[:password])
47
+ authenticated = true
48
+ rescue CFoundry::Denied
49
+ return if force?
50
+
51
+ s.fail do
52
+ failed = true
53
+ credentials.delete(:password)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ info.merge!(auth_token.to_hash)
60
+ save_target_info(info)
61
+ invalidate_client
62
+
63
+ if v2?
64
+ line if input.interactive?(:organization) || input.interactive?(:space)
65
+ select_org_and_space(input, info)
66
+ end
67
+
68
+ save_target_info(info)
69
+ ensure
70
+ exit_status 1 if not authenticated
71
+ end
72
+
73
+ private
74
+
75
+ def ask_prompts(credentials, prompts)
76
+ prompts.each do |name, meta|
77
+ type, label = meta
78
+ credentials[name] ||= ask_prompt(type, label)
79
+ end
80
+ end
81
+
82
+ def ask_prompt(type, label)
83
+ if type == "password"
84
+ options = { :echo => "*", :forget => true }
85
+ else
86
+ options = {}
87
+ end
88
+
89
+ ask(label, options)
90
+ end
91
+ end
92
+ end