rhc 0.97.17 → 0.98.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/bin/rhc +9 -9
  2. data/bin/rhc-port-forward +3 -0
  3. data/bin/rhc-sshkey +3 -0
  4. data/features/README.md +163 -35
  5. data/features/application.feature +24 -0
  6. data/features/cartridge.feature +24 -0
  7. data/features/client.feature +11 -0
  8. data/features/domain.feature +29 -0
  9. data/features/lib/rhc_helper.rb +14 -0
  10. data/features/lib/rhc_helper/app.rb +2 -8
  11. data/features/lib/rhc_helper/cartridge.rb +1 -7
  12. data/features/lib/rhc_helper/commandify.rb +37 -6
  13. data/features/lib/rhc_helper/domain.rb +5 -1
  14. data/features/lib/rhc_helper/httpify.rb +124 -60
  15. data/features/lib/rhc_helper/loggable.rb +0 -2
  16. data/features/lib/rhc_helper/persistable.rb +12 -2
  17. data/features/lib/rhc_helper/sshkey.rb +29 -0
  18. data/features/multiple_cartridge.feature +17 -0
  19. data/features/sshkey.feature +58 -0
  20. data/features/step_definitions/application_steps.rb +60 -52
  21. data/features/step_definitions/cartridge_steps.rb +22 -24
  22. data/features/step_definitions/client_steps.rb +9 -2
  23. data/features/step_definitions/domain_steps.rb +4 -0
  24. data/features/step_definitions/sshkey_steps.rb +56 -0
  25. data/features/support/assumptions.rb +37 -0
  26. data/features/support/before_hooks.rb +25 -0
  27. data/features/support/env.rb +84 -39
  28. data/features/support/key1 +27 -0
  29. data/features/support/key1.pub +1 -0
  30. data/features/support/key2 +27 -0
  31. data/features/support/key2.pub +1 -0
  32. data/features/support/key3.pub +1 -0
  33. data/features/support/ssh.sh +2 -0
  34. data/features/verify.feature +18 -159
  35. data/lib/rhc-common.rb +8 -21
  36. data/lib/rhc.rb +9 -5
  37. data/lib/rhc/autocomplete.rb +68 -0
  38. data/lib/rhc/autocomplete_templates/rhc.erb +33 -0
  39. data/lib/rhc/cli.rb +9 -6
  40. data/lib/rhc/command_runner.rb +108 -0
  41. data/lib/rhc/commands.rb +66 -132
  42. data/lib/rhc/commands/base.rb +95 -24
  43. data/lib/rhc/commands/domain.rb +33 -50
  44. data/lib/rhc/commands/port-forward.rb +81 -0
  45. data/lib/rhc/commands/setup.rb +1 -1
  46. data/lib/rhc/commands/sshkey.rb +95 -0
  47. data/lib/rhc/config.rb +108 -103
  48. data/lib/rhc/context_helper.rb +19 -0
  49. data/lib/rhc/coverage_helper.rb +1 -1
  50. data/lib/rhc/exceptions.rb +55 -4
  51. data/lib/rhc/help_formatter.rb +2 -3
  52. data/lib/rhc/helpers.rb +31 -23
  53. data/lib/{rhc-rest.rb → rhc/rest.rb} +95 -23
  54. data/lib/{rhc-rest → rhc/rest}/application.rb +1 -1
  55. data/lib/{rhc-rest → rhc/rest}/cartridge.rb +1 -1
  56. data/lib/{rhc-rest → rhc/rest}/client.rb +40 -9
  57. data/lib/{rhc-rest → rhc/rest}/domain.rb +1 -1
  58. data/lib/{rhc-rest → rhc/rest}/key.rb +11 -1
  59. data/lib/{rhc-rest → rhc/rest}/user.rb +1 -1
  60. data/lib/rhc/ssh_key_helpers.rb +10 -1
  61. data/lib/rhc/targz.rb +7 -8
  62. data/lib/rhc/usage_templates/command_help.erb +7 -6
  63. data/lib/rhc/usage_templates/help.erb +6 -9
  64. data/lib/rhc/usage_templates/missing_help.erb +1 -0
  65. data/lib/rhc/version.rb +2 -2
  66. data/lib/rhc/wizard.rb +4 -9
  67. data/spec/coverage_helper.rb +2 -2
  68. data/spec/rest_spec_helper.rb +66 -16
  69. data/spec/rhc/cli_spec.rb +16 -5
  70. data/spec/rhc/command_spec.rb +61 -6
  71. data/spec/rhc/commands/domain_spec.rb +50 -27
  72. data/spec/rhc/commands/port-forward_spec.rb +133 -0
  73. data/spec/rhc/commands/setup_spec.rb +2 -2
  74. data/spec/rhc/commands/sshkey_spec.rb +141 -0
  75. data/spec/rhc/common_spec.rb +1 -1
  76. data/spec/rhc/config_spec.rb +6 -4
  77. data/spec/rhc/helpers_spec.rb +0 -21
  78. data/spec/rhc/rest_application_spec.rb +7 -7
  79. data/spec/rhc/rest_client_spec.rb +87 -24
  80. data/spec/rhc/rest_spec.rb +36 -36
  81. data/spec/rhc/wizard_spec.rb +3 -3
  82. data/spec/spec.opts +1 -0
  83. data/spec/spec_helper.rb +3 -3
  84. metadata +61 -31
  85. data/lib/rhc-rest/exceptions/exceptions.rb +0 -75
  86. data/test/functional/application_test.rb +0 -71
  87. data/test/functional/domain_test.rb +0 -123
  88. data/test/functional/test_credentials.rb +0 -5
  89. data/test/sample-usage.rb +0 -122
  90. data/test/support/server.rb +0 -14
  91. data/test/support/testcase.rb +0 -3
  92. data/test/test_helper.rb +0 -4
  93. data/test/unit/command_test.rb +0 -19
data/lib/rhc/commands.rb CHANGED
@@ -3,100 +3,6 @@ require 'rhc/helpers'
3
3
 
4
4
  module RHC
5
5
  module Commands
6
- class CommandHelpBindings
7
- def initialize(command, instance_commands, global_options)
8
- @command = command
9
- @actions = instance_commands.collect do |ic|
10
- m = /^#{command.name} ([^ ]+)/.match(ic[0])
11
- # if we have a match and it is not an alias then we can use it
12
- m and ic[0] == ic[1].name ? {:name => m[1], :summary => ic[1].summary || ""} : nil
13
- end
14
- @actions.compact!
15
- @global_options = global_options
16
- end
17
- end
18
- class Runner < Commander::Runner
19
- # regex fix from git - match on word boundries
20
- def valid_command_names_from *args
21
- arg_string = args.delete_if { |value| value =~ /^-/ }.join ' '
22
- commands.keys.find_all { |name| name if /^#{name}\b/.match arg_string }
23
- end
24
-
25
- # override so we can do our own error handling
26
- def run!
27
- trace = false
28
- require_program :version, :description
29
- trap('INT') { abort program(:int_message) } if program(:int_message)
30
- trap('INT') { program(:int_block).call } if program(:int_block)
31
- global_option('-h', '--help', 'Display help documentation') do
32
- args = @args - %w[-h --help]
33
- command(:help).run(*args)
34
- return
35
- end
36
- global_option('-v', '--version', 'Display version information') { say version; return }
37
- global_option('-t', '--trace', 'Display backtrace when an error occurs') { trace = true }
38
- parse_global_options
39
- remove_global_options options, @args
40
-
41
- # if help is last arg run as if --help was passed in
42
- if @args[-1] == "help"
43
- args = @args - ["help"]
44
- command(:help).run(*args)
45
- return
46
- end
47
-
48
- unless trace
49
- begin
50
- run_active_command
51
- rescue InvalidCommandError => e
52
- usage = RHC::UsageHelpFormatter.new(self).render
53
- i = @args.find_index { |a| a.start_with?('-') } || @args.length
54
- abort "The command 'rhc #{@args[0,i].join(' ')}' is not recognized.\n#{usage}"
55
- rescue \
56
- ArgumentError,
57
- OptionParser::InvalidOption,
58
- OptionParser::InvalidArgument,
59
- OptionParser::MissingArgument => e
60
-
61
- help_bindings = CommandHelpBindings.new(active_command, commands, Commander::Runner.instance.options)
62
- usage = RHC::UsageHelpFormatter.new(self).render_command(help_bindings)
63
- say "#{e}\n#{usage}"
64
- 1
65
- rescue Rhc::Rest::BaseException => e
66
- RHC::Helpers.results { say "#{e}" }
67
- e.code.nil? ? 128 : e.code
68
- rescue Exception => e
69
- RHC::Helpers.results { say "error: #{e} Use --trace to view backtrace." }
70
- 128
71
- end
72
- else
73
- run_active_command
74
- end
75
- end
76
-
77
- def create_default_commands
78
- command :help do |c|
79
- c.syntax = 'rhc help <command>'
80
- c.description = 'Display global or <command> help documentation.'
81
- c.when_called do |args, options|
82
- if args.empty?
83
- say help_formatter.render
84
- else
85
- command = command args.join(' ')
86
- begin
87
- require_valid_command command
88
- rescue InvalidCommandError => e
89
- abort "#{e}"
90
- end
91
-
92
- help_bindings = CommandHelpBindings.new command, commands, Commander::Runner.instance.options
93
- say help_formatter.render_command help_bindings
94
- end
95
- end
96
- end
97
- end
98
- end
99
-
100
6
  def self.load
101
7
  Dir[File.join(File.dirname(__FILE__), "commands", "*.rb")].each do |file|
102
8
  require file
@@ -106,71 +12,96 @@ module RHC
106
12
  def self.add(opts)
107
13
  commands[opts[:name]] = opts
108
14
  end
109
- def self.global_option(switches, description)
110
- global_options << [switches, description].flatten(1)
111
- end
112
- def self.validate_command(c, args, options, args_metadata)
113
- # check to see if an arg's option was set
114
- raise ArgumentError.new("Invalid arguments") if args.length > args_metadata.length
115
- args_metadata.each_with_index do |arg_meta, i|
116
- switch = arg_meta[:switches]
117
- value = options.__hash__[arg_meta[:name]]
118
- unless value.nil?
119
- raise ArgumentError.new("#{arg_meta[:name]} specified twice on the command line and as a #{switch[0]} switch") unless args.length == i
120
- # add the option as an argument
121
- args << value
122
- end
123
- end
15
+ def self.global_option(*args, &block)
16
+ global_options << [args, block]
124
17
  end
125
18
 
126
19
  def self.global_config_setup(options)
127
20
  RHC::Config.set_opts_config(options.config) if options.config
128
21
  RHC::Config.password = options.password if options.password
129
22
  RHC::Config.opts_login = options.rhlogin if options.rhlogin
130
- RHC::Config.noprompt(options.noprompt) if options.noprompt
131
23
  RHC::Config
132
24
  end
133
25
 
134
- def self.needs_configuration!(cmd, config)
135
- # check to see if we need to run wizard
136
- if not cmd.class.suppress_wizard?
137
- w = RHC::Wizard.new config
138
- return w.run if w.needs_configuration?
26
+ def self.deprecated?
27
+ command_name = Commander::Runner.instance.command_name_from_args
28
+ command = Commander::Runner.instance.active_command
29
+
30
+ if deprecated[command_name]
31
+ msg = "The command 'rhc #{command_name}' is deprecated. Please use 'rhc #{command.name}' instead."
32
+
33
+ raise DeprecatedError.new("#{msg} For porting and testing purposes you may switch this error to a warning by setting the DISABLE_DEPRECATED environment variable to 0. It is not recommended to do so in a production environment as this command may be removed in future releases.") if RHC::Helpers.disable_deprecated?
34
+
35
+ warn "Warning: #{msg} For porting and testing purposes you may switch this warning to an error by setting the DISABLE_DEPRECATED environment variable to 1. This command may be removed in future releases."
36
+ end
37
+ end
38
+
39
+ def self.needs_configuration!(cmd, options, config)
40
+ if not (cmd.class.suppress_wizard? or
41
+ options.noprompt or
42
+ options.help or
43
+ config.has_local_config? or
44
+ config.has_opts_config?)
45
+ RHC::Wizard.new(config).run
139
46
  end
140
- false
141
47
  end
142
48
 
143
49
  def self.to_commander(instance=Commander::Runner.instance)
144
- global_options.each{ |args| instance.global_option *args }
50
+ global_options.each do |args, block|
51
+ opts = (args.pop if Hash === args.last) || {}
52
+ option = instance.global_option(*args, &block).last
53
+ option.merge!(opts)
54
+ end
145
55
  commands.each_pair do |name, opts|
146
56
  instance.command name do |c|
147
57
  c.description = opts[:description]
148
58
  c.summary = opts[:summary]
149
59
  c.syntax = opts[:syntax]
150
60
 
151
- (opts[:options]||[]).each { |o| c.option *o }
152
- args_metadata = opts[:args] || []
153
- (args_metadata).each do |arg_meta|
154
- arg_switches = arg_meta[:switches]
155
- arg_switches << arg_meta[:description]
156
- c.option *arg_switches unless arg_switches.nil?
61
+ (options_metadata = opts[:options] || []).each do |o|
62
+ option_data = [o[:switches], o[:description]].flatten(1)
63
+ c.option *option_data
64
+ o[:arg] = Commander::Runner.switch_to_sym(o[:switches].last)
157
65
  end
158
66
 
159
- c.when_called do |args, options|
160
- validate_command c, args, options, args_metadata
161
- config = global_config_setup options
162
- cmd = opts[:class].new c, args, options, config
163
- needs_configuration! cmd, config
164
- cmd.send opts[:method], *args
67
+ args_metadata = opts[:args] || []
68
+ args_metadata.each do |arg_meta|
69
+ arg_switches = arg_meta[:switches]
70
+ unless arg_switches.nil? or arg_switches.empty?
71
+ arg_switches << arg_meta[:description]
72
+ c.option *arg_switches
73
+ end
165
74
  end
166
75
 
167
76
  unless opts[:aliases].nil?
168
77
  opts[:aliases].each do |a|
169
- alias_components = name.split(" ")
170
- alias_components[-1] = a
171
- instance.alias_command "#{alias_components.join(' ')}", :"#{name}"
78
+ alias_cmd = a[:action]
79
+
80
+ unless a[:root_command]
81
+ # prepend the current resource
82
+ alias_components = name.split(" ")
83
+ alias_components[-1] = a[:action]
84
+ alias_cmd = alias_components.join(' ')
85
+ end
86
+
87
+ deprecated[alias_cmd] = true if a[:deprecated]
88
+ instance.alias_command "#{alias_cmd}", :"#{name}"
172
89
  end
173
90
  end
91
+
92
+ c.when_called do |args, options|
93
+ config = global_config_setup(options)
94
+ deprecated?
95
+
96
+ cmd = opts[:class].new
97
+ cmd.options = options
98
+ cmd.config = config
99
+
100
+ filled_args = cmd.validate_args_and_options(args_metadata, options_metadata, args)
101
+
102
+ needs_configuration!(cmd, options, config)
103
+ cmd.send(opts[:method], *filled_args)
104
+ end
174
105
  end
175
106
  end
176
107
  self
@@ -183,5 +114,8 @@ module RHC
183
114
  def self.global_options
184
115
  @options ||= []
185
116
  end
117
+ def self.deprecated
118
+ @deprecated ||= {}
119
+ end
186
120
  end
187
121
  end
@@ -5,23 +5,66 @@ require 'rhc/wizard'
5
5
  require 'rhc/config'
6
6
  require 'rhc/commands'
7
7
  require 'rhc/exceptions'
8
+ require 'rhc/context_helper'
8
9
 
9
10
  class RHC::Commands::Base
10
11
 
11
- def initialize(command=nil,
12
- args=[],
13
- options=Commander::Command::Options.new,
14
- config=RHC::Config)
15
- @command, @args, @options, @config = command, args, options, config
12
+ attr_writer :options, :config
13
+
14
+ def initialize(options=Commander::Command::Options.new,
15
+ config=nil)
16
+ @options, @config = options, config
16
17
 
17
18
  # apply timeout here even though it isn't quite a global
18
19
  $rest_timeout = @options.timeout ? @options.timeout.to_i : nil
19
20
  end
20
21
 
22
+ def validate_args_and_options(args_metadata, options_metadata, args)
23
+ # process options
24
+ options_metadata.each do |option_meta|
25
+ arg = option_meta[:arg]
26
+
27
+ context_helper = option_meta[:context_helper]
28
+ @options.__hash__[arg] = self.send(context_helper) if @options.__hash__[arg].nil? and context_helper
29
+ raise ArgumentError.new("Missing required option '#{arg}'.") if option_meta[:required] and @options.__hash__[arg].nil?
30
+ end
31
+
32
+ # process args
33
+ arg_slots = [].fill(nil, 0, args_metadata.length)
34
+ fill_args = args.reverse
35
+ args_metadata.each_with_index do |arg_meta, i|
36
+ # check options
37
+ value = @options.__hash__[arg_meta[:name]]
38
+ if value
39
+ arg_slots[i] = value
40
+ elsif arg_meta[:arg_type] == :list
41
+ arg_slots[i] = fill_args.reverse
42
+ fill_args = []
43
+ else
44
+ raise ArgumentError.new("Missing required argument '#{arg_meta[:name]}'.") if fill_args.empty?
45
+ arg_slots[i] = fill_args.pop
46
+ end
47
+ end
48
+
49
+ raise ArgumentError.new("Too many arguments passed in.") unless fill_args.empty?
50
+
51
+ arg_slots
52
+ end
53
+
21
54
  protected
22
55
  include RHC::Helpers
56
+ include RHC::ContextHelpers
23
57
 
24
- attr_reader :command, :args, :options, :config
58
+ attr_reader :options, :config
59
+
60
+ #
61
+ # The implicit config object provides no defaults.
62
+ #
63
+ def config
64
+ @config ||= begin
65
+ RHC::Config.new
66
+ end
67
+ end
25
68
 
26
69
  def application
27
70
  #@application ||= ... identify current application or throw,
@@ -31,18 +74,26 @@ class RHC::Commands::Base
31
74
  # current git repo for remote, fail.
32
75
  end
33
76
 
34
- def client
35
- #@client ||= ... Return a client object capable of making calls
36
- # to the OpenShift API that transforms intent
37
- # and options, to remote calls, and then handle
38
- # the output (or failures) into exceptions and
39
- # formatted object output. Most interactions
40
- # should be through this call pattern.
41
- #
42
- # Initialize with auth (a separate responsibility
43
- # object).
77
+ # Return a client object capable of making calls
78
+ # to the OpenShift API that transforms intent
79
+ # and options, to remote calls, and then handle
80
+ # the output (or failures) into exceptions and
81
+ # formatted object output. Most interactions
82
+ # should be through this call pattern.
83
+ def rest_client
84
+ @rest_client ||= begin
85
+ username = config.username
86
+ unless username
87
+ username = ask "To connect to #{openshift_server} enter your OpenShift login (email or Red Hat login id): "
88
+ config.config_user(username)
89
+ end
90
+ password = RHC::Config.password || RHC::get_password
91
+
92
+ RHC::Rest::Client.new(openshift_rest_node, username, password, @options.debug)
93
+ end
44
94
  end
45
95
 
96
+
46
97
  class InvalidCommand < StandardError ; end
47
98
 
48
99
  def self.inherited(klass)
@@ -62,7 +113,7 @@ class RHC::Commands::Base
62
113
  RHC::Commands.add((@options || {}).merge({
63
114
  :name => name.join(' '),
64
115
  :class => self,
65
- :method => method,
116
+ :method => method
66
117
  }));
67
118
  @options = nil
68
119
  end
@@ -72,7 +123,7 @@ class RHC::Commands::Base
72
123
  value ||= if self.name && !self.name.empty?
73
124
  self.name.split('::').last
74
125
  end
75
- value.to_s.downcase if value
126
+ value.to_s.split(/(?=[A-Z])/).join('-').downcase if value
76
127
  end
77
128
  end
78
129
 
@@ -94,16 +145,30 @@ class RHC::Commands::Base
94
145
  @suppress_wizard
95
146
  end
96
147
 
97
- def self.alias_action(action)
98
- aliases << action
148
+ def self.alias_action(action, options={})
149
+ # if it is a root_command we simply alias it to the passed in action
150
+ # if not we prepend the current resource to the action
151
+ # default == false
152
+ options[:root_command] ||= false
153
+ options[:action] = action
154
+ options[:deprecated] ||= false
155
+ aliases << options
99
156
  end
100
157
 
101
- def self.option(switches, description)
102
- options_metadata << [switches, description].flatten(1)
158
+ def self.option(switches, description, options={})
159
+ options_metadata << {:switches => switches,
160
+ :description => description,
161
+ :context_helper => options[:context],
162
+ :required => options[:required]
163
+ }
103
164
  end
104
165
 
105
- def self.argument(name, description, switches)
106
- args_metadata << {:name => name, :description => description, :switches => switches}
166
+ def self.argument(name, description, switches, options={})
167
+ arg_type = options[:arg_type]
168
+ raise ArgumentError("Only the last argument descriptor for an action can be a list") if arg_type == :list and list_argument_defined?
169
+ list_argument_defined true if arg_type == :list
170
+
171
+ args_metadata << {:name => name, :description => description, :switches => switches, :arg_type => arg_type}
107
172
  end
108
173
 
109
174
  def self.default_action(action)
@@ -111,6 +176,12 @@ class RHC::Commands::Base
111
176
  end
112
177
 
113
178
  private
179
+ def self.list_argument_defined(bool)
180
+ options[:list_argument_defined] = bool
181
+ end
182
+ def self.list_argument_defined?
183
+ options[:list_argument_defined]
184
+ end
114
185
  def self.options_metadata
115
186
  options[:options] ||= []
116
187
  end
@@ -2,11 +2,11 @@ require 'rhc/commands/base'
2
2
 
3
3
  module RHC::Commands
4
4
  class Domain < Base
5
- summary "Manage your domain"
5
+ summary "Manage the domain and namespace for your applications."
6
6
  syntax "<action>"
7
7
  default_action :show
8
8
 
9
- summary "Bind a registered user to a domain"
9
+ summary "Define a namespace for your applications to share."
10
10
  syntax "<namespace> [--timeout timeout]"
11
11
  argument :namespace, "Namespace for your application(s) (alphanumeric)", ["-n", "--namespace namespace"]
12
12
  option ["--timeout timeout"], "Timeout, in seconds, for the session"
@@ -22,9 +22,9 @@ module RHC::Commands
22
22
  0
23
23
  end
24
24
 
25
- summary "Update namespace (will change urls)."
25
+ summary "Change current namespace (will change application urls)"
26
26
  syntax "<namespace> [--timeout timeout]"
27
- argument :namespace, "Namespace for your application(s) (alphanumeric)", ["-n", "--namespace namespace"]
27
+ argument :namespace, "Namespace to change", ["-n", "--namespace namespace"]
28
28
  option ["--timeout timeout"], "Timeout, in seconds, for the session"
29
29
  alias_action :alter
30
30
  def update(namespace)
@@ -33,9 +33,9 @@ module RHC::Commands
33
33
  # but in the future this will be manditory if you have more than one
34
34
  # domain. Figure out how to support overloading of commands
35
35
  domain = rest_client.domains
36
- raise RHC::DomainNotFoundException.new("No domains are registered to the user #{config.username}. Please use 'rhc domain create' to create one.") if domain.empty?
36
+ raise RHC::DomainNotFoundException, "No domains are registered to the user #{config.username}. Please use 'rhc domain create' to create one." if domain.empty?
37
37
 
38
- paragraph { say "Updating domain '#{domain[0].id}' to namespace '#{namespace}'" }
38
+ say "Changing namespace '#{domain[0].id}' to '#{namespace}'..."
39
39
 
40
40
  domain[0].update(namespace)
41
41
 
@@ -47,57 +47,41 @@ module RHC::Commands
47
47
  0
48
48
  end
49
49
 
50
- summary "Show your configured domains"
50
+ summary "Display the applications in your domain"
51
51
  def show
52
- domains = rest_client.domains
53
- paragraph do
54
- say "User Info"
55
- say "========="
56
- if domains.length == 0
57
- say "Namespace: No namespaces found. You can use 'rhc domain create <namespace>' to create a namespace for your applications."
58
- elsif domains.length == 1
59
- say "Namespace: #{domains[0].id}"
60
- else
61
- domains.each_with_index { |d, i| say "Namespace(#{i}): #{d.id}" }
62
- end
63
- end
52
+ domain = rest_client.domains.first
64
53
 
65
- paragraph { say "Login: #{config.username}" }
66
- domains.each do |d|
54
+ if domain
67
55
  paragraph do
68
- header = "Namespace #{d.id}'s Applications"
69
- say header
70
- say "=" * header.length
71
- apps = d.applications
56
+ say "Applications in #{domain.id}:"
57
+ apps = domain.applications
72
58
  if apps.length == 0
73
- say "No applications found. You can use 'rhc app create' to create new applications."
59
+ say "No applications. You can use 'rhc app create' to create new applications."
74
60
  else
75
- apps.each do |a|
61
+ apps.each_with_index do |a,i|
76
62
  carts = a.cartridges
77
- paragraph do
78
- say a.name
79
- say " Framework: #{carts[0].name}"
80
- say " Creation: #{a.creation_time}"
81
- say " UUID: #{a.uuid}"
82
- say " Git URL: #{a.git_url}" if a.git_url
83
- say " Public URL: #{a.app_url}" if a.app_url
84
- say " Aliases: #{a.aliases.join(', ')}" if a.aliases and not a.aliases.empty?
85
- say " Cartridges:"
86
- if carts.length > 1
63
+ section(:top => (i == 0 ? 1 : 2)) do
64
+ header "%s @ %s" % [a.name, a.app_url]
65
+ say "Created: #{date(a.creation_time)}"
66
+ #say " UUID: #{a.uuid}"
67
+ say "Git URL: #{a.git_url}" if a.git_url
68
+ say "Aliases: #{a.aliases.join(', ')}" if a.aliases and not a.aliases.empty?
69
+ if carts.present?
70
+ say "\nCartridges:"
87
71
  carts.each do |c|
88
- if c.type == 'embedded'
89
- connection_url = c.property(:cart_data, :connection_url) || c.property(:cart_data, :job_url) || c.property(:cart_data, :monitoring_url)
90
- value = connection_url ? " - #{connection_url['value']}" : ""
91
- say " #{c.name}#{value}"
92
- end
72
+ connection_url = c.property(:cart_data, :connection_url) || c.property(:cart_data, :job_url) || c.property(:cart_data, :monitoring_url)
73
+ value = connection_url ? " - #{connection_url['value']}" : ""
74
+ say " #{c.name}#{value}"
93
75
  end
94
76
  else
95
- say " None"
77
+ say "Cartridges: none"
96
78
  end
97
79
  end
98
80
  end
99
81
  end
100
82
  end
83
+ else
84
+ say "No domain exists. You can use 'rhc domain create' to create a namespace for applications." unless domain
101
85
  end
102
86
  0
103
87
  end
@@ -123,15 +107,14 @@ module RHC::Commands
123
107
  option ["--timeout timeout"], "Timeout, in seconds, for the session"
124
108
  alias_action :destroy
125
109
  def delete(namespace)
126
- paragraph { say "Deleting domain '#{namespace}'" }
127
110
  domain = rest_client.find_domain namespace
128
111
 
129
- paragraph do
130
- begin
131
- domain.destroy
132
- rescue Rhc::Rest::ClientErrorException
133
- raise Rhc::Rest::ClientErrorException.new("Domain contains applications. Delete applications first.", 128)
134
- end
112
+ say "Deleting domain '#{namespace}'"
113
+
114
+ begin
115
+ domain.destroy
116
+ rescue RHC::Rest::ClientErrorException #FIXME: I am insufficiently specific
117
+ raise RHC::Exception.new("Domain contains applications. Delete applications first.", 128)
135
118
  end
136
119
 
137
120
  results { say "Success!" }