rhc 1.6.8 → 1.7.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/autocomplete/rhc_bash +1167 -0
  2. data/features/README.md +1 -1
  3. data/features/domain.feature +1 -1
  4. data/features/lib/rhc_helper/persistable.rb +4 -1
  5. data/features/multiple_cartridge.feature +4 -3
  6. data/features/sshkey.feature +3 -3
  7. data/features/support/assumptions.rb +3 -3
  8. data/features/support/env.rb +10 -0
  9. data/features/support/platform_support.rb +2 -2
  10. data/lib/rhc.rb +6 -0
  11. data/lib/rhc/auth/token.rb +4 -0
  12. data/lib/rhc/autocomplete.rb +50 -52
  13. data/lib/rhc/autocomplete_templates/{rhc.erb → bash.erb} +8 -2
  14. data/lib/rhc/cartridge_helpers.rb +1 -1
  15. data/lib/rhc/cli.rb +1 -7
  16. data/lib/rhc/command_runner.rb +45 -16
  17. data/lib/rhc/commands.rb +75 -55
  18. data/lib/rhc/commands/account.rb +7 -51
  19. data/lib/rhc/commands/alias.rb +26 -17
  20. data/lib/rhc/commands/app.rb +75 -39
  21. data/lib/rhc/commands/authorization.rb +4 -2
  22. data/lib/rhc/commands/base.rb +31 -29
  23. data/lib/rhc/commands/cartridge.rb +66 -44
  24. data/lib/rhc/commands/domain.rb +20 -8
  25. data/lib/rhc/commands/git_clone.rb +3 -3
  26. data/lib/rhc/commands/logout.rb +51 -0
  27. data/lib/rhc/commands/port_forward.rb +15 -11
  28. data/lib/rhc/commands/setup.rb +25 -0
  29. data/lib/rhc/commands/snapshot.rb +20 -10
  30. data/lib/rhc/commands/sshkey.rb +21 -7
  31. data/lib/rhc/commands/tail.rb +2 -2
  32. data/lib/rhc/commands/threaddump.rb +2 -2
  33. data/lib/rhc/context_helper.rb +0 -4
  34. data/lib/rhc/core_ext.rb +96 -76
  35. data/lib/rhc/exceptions.rb +6 -0
  36. data/lib/rhc/help_formatter.rb +19 -2
  37. data/lib/rhc/helpers.rb +32 -194
  38. data/lib/rhc/highline_extensions.rb +412 -0
  39. data/lib/rhc/output_helpers.rb +31 -67
  40. data/lib/rhc/rest.rb +4 -2
  41. data/lib/rhc/rest/alias.rb +0 -2
  42. data/lib/rhc/rest/application.rb +9 -4
  43. data/lib/rhc/rest/authorization.rb +0 -2
  44. data/lib/rhc/rest/base.rb +1 -1
  45. data/lib/rhc/rest/client.rb +11 -9
  46. data/lib/rhc/rest/domain.rb +5 -1
  47. data/lib/rhc/rest/gear_group.rb +0 -2
  48. data/lib/rhc/rest/key.rb +0 -2
  49. data/lib/rhc/rest/mock.rb +32 -10
  50. data/lib/rhc/ssh_helpers.rb +2 -2
  51. data/lib/rhc/usage_templates/command_help.erb +20 -13
  52. data/lib/rhc/usage_templates/command_syntax_help.erb +1 -3
  53. data/lib/rhc/usage_templates/help.erb +15 -16
  54. data/lib/rhc/usage_templates/options_help.erb +7 -9
  55. data/lib/rhc/wizard.rb +193 -159
  56. data/spec/rest_spec_helper.rb +2 -2
  57. data/spec/rhc/cli_spec.rb +36 -5
  58. data/spec/rhc/command_spec.rb +94 -42
  59. data/spec/rhc/commands/account_spec.rb +1 -75
  60. data/spec/rhc/commands/alias_spec.rb +28 -28
  61. data/spec/rhc/commands/app_spec.rb +141 -33
  62. data/spec/rhc/commands/apps_spec.rb +4 -4
  63. data/spec/rhc/commands/authorization_spec.rb +8 -8
  64. data/spec/rhc/commands/cartridge_spec.rb +18 -9
  65. data/spec/rhc/commands/domain_spec.rb +16 -16
  66. data/spec/rhc/commands/git_clone_spec.rb +3 -3
  67. data/spec/rhc/commands/logout_spec.rb +86 -0
  68. data/spec/rhc/commands/port_forward_spec.rb +9 -9
  69. data/spec/rhc/commands/server_spec.rb +5 -5
  70. data/spec/rhc/commands/setup_spec.rb +19 -5
  71. data/spec/rhc/commands/snapshot_spec.rb +12 -12
  72. data/spec/rhc/commands/sshkey_spec.rb +11 -11
  73. data/spec/rhc/commands/tail_spec.rb +5 -5
  74. data/spec/rhc/commands/threaddump_spec.rb +3 -3
  75. data/spec/rhc/config_spec.rb +6 -6
  76. data/spec/rhc/helpers_spec.rb +72 -219
  77. data/spec/rhc/highline_extensions_spec.rb +269 -0
  78. data/spec/rhc/rest_application_spec.rb +28 -1
  79. data/spec/rhc/rest_client_spec.rb +20 -21
  80. data/spec/rhc/rest_spec.rb +10 -0
  81. data/spec/rhc/wizard_spec.rb +72 -32
  82. data/spec/spec_helper.rb +86 -56
  83. data/spec/wizard_spec_helper.rb +7 -4
  84. metadata +165 -160
  85. data/spec/spec.opts +0 -1
@@ -12,59 +12,15 @@ module RHC::Commands
12
12
  def run
13
13
  user = rest_client.user
14
14
 
15
- say_table nil, get_properties(user, :login, :plan_id, :consumed_gears, :max_gears) + get_properties(user.capabilities, :gear_sizes).unshift(['Server:', openshift_server]) << ['SSL Certificates Supported:', user.capabilities.private_ssl_certificates ? 'yes' : 'no'], :delete => true
16
-
17
- if openshift_online_server?
18
- else
19
- end
20
-
21
- 0
22
- end
23
-
24
- summary "End the current session"
25
- description <<-DESC
26
- Logout ends your current session on the server and then removes
27
- all of the local session files. If you are using multiple
28
- servers and configurations this will remove all of your local
29
- session files.
30
-
31
- The --all option will terminate all authorizations on your
32
- account. Any previously generated authorizations will be
33
- deleted and external tools that integrate with your account
34
- will no longer be able to log in.
35
- DESC
36
- option '--all', "Remove all authorizations on your account."
37
- alias_action 'logout', :root_command => true
38
- def logout
39
- if options.all
40
- rest_client.user # force authentication
41
- say "Deleting all authorizations associated with your account ... "
42
- begin
43
- rest_client.delete_authorizations
44
- success "done"
45
- rescue RHC::Rest::AuthorizationsNotSupported
46
- info "not supported"
47
- end
48
- elsif options.token
49
- options.noprompt = true
50
- say "Ending session on server ... "
51
- begin
52
- rest_client.delete_authorization(options.token)
53
- success "deleted"
54
- rescue RHC::Rest::AuthorizationsNotSupported
55
- info "not supported"
56
- rescue RHC::Rest::TokenExpiredOrInvalid
57
- info "already closed"
58
- rescue => e
59
- debug_error(e)
60
- warn e.message
61
- end
62
- end
15
+ say format_table \
16
+ nil,
17
+ get_properties(user, :login, :plan_id, :consumed_gears, :max_gears).
18
+ concat(get_properties(user.capabilities, :gear_sizes)).
19
+ unshift(['Server:', openshift_server]).
20
+ push(['SSL Certificates Supported:', user.capabilities.private_ssl_certificates ? 'yes' : 'no']),
21
+ :delete => true
63
22
 
64
23
  0
65
- ensure
66
- token_store.clear
67
- success "All local sessions removed."
68
24
  end
69
25
  end
70
26
  end
@@ -3,33 +3,42 @@ require 'rhc/config'
3
3
 
4
4
  module RHC::Commands
5
5
  class Alias < Base
6
- summary "Add or remove a custom domain name (alias) for the application"
7
- syntax "<command> <application> <alias> [--namespace namespace]"
6
+ summary "Add or remove a custom domain name for an app"
7
+ syntax "<action>"
8
+ description <<-DESC
9
+ Each application may have one or more custom domain names (known as
10
+ aliases) mapped to it. You may then configure your custom DNS entry
11
+ CNAME to point to your OpenShift application to serve web requests
12
+ from that name.
13
+
14
+ Each alias may have a single SSL certificate associated with the name
15
+ to handle SSL traffic. See the 'add' command for more info.
16
+ DESC
8
17
  default_action :help
9
18
 
10
19
  summary "Add a custom domain name for the application"
11
- syntax "<application> <alias> [--namespace namespace]"
20
+ syntax "<application> <alias> [--namespace NAME]"
12
21
  argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
13
22
  argument :app_alias, "Custom domain name for the application", []
14
- option ["-n", "--namespace namespace"], "Namespace of your application", :context => :namespace_context, :required => true
23
+ option ["-n", "--namespace NAME"], "Namespace of your application", :context => :namespace_context, :required => true
15
24
  alias_action :"app add-alias", :root_command => true, :deprecated => true
16
25
  def add(app, app_alias)
17
26
  rest_app = rest_client.find_application(options.namespace, app)
18
27
  rest_app.add_alias(app_alias)
19
- results { say "Alias '#{app_alias}' has been added." }
28
+ success "Alias '#{app_alias}' has been added."
20
29
  0
21
30
  end
22
31
 
23
32
  summary "Remove a custom domain name for the application"
24
- syntax "<application> <alias> [--namespace namespace]"
33
+ syntax "<application> <alias> [--namespace NAME]"
25
34
  argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
26
35
  argument :app_alias, "Custom domain name for the application", []
27
- option ["-n", "--namespace namespace"], "Namespace of your application", :context => :namespace_context, :required => true
36
+ option ["-n", "--namespace NAME"], "Namespace of your application", :context => :namespace_context, :required => true
28
37
  alias_action :"app remove-alias", :root_command => true, :deprecated => true
29
38
  def remove(app, app_alias)
30
39
  rest_app = rest_client.find_application(options.namespace, app)
31
40
  rest_app.remove_alias(app_alias)
32
- results { say "Alias '#{app_alias}' has been removed." }
41
+ success "Alias '#{app_alias}' has been removed."
33
42
  0
34
43
  end
35
44
 
@@ -46,13 +55,13 @@ module RHC::Commands
46
55
  Pass phrase for the certificate private key is required if the
47
56
  provided private key is encrypted.
48
57
  DESC
49
- syntax "<application> <alias> --certificate FILE --private-key FILE [--passphrase passphrase]"
58
+ syntax "<application> <alias> --certificate FILE --private-key FILE [--passphrase PASSPHRASE]"
50
59
  argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
51
60
  argument :app_alias, "Custom domain name for the application (required)", []
52
61
  option ["--certificate FILE"], "SSL certificate filepath (file in .crt or .pem format)", :required => true
53
62
  option ["--private-key FILE"], "Private key filepath for the given SSL certificate", :required => true
54
- option ["--passphrase passphrase"], "Private key pass phrase, required if the private key is encripted", :required => false
55
- option ["-n", "--namespace namespace"], "Namespace of your application", :context => :namespace_context, :required => true
63
+ option ["--passphrase PASSPHRASE"], "Private key pass phrase, required if the private key is encrypted", :required => false
64
+ option ["-n", "--namespace NAME"], "Namespace of your application", :context => :namespace_context, :required => true
56
65
  def update_cert(app, app_alias)
57
66
  certificate_file_path = options.certificate
58
67
  raise ArgumentError, "Certificate file not found: #{certificate_file_path}" if !File.exist?(certificate_file_path) || !File.file?(certificate_file_path)
@@ -70,7 +79,7 @@ module RHC::Commands
70
79
  rest_alias = rest_app.find_alias(app_alias)
71
80
  if rest_client.api_version_negotiated >= 1.4
72
81
  rest_alias.add_certificate(certificate_content, private_key_content, options.passphrase)
73
- results { say "SSL certificate successfully added." }
82
+ success "SSL certificate successfully added."
74
83
  0
75
84
  else
76
85
  raise RHC::Rest::SslCertificatesNotSupported, "The server does not support SSL certificates for custom aliases."
@@ -82,14 +91,14 @@ module RHC::Commands
82
91
  argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
83
92
  argument :app_alias, "Custom domain name for the application (required)", []
84
93
  option ["--confirm"], "Pass to confirm deleting the application"
85
- option ["-n", "--namespace namespace"], "Namespace of your application", :context => :namespace_context, :required => true
94
+ option ["-n", "--namespace NAME"], "Namespace of your application", :context => :namespace_context, :required => true
86
95
  def delete_cert(app, app_alias)
87
96
  rest_app = rest_client.find_application(options.namespace, app)
88
97
  rest_alias = rest_app.find_alias(app_alias)
89
98
  if rest_client.api_version_negotiated >= 1.4
90
99
  confirm_action "#{color("This is a non-reversible action! Your SSL certificate will be permanently deleted from application '#{app}'.", :yellow)}\n\nAre you sure you want to delete the SSL certificate?"
91
100
  rest_alias.delete_certificate
92
- results { say "SSL certificate successfully deleted." }
101
+ success "SSL certificate successfully deleted."
93
102
  0
94
103
  else
95
104
  raise RHC::Rest::SslCertificatesNotSupported, "The server does not support SSL certificates for custom aliases."
@@ -99,7 +108,7 @@ module RHC::Commands
99
108
  summary "List the aliases on an application"
100
109
  syntax "<application>"
101
110
  argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
102
- option ["-n", "--namespace namespace"], "Namespace of your application", :context => :namespace_context, :required => true
111
+ option ["-n", "--namespace NAME"], "Namespace of your application", :context => :namespace_context, :required => true
103
112
  def list(app)
104
113
  rest_app = rest_client.find_application(options.namespace, app)
105
114
  items = rest_app.aliases.map do |a|
@@ -108,9 +117,9 @@ module RHC::Commands
108
117
  [a.id, a.has_private_ssl_certificate? ? 'yes' : 'no', a.has_private_ssl_certificate? ? Date.parse(a.certificate_added_at) : '-']
109
118
  end
110
119
  if items.empty?
111
- results { say "No aliases associated with the application #{app}." }
120
+ info "No aliases associated with the application #{app}."
112
121
  else
113
- table(items, :header => ["Alias", "Has Certificate?", "Certificate Added"]).each { |s| say s }
122
+ say table(items, :header => ["Alias", "Has Certificate?", "Certificate Added"])
114
123
  end
115
124
  0
116
125
  end
@@ -9,6 +9,7 @@ module RHC::Commands
9
9
  description "Creates and controls an OpenShift application. To see the list of all applications use the rhc domain show command. Note that delete is not reversible and will stop your application and then remove the application and repo from the remote server. No local changes are made."
10
10
  syntax "<action>"
11
11
  default_action :help
12
+ suppress_wizard
12
13
 
13
14
  summary "Create an application"
14
15
  description <<-DESC
@@ -38,19 +39,24 @@ module RHC::Commands
38
39
 
39
40
  DESC
40
41
  syntax "<name> <cartridge> [-n namespace]"
41
- option ["-n", "--namespace namespace"], "Namespace for the application", :context => :namespace_context
42
- option ["-g", "--gear-size size"], "Gear size controls how much memory and CPU your cartridges can use."
42
+ option ["-n", "--namespace NAME"], "Namespace for the application"
43
+ option ["-g", "--gear-size SIZE"], "Gear size controls how much memory and CPU your cartridges can use."
43
44
  option ["-s", "--scaling"], "Enable scaling for the web cartridge."
44
- option ["-r", "--repo dir"], "Path to the Git repository (defaults to ./$app_name)"
45
+ option ["-r", "--repo DIR"], "Path to the Git repository (defaults to ./$app_name)"
45
46
  option ["--from-code URL"], "URL to a Git repository that will become the initial contents of the application"
46
47
  option ["--[no-]git"], "Skip creating the local Git repository."
47
48
  option ["--nogit"], "DEPRECATED: Skip creating the local Git repository.", :deprecated => {:key => :git, :value => false}
48
49
  option ["--[no-]dns"], "Skip waiting for the application DNS name to resolve. Must be used in combination with --no-git"
49
- option ["--enable-jenkins [server_name]"], "Enable Jenkins builds for this application (will create a Jenkins application if not already available). The default name will be 'jenkins' if not specified."
50
- argument :name, "Name for your application", ["-a", "--app name"]
51
- argument :cartridges, "The web framework this application should use", ["-t", "--type cartridge"], :arg_type => :list
50
+ option ['--no-keys'], "Skip checking SSH keys during app creation", :hide => true
51
+ option ["--enable-jenkins [NAME]"], "Enable Jenkins builds for this application (will create a Jenkins application if not already available). The default name will be 'jenkins' if not specified."
52
+ argument :name, "Name for your application", ["-a", "--app NAME"], :optional => true
53
+ argument :cartridges, "The web framework this application should use", ["-t", "--type CARTRIDGE"], :optional => true, :arg_type => :list
52
54
  #argument :additional_cartridges, "A list of other cartridges such as databases you wish to add. Cartridges can also be added later using 'rhc cartridge add'", [], :arg_type => :list
53
55
  def create(name, cartridges)
56
+ check_config!
57
+
58
+ check_name!(name)
59
+
54
60
  cartridges = check_cartridges(cartridges, &require_one_web_cart)
55
61
 
56
62
  options.default \
@@ -59,8 +65,7 @@ module RHC::Commands
59
65
 
60
66
  raise ArgumentError, "You have named both your main application and your Jenkins application '#{name}'. In order to continue you'll need to specify a different name with --enable-jenkins or choose a different application name." if jenkins_app_name == name && enable_jenkins?
61
67
 
62
- raise RHC::Rest::DomainNotFoundException.new("No domains found. Please create a domain with 'rhc domain create <namespace>' before creating applications.") if rest_client.domains.empty?
63
- rest_domain = rest_client.find_domain(options.namespace)
68
+ rest_domain = check_domain!
64
69
  rest_app = nil
65
70
 
66
71
  cart_names = cartridges.collect do |c|
@@ -121,6 +126,9 @@ module RHC::Commands
121
126
  end if build_app_exists
122
127
  end
123
128
 
129
+ debug "Checking SSH keys through the wizard"
130
+ check_sshkeys! unless options.no_keys
131
+
124
132
  if options.dns
125
133
  paragraph do
126
134
  say "Waiting for your DNS name to be available ... "
@@ -139,9 +147,6 @@ module RHC::Commands
139
147
 
140
148
  if options.git
141
149
  paragraph do
142
- debug "Checking SSH keys through the wizard"
143
- check_sshkeys! unless options.noprompt
144
-
145
150
  say "Downloading the application Git repository ..."
146
151
  paragraph do
147
152
  begin
@@ -174,8 +179,8 @@ module RHC::Commands
174
179
  summary "Delete an application from the server"
175
180
  description "Deletes your application and all of its data from the server.",
176
181
  "Use with caution as this operation is permanent."
177
- syntax "<app> [--namespace namespace]"
178
- option ["-n", "--namespace namespace"], "Namespace your application belongs to", :context => :namespace_context, :required => true
182
+ syntax "<app> [--namespace NAME]"
183
+ option ["-n", "--namespace NAME"], "Namespace your application belongs to", :context => :namespace_context, :required => true
179
184
  option ["-b", "--bypass"], "DEPRECATED Please use '--confirm'", :deprecated => {:key => :confirm, :value => true}
180
185
  option ["--confirm"], "Pass to confirm deleting the application"
181
186
  argument :app, "The application you wish to delete", ["-a", "--app name"], :context => :app_context
@@ -193,9 +198,9 @@ module RHC::Commands
193
198
  end
194
199
 
195
200
  summary "Start the application"
196
- syntax "<app> [--namespace namespace] [--app app]"
197
- argument :app, "The name of the application you are starting", ["-a", "--app app"], :context => :app_context
198
- option ["-n", "--namespace namespace"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
201
+ syntax "<app> [--namespace NAME] [--app NAME]"
202
+ argument :app, "The name of the application you are starting", ["-a", "--app NAME"], :context => :app_context
203
+ option ["-n", "--namespace NAME"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
199
204
  def start(app)
200
205
  app_action app, :start
201
206
 
@@ -204,9 +209,9 @@ module RHC::Commands
204
209
  end
205
210
 
206
211
  summary "Stop the application"
207
- syntax "<app> [--namespace namespace] [--app app]"
208
- argument :app, "The name of the application you are stopping", ["-a", "--app app"], :context => :app_context
209
- option ["-n", "--namespace namespace"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
212
+ syntax "<app> [--namespace NAME] [--app NAME]"
213
+ argument :app, "The name of the application you are stopping", ["-a", "--app NAME"], :context => :app_context
214
+ option ["-n", "--namespace NAME"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
210
215
  def stop(app)
211
216
  app_action app, :stop
212
217
 
@@ -215,9 +220,9 @@ module RHC::Commands
215
220
  end
216
221
 
217
222
  summary "Stops all application processes"
218
- syntax "<app> [--namespace namespace] [--app app]"
219
- argument :app, "The name of the application you are stopping", ["-a", "--app app"], :context => :app_context
220
- option ["-n", "--namespace namespace"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
223
+ syntax "<app> [--namespace NAME] [--app NAME]"
224
+ argument :app, "The name of the application you are stopping", ["-a", "--app NAME"], :context => :app_context
225
+ option ["-n", "--namespace NAME"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
221
226
  def force_stop(app)
222
227
  app_action app, :stop, true
223
228
 
@@ -226,9 +231,9 @@ module RHC::Commands
226
231
  end
227
232
 
228
233
  summary "Restart the application"
229
- syntax "<app> [--namespace namespace] [--app app]"
230
- argument :app, "The name of the application you are restarting", ["-a", "--app app"], :context => :app_context
231
- option ["-n", "--namespace namespace"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
234
+ syntax "<app> [--namespace NAME] [--app NAME]"
235
+ argument :app, "The name of the application you are restarting", ["-a", "--app NAME"], :context => :app_context
236
+ option ["-n", "--namespace NAME"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
232
237
  def restart(app)
233
238
  app_action app, :restart
234
239
 
@@ -237,9 +242,9 @@ module RHC::Commands
237
242
  end
238
243
 
239
244
  summary "Reload the application's configuration"
240
- syntax "<app> [--namespace namespace] [--app app]"
241
- argument :app, "The name of the application you are reloading", ["-a", "--app app"], :context => :app_context
242
- option ["-n", "--namespace namespace"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
245
+ syntax "<app> [--namespace NAME] [--app NAME]"
246
+ argument :app, "The name of the application you are reloading", ["-a", "--app NAME"], :context => :app_context
247
+ option ["-n", "--namespace NAME"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
243
248
  def reload(app)
244
249
  app_action app, :reload
245
250
 
@@ -248,9 +253,9 @@ module RHC::Commands
248
253
  end
249
254
 
250
255
  summary "Clean out the application's logs and tmp directories and tidy up the git repo on the server"
251
- syntax "<app> [--namespace namespace] [--app app]"
252
- argument :app, "The name of the application you are tidying", ["-a", "--app app"], :context => :app_context
253
- option ["-n", "--namespace namespace"], "Namespace of the application belongs to", :context => :namespace_context, :required => true
256
+ syntax "<app> [--namespace NAME] [--app NAME]"
257
+ argument :app, "The name of the application you are tidying", ["-a", "--app NAME"], :context => :app_context
258
+ option ["-n", "--namespace NAME"], "Namespace of the application belongs to", :context => :namespace_context, :required => true
254
259
  def tidy(app)
255
260
  app_action app, :tidy
256
261
 
@@ -259,9 +264,9 @@ module RHC::Commands
259
264
  end
260
265
 
261
266
  summary "Show information about an application"
262
- syntax "<app> [--namespace namespace]"
263
- argument :app, "The name of the application you are getting information on", ["-a", "--app app"], :context => :app_context
264
- option ["-n", "--namespace namespace"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
267
+ syntax "<app> [--namespace NAME]"
268
+ argument :app, "The name of the application you are getting information on", ["-a", "--app NAME"], :context => :app_context
269
+ option ["-n", "--namespace NAME"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
265
270
  option ["--state"], "Get the current state of the cartridges in this application"
266
271
  option ["--gears"], "Show the ID, state, and cartridges on each gear in this application"
267
272
  def show(app_name)
@@ -282,9 +287,9 @@ module RHC::Commands
282
287
 
283
288
  summary "SSH into the specified application"
284
289
  syntax "<app> [--ssh path_to_ssh_executable]"
285
- argument :app, "The name of the application you want to SSH into", ["-a", "--app app"], :context => :app_context
290
+ argument :app, "The name of the application you want to SSH into", ["-a", "--app NAME"], :context => :app_context
286
291
  option ["--ssh PATH"], "Path to your SSH executable"
287
- option ["-n", "--namespace namespace"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
292
+ option ["-n", "--namespace NAME"], "Namespace of the application the cartridge belongs to", :context => :namespace_context, :required => true
288
293
  alias_action 'ssh', :root_command => true
289
294
  def ssh(app_name)
290
295
  raise ArgumentError, "No application specified" unless app_name.present?
@@ -303,9 +308,9 @@ module RHC::Commands
303
308
  end
304
309
 
305
310
  summary "DEPRECATED use 'show <app> --state' instead"
306
- syntax "<app> [--namespace namespace] [--app app]"
307
- argument :app, "The name of the application you are getting information on", ["-a", "--app app"], :context => :app_context
308
- option ["-n", "--namespace namespace"], "Namespace of the application belongs to", :context => :namespace_context, :required => true
311
+ syntax "<app> [--namespace NAME] [--app NAME]"
312
+ argument :app, "The name of the application you are getting information on", ["-a", "--app NAME"], :context => :app_context
313
+ option ["-n", "--namespace NAME"], "Namespace of the application belongs to", :context => :namespace_context, :required => true
309
314
  deprecated "rhc app show --state"
310
315
  def status(app)
311
316
  # TODO: add a way to deprecate this and alias to show --apache
@@ -335,9 +340,40 @@ module RHC::Commands
335
340
  end
336
341
 
337
342
  def check_sshkeys!
343
+ return unless interactive?
338
344
  RHC::SSHWizard.new(rest_client, config, options).run
339
345
  end
340
346
 
347
+ def check_name!(name)
348
+ return unless name.blank?
349
+
350
+ paragraph{ say "When creating an application, you must provide a name and a cartridge from the list below:" }
351
+ paragraph{ list_cartridges(standalone_cartridges) }
352
+
353
+ raise ArgumentError, "Please specify the name of the application and the web cartridge to install"
354
+ end
355
+
356
+ def check_config!
357
+ return if not interactive? or (!options.clean && config.has_local_config?) or (options.server && (options.rhlogin || options.token))
358
+ RHC::EmbeddedWizard.new(config, options).run
359
+ end
360
+
361
+ def check_domain!
362
+ if options.namespace
363
+ rest_client.find_domain(options.namespace)
364
+ else
365
+ if rest_client.domains.empty?
366
+ raise RHC::Rest::DomainNotFoundException, "No domains found. Please create a domain with 'rhc domain create <namespace>' before creating applications." unless interactive?
367
+ RHC::DomainWizard.new(config, options, rest_client).run
368
+ end
369
+ domain = rest_client.domains.first
370
+ raise RHC::Rest::DomainNotFoundException, "No domains found. Please create a domain with 'rhc domain create <namespace>' before creating applications." unless domain
371
+ options.namespace = domain.id
372
+ domain
373
+ end
374
+ end
375
+
376
+
341
377
  def gear_groups_for_app(app_name)
342
378
  rest_client.find_application_gear_groups(options.namespace, app_name)
343
379
  end
@@ -1,7 +1,7 @@
1
1
  module RHC::Commands
2
2
  class Authorization < Base
3
3
 
4
- summary "Display the authorization tokens created under your account"
4
+ summary "Show the authorization tokens for your account"
5
5
  description <<-DESC
6
6
  Shows the full list of authorization tokens on your account. You
7
7
  can add, edit, or delete authorizations with subcommands.
@@ -11,8 +11,9 @@ module RHC::Commands
11
11
  add an optional note to each authorization token to assist you in
12
12
  remembering what is available.
13
13
  DESC
14
+ alias_action 'authorizations', :root_command => true
14
15
  def run
15
- rest_client.authorizations.each{ |auth| paragraph{ display_authorization(auth, options.token) } } or info "No authorizations"
16
+ rest_client.authorizations.each{ |auth| paragraph{ display_authorization(auth, token_for_user) } } or info "No authorizations"
16
17
 
17
18
  0
18
19
  end
@@ -21,6 +22,7 @@ module RHC::Commands
21
22
  option "--note NOTE", "A description of this authorization (optional)"
22
23
  option "--expires-in SECONDS", "The number of seconds before this authorization expires (optional)"
23
24
  summary "Add an authorization to your account"
25
+ syntax "--scopes SCOPES [--note NOTE] [--expires-in SECONDS]"
24
26
  description <<-DESC
25
27
  Add an authorization to your account. An authorization token grants
26
28
  access to the OpenShift REST API with a set of privleges called 'scopes'
@@ -26,14 +26,21 @@ class RHC::Commands::Base
26
26
  # to the OpenShift API that transforms intent
27
27
  # and options, to remote calls, and then handle
28
28
  # the output (or failures) into exceptions and
29
- # formatted object output. Most interactions
29
+ # formatted object output. Most interactions
30
30
  # should be through this call pattern.
31
31
  def rest_client(opts={})
32
32
  @rest_client ||= begin
33
33
  auth = RHC::Auth::Basic.new(options)
34
- auth = RHC::Auth::Token.new(options, auth, token_store)
34
+ auth = RHC::Auth::Token.new(options, auth, token_store) if (options.use_authorization_tokens || options.token) && !(options.rhlogin && options.password)
35
+ debug "Authenticating with #{auth.class}"
35
36
  client_from_options(:auth => auth)
36
37
  end
38
+
39
+ if opts[:min_api] && opts[:min_api].to_f > @rest_client.api_version_negotiated.to_f
40
+ raise RHC::ServerAPINotSupportedException.new(opts[:min_api], @rest_client.api_version_negotiated)
41
+ end
42
+
43
+ @rest_client
37
44
  end
38
45
 
39
46
  def token_store
@@ -60,12 +67,15 @@ class RHC::Commands::Base
60
67
  return if private_method_defined? method
61
68
  return if protected_method_defined? method
62
69
 
70
+ prefix = self.object_name
63
71
  method_name = method.to_s == 'run' ? nil : method.to_s.gsub("_", "-")
64
- name = [method_name]
65
- name.unshift(self.object_name).compact!
72
+ name = [prefix, method_name].compact
66
73
  raise InvalidCommand, "Either object_name must be set or a non default method defined" if name.empty?
74
+
75
+ aliases.each{ |a| a[:action].unshift(prefix) unless a[:root_command] } if prefix
76
+
67
77
  RHC::Commands.add((@options || {}).merge({
68
- :name => name.join(' '),
78
+ :name => name,
69
79
  :class => self,
70
80
  :method => method
71
81
  }));
@@ -84,12 +94,7 @@ class RHC::Commands::Base
84
94
 
85
95
  def self.description(*args)
86
96
  o = args.join(' ')
87
- indent = o.scan(/^[ \t]*(?=\S)/).min.size || 0
88
- options[:description] =
89
- o.gsub(/^[ \t]{#{indent}}/, '').
90
- gsub(/(\b|')\s*\n(?!\s*\n)(\S)/m, '\1 \2').
91
- gsub(/\n+\Z/, '').
92
- gsub(/\n{3,}/, "\n\n")
97
+ options[:description] = o.strip_heredoc
93
98
  end
94
99
  def self.summary(value)
95
100
  options[:summary] = value
@@ -108,13 +113,17 @@ class RHC::Commands::Base
108
113
  @suppress_wizard
109
114
  end
110
115
 
116
+ #
117
+ # Provide an alias to the command. The alias will not be shown in help, but will
118
+ # be available in autocompletion and at execution time.
119
+ #
120
+ # Supported options:
121
+ #
122
+ # :deprecated - if true, a warning will be displayed when the command is executed
123
+ # :root_command - if true, do not prepend the object name to the command
124
+ #
111
125
  def self.alias_action(action, options={})
112
- # if it is a root_command we simply alias it to the passed in action
113
- # if not we prepend the current resource to the action
114
- # default == false
115
- options[:root_command] ||= false
116
- options[:action] = action
117
- options[:deprecated] ||= false
126
+ options[:action] = action.is_a?(Array) ? action : action.to_s.split(' ')
118
127
  aliases << options
119
128
  end
120
129
 
@@ -127,10 +136,8 @@ class RHC::Commands::Base
127
136
  }
128
137
  end
129
138
 
130
- def self.argument(name, description, switches, options={})
139
+ def self.argument(name, description, switches=[], options={})
131
140
  arg_type = options[:arg_type]
132
- raise ArgumentError("Only the last argument descriptor for an action can be a list") if arg_type == :list and list_argument_defined?
133
- list_argument_defined true if arg_type == :list
134
141
 
135
142
  option_symbol = Commander::Runner.switch_to_sym(switches.last)
136
143
  args_metadata << {:name => name,
@@ -138,6 +145,7 @@ class RHC::Commands::Base
138
145
  :switches => switches,
139
146
  :context_helper => options[:context],
140
147
  :option_symbol => option_symbol,
148
+ :optional => options[:optional],
141
149
  :arg_type => arg_type}
142
150
  end
143
151
 
@@ -147,22 +155,16 @@ class RHC::Commands::Base
147
155
  end
148
156
 
149
157
  private
150
- def self.list_argument_defined(bool)
151
- options[:list_argument_defined] = bool
152
- end
153
- def self.list_argument_defined?
154
- options[:list_argument_defined]
155
- end
156
158
  def self.options_metadata
157
159
  options[:options] ||= []
158
160
  end
159
161
  def self.args_metadata
160
162
  options[:args] ||= []
161
163
  end
162
- def self.options
163
- @options ||= {}
164
- end
165
164
  def self.aliases
166
165
  options[:aliases] ||= []
167
166
  end
167
+ def self.options
168
+ @options ||= {}
169
+ end
168
170
  end