rhcp_shell 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
data/bin/rhcp_shell CHANGED
@@ -7,10 +7,7 @@ require "getoptlong"
7
7
  require 'rubygems'
8
8
 
9
9
  require 'rhcp'
10
-
11
- require 'base_shell'
12
- require 'rhcp_shell_backend'
13
- require 'version'
10
+ require 'rhcp_shell'
14
11
 
15
12
  require 'uri'
16
13
 
File without changes
@@ -0,0 +1,11 @@
1
+ def format_hash_output(command, response)
2
+ output = []
3
+
4
+ max_key_length = response.data.keys().sort { |a,b| a.to_s.length <=> b.to_s.length }.last.to_s.length
5
+
6
+ response.data.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |k|
7
+ v = response.data[k]
8
+ output << sprintf(" %-#{max_key_length + 5}s\t%s", k, v)
9
+ end
10
+ output.join("\n")
11
+ end
@@ -21,9 +21,19 @@ def format_table_output(command, response)
21
21
  $logger.debug "column title list : #{column_title_list}"
22
22
 
23
23
  # TODO the sorting column should be configurable
24
- first_column = columns_to_display[0]
25
- $logger.debug "sorting by #{first_column}"
26
- response.data = response.data.sort { |a,b| a[first_column] <=> b[first_column] }
24
+ if response.data.size > 0
25
+ begin
26
+ first_column = columns_to_display[0]
27
+ $logger.debug "sorting by #{first_column}"
28
+ if response.data.first.has_key? first_column
29
+ response.data = response.data.sort { |a,b| a[first_column] <=> b[first_column] }
30
+ else
31
+ $logger.info "not sorting output because first defined column '#{first_column}' is missing in response data"
32
+ end
33
+ rescue => detail
34
+ $logger.warn "got a problem while sorting the output : #{detail.message}"
35
+ end
36
+ end
27
37
 
28
38
  # add the index column
29
39
  columns_to_display.unshift "__idx"
@@ -184,15 +184,19 @@ class RHCPShellBackend < ShellBackend
184
184
  request = RHCP::Request.new(command, @collected_values)
185
185
  response = @command_broker.execute(request)
186
186
 
187
- # we might want to access this response in further commands
188
- @last_response = response
189
-
190
187
  if (response.status == RHCP::Response::Status::OK)
191
-
192
188
  $logger.debug "raw result : #{response.data}"
193
189
  $logger.debug "result hints: #{command.result_hints}"
194
190
  $logger.debug "display_type : #{command.result_hints[:display_type]}"
191
+
192
+ #if not command.result_hints.has_key? :display_type
193
+ # puts response.data.class
194
+ #end
195
+
196
+ @last_response = response
195
197
  if command.result_hints[:display_type] == "table"
198
+ # we might want to access this response in further commands
199
+
196
200
  output = format_table_output(command, response)
197
201
  puts output
198
202
  elsif command.result_hints[:display_type] == "hash"
@@ -206,8 +210,14 @@ class RHCPShellBackend < ShellBackend
206
210
  puts output
207
211
  elsif command.result_hints[:display_type] == "hidden"
208
212
  $logger.debug "suppressing output due to display_type 'hidden'"
213
+ elsif command.result_hints[:display_type] == "raw"
214
+ p output
209
215
  else
210
- puts "executed '#{@command_selected.name}' successfully : #{@prompt_color_enabled ? green(response.data) : response.data}"
216
+ if @prompt_color_enabled
217
+ puts "#{green(@command_selected.name)} : #{response.data}"
218
+ else
219
+ puts "executed '#{@command_selected.name}' successfully : #{response.data}"
220
+ end
211
221
  end
212
222
 
213
223
  # if the command has been executed successfully, we might have to update the prompt
@@ -221,8 +231,12 @@ class RHCPShellBackend < ShellBackend
221
231
  Kernel.exit(0)
222
232
  end
223
233
 
224
- puts "could not execute '#{@command_selected.name}' : #{@prompt_color_enabled ? red(response.error_text) : response.error_text}"
225
- $logger.error "#{response.error_text} : #{response.error_detail}"
234
+ if @prompt_color_enabled
235
+ puts "#{red(@command_selected.name)} : #{response.error_text}"
236
+ else
237
+ puts "could not execute '#{@command_selected.name}' : #{response.error_text}"
238
+ end
239
+ $logger.error "[#{@command_selected.name}] #{response.error_text} : #{response.error_detail}"
226
240
 
227
241
  set_prompt nil
228
242
  end
@@ -310,7 +324,14 @@ class RHCPShellBackend < ShellBackend
310
324
  @current_param = @command_selected.get_param(key)
311
325
  add_parameter_value(value)
312
326
  rescue RHCP::RhcpException => ex
313
- puts "ignoring parameter value '#{value}' for param '#{key}' : " + ex.to_s
327
+ if @command_selected.accepts_extra_params
328
+ puts "collecting value for extra param : #{key} => #{value}"
329
+ @collected_values["extra_params"] = {} unless @collected_values.has_key?("extra_params")
330
+ @collected_values["extra_params"][key] = Array.new if @collected_values["extra_params"][key] == nil
331
+ @collected_values["extra_params"][key] << [ value ]
332
+ else
333
+ puts "ignoring parameter value '#{value}' for param '#{key}' : " + ex.to_s
334
+ end
314
335
  end
315
336
  end
316
337
  end
File without changes
@@ -1,3 +1,5 @@
1
+ require 'singleton'
2
+
1
3
  module RhcpShell #:nodoc:
2
4
 
3
5
  class Version
@@ -5,7 +7,7 @@ module RhcpShell #:nodoc:
5
7
 
6
8
  MAJOR = 0
7
9
  MINOR = 2
8
- TINY = 12
10
+ TINY = 13
9
11
 
10
12
  def Version.to_s
11
13
  [ MAJOR, MINOR, TINY ].join(".")
data/lib/rhcp_shell.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rhcp'
2
+
3
+ require 'rhcp_shell/version'
4
+ require 'rhcp_shell/base_shell'
5
+ require 'rhcp_shell/rhcp_shell_backend'
data/lib/test.log CHANGED
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,22 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhcp_shell
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease: false
4
+ hash: 13
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 12
10
- version: 0.2.12
9
+ - 13
10
+ version: 0.2.13
11
11
  platform: ruby
12
12
  authors:
13
- - Philipp Traeder
13
+ - Philipp T.
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-20 00:00:00 +01:00
19
- default_executable:
18
+ date: 2013-01-06 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: rhcp
@@ -35,7 +34,7 @@ dependencies:
35
34
  type: :runtime
36
35
  version_requirements: *id001
37
36
  description:
38
- email: philipp at hitchhackers.net
37
+ email: philipp at virtualop dot org
39
38
  executables:
40
39
  - rhcp_shell
41
40
  extensions: []
@@ -44,22 +43,22 @@ extra_rdoc_files: []
44
43
 
45
44
  files:
46
45
  - bin/rhcp_shell
47
- - lib/base_shell.rb
46
+ - lib/rhcp_shell.rb
47
+ - lib/rhcp_shell/util/colorize.rb
48
+ - lib/rhcp_shell/rhcp_shell_backend.rb
49
+ - lib/rhcp_shell/local_commands/set_prompt.rb
50
+ - lib/rhcp_shell/local_commands/context.rb
51
+ - lib/rhcp_shell/local_commands/detail.rb
52
+ - lib/rhcp_shell/local_commands/help.rb
53
+ - lib/rhcp_shell/local_commands/exit.rb
54
+ - lib/rhcp_shell/version.rb
55
+ - lib/rhcp_shell/display_types/hash.rb
56
+ - lib/rhcp_shell/display_types/table.rb
57
+ - lib/rhcp_shell/base_shell.rb
58
+ - lib/rhcp_shell/shell_backend.rb
48
59
  - lib/test.log
49
- - lib/shell_backend.rb
50
- - lib/rhcp_shell_backend.rb
51
- - lib/local_commands/set_prompt.rb
52
- - lib/local_commands/help.rb
53
- - lib/local_commands/context.rb
54
- - lib/local_commands/detail.rb
55
- - lib/local_commands/exit.rb
56
- - lib/version.rb
57
- - lib/util/colorize.rb
58
- - lib/display_types/hash.rb
59
- - lib/display_types/table.rb
60
60
  - test/rhcp_shell_backend_test.rb
61
61
  - test/setup_test_registry.rb
62
- has_rdoc: true
63
62
  homepage: http://rubyforge.org/projects/rhcp
64
63
  licenses: []
65
64
 
@@ -88,10 +87,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
87
  version: "0"
89
88
  requirements: []
90
89
 
91
- rubyforge_project: rhcp
92
- rubygems_version: 1.3.7
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.24
93
92
  signing_key:
94
93
  specification_version: 3
95
- summary: RHCP is a protocol designed for building up a command-metadata-based communication infrastructure making it easier for application developers to export commands in applications to generic clients - this is the generic shell for it.
94
+ summary: command line shell for RHCP
96
95
  test_files: []
97
96
 
@@ -1,10 +0,0 @@
1
- def format_hash_output(command, response)
2
- output = []
3
-
4
- max_key_length = response.data.keys().sort { |a,b| a.length <=> b.length }.first.length
5
-
6
- response.data.each do |k,v|
7
- output << sprintf(" %-#{max_key_length + 5}s\t%s", k, v)
8
- end
9
- output.join("\n")
10
- end