aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands/list.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/leap_cli/commands/list.rb')
-rw-r--r--lib/leap_cli/commands/list.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/leap_cli/commands/list.rb b/lib/leap_cli/commands/list.rb
index 5b84113..b8d7739 100644
--- a/lib/leap_cli/commands/list.rb
+++ b/lib/leap_cli/commands/list.rb
@@ -15,24 +15,25 @@ module LeapCli; module Commands
c.flag 'print', :desc => 'What attributes to print (optional)'
c.switch 'disabled', :desc => 'Include disabled nodes in the list.', :negatable => false
c.action do |global_options,options,args|
+ # don't rely on default manager(), because we want to pass custom options to load()
+ manager = LeapCli::Config::Manager.new
if global_options[:color]
colors = ['cyan', 'white']
else
colors = [nil, nil]
end
puts
- if options['disabled']
- manager.load(:include_disabled => true) # reload, with disabled nodes
- end
+ manager.load(:include_disabled => options['disabled'], :continue_on_error => true)
if options['print']
print_node_properties(manager.filter(args), options['print'])
else
if args.any?
NodeTable.new(manager.filter(args), colors).run
else
- TagTable.new('SERVICES', manager.services, colors).run
- TagTable.new('TAGS', manager.tags, colors).run
- NodeTable.new(manager.nodes, colors).run
+ environment = LeapCli.leapfile.environment || '_all_'
+ TagTable.new('SERVICES', manager.env(environment).services, colors).run
+ TagTable.new('TAGS', manager.env(environment).tags, colors).run
+ NodeTable.new(manager.filter(), colors).run
end
end
end
@@ -41,11 +42,9 @@ module LeapCli; module Commands
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.each_node do |node|
- node.evaluate
value = properties.collect{|prop|
if node[prop].nil?
"null"
@@ -68,7 +67,7 @@ module LeapCli; module Commands
@colors = colors
end
def run
- tags = @tag_list.keys.sort
+ tags = @tag_list.keys.select{|tag| tag !~ /^_/}.sort # sorted list of tags, excluding _partials
max_width = [20, (tags+[@heading]).inject(0) {|max,i| [i.size,max].max}].max
table :border => false do
row :color => @colors[0] do
@@ -76,6 +75,7 @@ module LeapCli; module Commands
column "NODES", :width => HighLine::SystemExtensions.terminal_size.first - max_width - 2, :padding => 2
end
tags.each do |tag|
+ next if @tag_list[tag].node_list.empty?
row :color => @colors[1] do
column tag
column @tag_list[tag].node_list.keys.sort.join(', ')