summaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-11-03 22:43:22 -0700
committerelijah <elijah@riseup.net>2012-11-03 22:43:22 -0700
commiteab3a872de04dfaa197cbe71ab34472dcb4fd7e5 (patch)
tree7430c5c408e6ebfe24ffe7e98bcb78ac6e2f5c89 /lib/leap_cli/commands
parent6c98d65096bb31fa231b6f65de4b1a9b5a7d90ef (diff)
added --print <attr> to "leap list" command.
Diffstat (limited to 'lib/leap_cli/commands')
-rw-r--r--lib/leap_cli/commands/list.rb47
1 files changed, 32 insertions, 15 deletions
diff --git a/lib/leap_cli/commands/list.rb b/lib/leap_cli/commands/list.rb
index 0f1c96e..033c95f 100644
--- a/lib/leap_cli/commands/list.rb
+++ b/lib/leap_cli/commands/list.rb
@@ -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