# -*- encoding: utf-8 -*- require 'webgen/cli/utils' module Webgen module CLI # The CLI command for showing the node tree. class ShowTreeCommand < CmdParse::Command def initialize # :nodoc: super('tree', false, false, true) self.short_desc = 'Show the node tree' self.description = Utils.format_command_desc(< b.alcn}.map do |node| sub = collect_data(node.children, selector) if sub.length > 0 || ((selector.nil? || node.lcn.include?(selector)) && ((!node.is_fragment? || @show_fragments) && (!node['passive'] || commandparser.website.ext.item_tracker.node_referenced?(node)))) data = [@use_alcn ? node.alcn : node.lcn] data << (@meta_info ? node.meta_info.map {|k,v| "#{k}: #{v.inspect}"} : []) data << sub data else nil end end.compact end private :collect_data def print_tree(data, indent = '', selector) data.each do |name, info, children| puts("#{indent}#{Utils.light(Utils.blue(name))}") info.each {|i| puts("#{indent} #{i}")} if info.length > 0 && (selector.nil? || name.include?(selector)) print_tree(children, indent + ' ', selector) end end private :print_tree end end end