]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
added --print <attr> to "leap list" command.
authorelijah <elijah@riseup.net>
Sun, 4 Nov 2012 05:43:22 +0000 (22:43 -0700)
committerelijah <elijah@riseup.net>
Sun, 4 Nov 2012 05:43:22 +0000 (22:43 -0700)
bin/leap
lib/leap_cli/commands/list.rb
lib/leap_cli/config/manager.rb

index 45f64fb2a9b3f8f66e0c36796d233ffa82723735..2749fc86aed398c3b3aa4c908703972f0fd95579 100755 (executable)
--- a/bin/leap
+++ b/bin/leap
@@ -42,11 +42,12 @@ module LeapCli::Commands
   # delegate highline methods to make them available to sub-commands
   #
   @terminal = HighLine.new
-  def_delegator :@terminal, :ask, 'self.ask'
-  def_delegator :@terminal, :agree, 'self.agree'
+  def_delegator :@terminal, :ask,    'self.ask'
+  def_delegator :@terminal, :agree,  'self.agree'
   def_delegator :@terminal, :choose, 'self.choose'
-  def_delegator :@terminal, :say, 'self.say'
-  def_delegator :@terminal, :color, 'self.color'
+  def_delegator :@terminal, :say,    'self.say'
+  def_delegator :@terminal, :color,  'self.color'
+  def_delegator :@terminal, :list,   'self.list'
 
   #
   # make config manager available as 'manager'
index 0f1c96e3f2b61075b5368d517ba1e1fc5b360fb0..033c95f3139d14b0b8773d16c45568cbb732e24e 100644 (file)
@@ -1,6 +1,38 @@
 module LeapCli
   module Commands
 
+    desc 'List nodes and their classifications'
+    long_desc 'Prints out a listing of nodes, services, or tags.'
+    arg_name 'filter'
+    command :list do |c|
+      c.flag 'print', :desc => 'What attributes to print (optional)'
+      c.action do |global_options,options,args|
+        if options['print']
+          print_node_properties(manager.filter(args), options['print'])
+        else
+          if args.any?
+            print_config_table(:nodes, manager.filter(args))
+          else
+            print_config_table(:services, manager.services)
+            print_config_table(:tags, manager.tags)
+            print_config_table(:nodes, manager.nodes)
+          end
+        end
+      end
+    end
+
+    private
+
+    def self.print_node_properties(nodes, properties)
+      node_list = manager.nodes
+      properties = properties.split(',')
+      max_width = nodes.keys.inject(0) {|max,i| [i.size,max].max}
+      nodes.keys.sort.each do |node_name|
+        value = properties.collect{|prop| node_list[node_name][prop]}.join(', ')
+        printf("%#{max_width}s   %s\n", node_name, value)
+      end
+    end
+
     def self.print_config_table(type, object_list)
       style = {:border_x => '-', :border_y => ':', :border_i => '-', :width => 60}
 
@@ -44,20 +76,5 @@ module LeapCli
       end
     end
 
-    desc 'List nodes and their classifications'
-    long_desc 'Prints out a listing of nodes, services, or tags.'
-    arg_name 'filter'
-    command :list do |c|
-      c.action do |global_options,options,args|
-        if args.any?
-          print_config_table(:nodes, manager.filter(args))
-        else
-          print_config_table(:services, manager.services)
-          print_config_table(:tags, manager.tags)
-          print_config_table(:nodes, manager.nodes)
-        end
-      end
-    end
-
   end
 end
index 72958ddca73eed8ebe87ba0e69e6afcf38a81749..2eda7a49f008f1e7b08a92ee93f42a2f43f15fda 100644 (file)
@@ -211,6 +211,8 @@ module LeapCli
           service.node_list
         elsif tag = self.tags[name]
           tag.node_list
+        else
+          {}
         end
       end