incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r984327 - in /incubator/deltacloud/trunk/client: bin/deltacloudc lib/deltacloud.rb lib/plain_formatter.rb
Date Wed, 11 Aug 2010 08:24:42 GMT
Author: mfojtik
Date: Wed Aug 11 08:24:42 2010
New Revision: 984327

URL: http://svn.apache.org/viewvc?rev=984327&view=rev
Log:
Fixed command line client

Modified:
    incubator/deltacloud/trunk/client/bin/deltacloudc
    incubator/deltacloud/trunk/client/lib/deltacloud.rb
    incubator/deltacloud/trunk/client/lib/plain_formatter.rb

Modified: incubator/deltacloud/trunk/client/bin/deltacloudc
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/bin/deltacloudc?rev=984327&r1=984326&r2=984327&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/bin/deltacloudc (original)
+++ incubator/deltacloud/trunk/client/bin/deltacloudc Wed Aug 11 08:24:42 2010
@@ -20,8 +20,8 @@
 require 'rubygems'
 require 'optparse'
 require 'uri'
-require 'lib/deltacloud'
-require 'lib/plain_formatter'
+require 'lib/deltacloud.rb'
+require 'lib/plain_formatter.rb'
 
 include DeltaCloud::PlainFormatter
 
@@ -80,8 +80,7 @@ collections.delete(:instance_states)
 # with API documentation
 if options[:list] and options[:collection].nil?
   collections.each do |c|
-    doc = client.fetch_documentation(c.to_s)
-    puts sprintf("%-22s: %s", c.to_s[0, 22], doc[:description])
+    puts sprintf("%-22s", c.to_s[0, 22])
   end
   exit(0)
 end
@@ -89,9 +88,9 @@ end
 # If collection parameter is present and user requested list
 # print all operation defined for collection with API documentation
 if options[:list] and options[:collection]
-  doc = client.fetch_documentation(options[:collection])
-  doc[:operations].each do |c|
-    puts sprintf("%-20s: %s", c[:name][0, 20], c[:description])
+  doc = client.documentation(options[:collection])
+  doc.operations.each do |c|
+    puts sprintf("%-20s: %s", c.operation, c.description)
   end
   exit(0)
 end

Modified: incubator/deltacloud/trunk/client/lib/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/deltacloud.rb?rev=984327&r1=984326&r2=984327&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client/lib/deltacloud.rb Wed Aug 11 08:24:42 2010
@@ -328,7 +328,7 @@ module DeltaCloud
 
     # Check if specified collection have wanted feature
     def feature?(collection, name)
-      @feature.has_key?(collection) && @feature[collection].include?(name)
+      @features.has_key?(collection) && @features[collection].include?(name)
     end
 
     # List available instance states and transitions between them
@@ -364,7 +364,8 @@ module DeltaCloud
       request(:get, "/docs/#{collection}") do |body|
         document = Nokogiri::XML(body)
         if operation
-          data[:description] = document.xpath('/docs/collection/operations/operation[@name
= "'+operation+'"]/description').first
+          data[:operation] = operation
+          data[:description] = document.xpath('/docs/collection/operations/operation[@name
= "'+operation+'"]/description').first.text.strip
           return false unless data[:description]
           data[:params] = []
           (document/"/docs/collection/operations/operation[@name='#{operation}']/parameter").each
do |param|
@@ -376,9 +377,11 @@ module DeltaCloud
           end
         else
           data[:description] = (document/'/docs/collection/description').text
+          data[:collection] = collection
+          data[:operations] = (document/"/docs/collection/operations/operation").collect{
|o| o['name'] }
         end
       end
-      return Documentation.new(data)
+      return Documentation.new(self, data)
     end
 
     private
@@ -393,15 +396,23 @@ module DeltaCloud
   end
 
   class Documentation
-    attr_reader :description
-    attr_reader :params
 
-    def initialize(opts={})
-      @description = opts[:description]
+    attr_reader :api, :description, :params, :collection_operations
+    attr_reader :collection, :operation
+
+    def initialize(api, opts={})
+      @description, @api = opts[:description], api
       @params = parse_parameters(opts[:params]) if opts[:params]
+      @collection_operations = opts[:operations] if opts[:operations]
+      @collection = opts[:collection]
+      @operation = opts[:operation]
       self
     end
 
+    def operations
+      @collection_operations.collect { |o| api.documentation(@collection, o) }
+    end
+
     class OperationParameter
       attr_reader :name
       attr_reader :type

Modified: incubator/deltacloud/trunk/client/lib/plain_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/plain_formatter.rb?rev=984327&r1=984326&r2=984327&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/lib/plain_formatter.rb (original)
+++ incubator/deltacloud/trunk/client/lib/plain_formatter.rb Wed Aug 11 08:24:42 2010
@@ -77,7 +77,7 @@ module DeltaCloud
     end
 
     def format(obj)
-      object_name = obj.class.name.classify.gsub(/^DeltaCloud::/, '')
+      object_name = obj.class.name.classify.gsub(/^DeltaCloud::API::/, '')
       format_class = DeltaCloud::PlainFormatter::FormatObject.const_get(object_name)
       format_class.new(obj).format
     end



Mime
View raw message