diff options
author | elijah <elijah@riseup.net> | 2012-10-09 00:05:44 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2012-10-09 00:05:44 -0700 |
commit | 73b126976ad7843eb47a84944cf191bf05b14216 (patch) | |
tree | 918656f8d7c637e8c7a8f0c010eff55bfd98ae1b /lib/leap_cli/commands/list.rb | |
parent | 578ac2f5dc7432317d7a022bed9d869ab89ee45c (diff) | |
download | leap_cli-73b126976ad7843eb47a84944cf191bf05b14216.tar.gz leap_cli-73b126976ad7843eb47a84944cf191bf05b14216.tar.bz2 |
fixed paths
Diffstat (limited to 'lib/leap_cli/commands/list.rb')
-rw-r--r-- | lib/leap_cli/commands/list.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/leap_cli/commands/list.rb b/lib/leap_cli/commands/list.rb new file mode 100644 index 0000000..a186049 --- /dev/null +++ b/lib/leap_cli/commands/list.rb @@ -0,0 +1,61 @@ +module LeapCli + module Commands + + def self.print_config_table(type, config_list) + style = {:border_x => '-', :border_y => ':', :border_i => '-', :width => 60} + + if type == :services + t = table do + self.style = style + self.headings = ['SERVICE', 'NODES'] + list = config_list.keys.sort + list.each do |name| + add_row [name, config_list[name].nodes.keys.join(', ')] + add_separator unless name == list.last + end + end + puts t + puts "\n\n" + elsif type == :tags + t = table do + self.style = style + self.headings = ['TAG', 'NODES'] + list = config_list.keys.sort + list.each do |name| + add_row [name, config_list[name].nodes.keys.join(', ')] + add_separator unless name == list.last + end + end + puts t + puts "\n\n" + elsif type == :nodes + t = table do + self.style = style + self.headings = ['NODE', 'SERVICES', 'TAGS'] + list = config_list.keys.sort + list.each do |name| + add_row [name, config_list[name].services.to_a.join(', '), config_list[name].tags.to_a.join(', ')] + add_separator unless name == list.last + end + end + puts t + 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, ConfigManager.filter(args)) + else + print_config_table(:services, ConfigManager.services) + print_config_table(:tags, ConfigManager.tags) + print_config_table(:nodes, ConfigManager.nodes) + end + end + end + + end +end |