]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
leap inspect now works with all .json files
authorelijah <elijah@riseup.net>
Sat, 9 Feb 2013 05:47:45 +0000 (21:47 -0800)
committerelijah <elijah@riseup.net>
Sat, 9 Feb 2013 05:47:45 +0000 (21:47 -0800)
lib/leap_cli/commands/inspect.rb

index 1856ad6450c0a60d0116930cfdf0456934442e56..97d0b2086322494beeb9940c5e1d7b542975fe26 100644 (file)
@@ -30,16 +30,39 @@ module LeapCli; module Commands
       log 2, "file is of type '#{ftype}'"
       if FTYPE_MAP[ftype]
         FTYPE_MAP[ftype]
-      elsif ftype == "ASCII text"
-        nil
+      elsif File.extname(object) == ".json"
+        full_path = File.expand_path(object, Dir.pwd)
+        if path_match?(:node_config, full_path)
+          :inspect_node
+        elsif path_match?(:service_config, full_path)
+          :inspect_service
+        elsif path_match?(:tag_config, full_path)
+          :inspect_tag
+        elsif path_match?(:provider_config, full_path)
+          :inspect_provider
+        elsif path_match?(:common_config, full_path)
+          :inspect_common
+        end
       end
     elsif manager.nodes[object]
       :inspect_node
+    elsif manager.services[object]
+      :inspect_service
+    elsif manager.tags[object]
+      :inspect_tag
+    elsif object == "common"
+      :inspect_common
+    elsif object == "provider"
+      :inspect_provider
     else
       nil
     end
   end
 
+  #
+  # inspectors
+  #
+
   def inspect_x509_key(file_path, options)
     assert_bin! 'openssl'
     puts assert_run! 'openssl rsa -in %s -text -check' % file_path
@@ -59,9 +82,38 @@ module LeapCli; module Commands
   #def inspect_ssh_pub_key(file_path)
   #end
 
-  def inspect_node(node_name, options)
-    node = manager.nodes[node_name]
-    puts node.dump_json
+  def inspect_node(arg, options)
+    inspect_json(arg, options) {|name| manager.nodes[name] }
+  end
+
+  def inspect_service(arg, options)
+    inspect_json(arg, options) {|name| manager.services[name] }
+  end
+
+  def inspect_tag(arg, options)
+    inspect_json(arg, options) {|name| manager.tags[name] }
+  end
+
+  def inspect_provider(arg, options)
+    inspect_json(arg, options) {|name| manager.provider }
+  end
+
+  def inspect_common(arg, options)
+    inspect_json(arg, options) {|name| manager.common }
+  end
+
+  #
+  # helpers
+  #
+
+  def inspect_json(arg, options)
+    name = File.basename(arg).sub(/\.json$/, '')
+    config = yield name
+    puts config.dump_json
+  end
+
+  def path_match?(path_symbol, path)
+    Dir.glob(Path.named_path([path_symbol, '*'])).include?(path)
   end
 
 end; end