Arborist::CLI::

Tree

module
Extended With
Arborist::CLI::Subcommand

Command to dump the node tree of a running Arborist manager

Public Instance Methods

anchor
ack_description( node )

Return a description of the acknowledgement from the node.

# File lib/arborist/command/tree.rb, line 214
def ack_description( node )
        ack = node['ack'] or return '(no ack)'

        return " Acked by %s at %s%s: %s" % [
                ack['sender'],
                ack['time'],
                ack['via'] ? ' via ' + ack['via'] : '',
                ack['message']
        ]
end
anchor
build_path( nodes, root )

Given a sorted array of nodes, reorganize it for TTY::Tree.

# File lib/arborist/command/tree.rb, line 112
def build_path( nodes, root )
        children = []
        parent_node = nodes.shift
        return children unless parent_node

        if parent_node == root
                children << { node_description(parent_node) => build_tree(parent_node) }
        else
                children << { node_description(parent_node) => build_path(nodes, root) }
        end
        return children
end
anchor
build_tree( node )

Reorganize the node data to format used by TTY::Tree.

# File lib/arborist/command/tree.rb, line 100
def build_tree( node )
        return [] if node[ 'children' ].empty?

        children = []
        node[ 'children' ].each_value do |child|
                children << { node_description(child) => build_tree(child) }
        end
        return children
end
anchor
errors_description( node )

Return the errors from the specified node in a single line.

# File lib/arborist/command/tree.rb, line 188
def errors_description( node )
        errors = node['errors'] or return ''
        return '  ' + errors.map do |monid, error|
                "%s: %s" % [ monid, error ]
        end.join( '; ' )
end
anchor
fetch_parents( start_node )

Given a starting node, walk upwards through the tree until reaching the Arborist root node. Returns an array of nodes, sorted root down.

# File lib/arborist/command/tree.rb, line 129
def fetch_parents( start_node )
        client = Arborist::Client.instance
        path = [ start_node ]
        parent = start_node[ 'parent' ]
        while parent
                parent_node = client.fetch_node( parent )
                path << parent_node
                parent = parent_node[ 'parent' ]
        end
        return path.reverse
end
anchor
node_description( node )

Return a description of the specified node.

# File lib/arborist/command/tree.rb, line 143
def node_description( node )
        desc = ""

        case node['type']
        when 'root'
                desc << "%s" % [ hl.bold.bright_blue(node['type']) ]
        else
                desc << highlight_string( node['identifier'] )
                desc << " %s" % [ hl.dark.white(node['type']) ]
        end

        desc << " [%s]" % [ node['description'] ] unless
                !node['description'] || node['description'].empty?
        desc << " (%s)" % [ status_description(node) ]

        child_count = node[ 'children' ].length
        desc << " [%d child node%s" % [
                child_count, child_count == 1 ? ']' : 's]'
        ] unless child_count.zero?

        case node['status']
        when 'down'
                desc << errors_description( node )
        when 'warn'
                desc << warnings_description( node )
        when 'quieted'
                desc << quieted_reasons_description( node )
        when 'acked'
                desc << ack_description( node )
                desc << "; was: "
                desc << errors_description( node )
        end

        return desc
end
anchor
quieted_reasons_description( node )

Return the quieted reasons from the specified node in a single line.

# File lib/arborist/command/tree.rb, line 205
def quieted_reasons_description( node )
        reasons = node['quieted_reasons'] or return ''
        return '  ' + reasons.map do |depname, reason|
                "%s: %s" % [ depname, reason ]
        end.join( '; ' )
end
anchor
status_description( node )

Return a more colorful description of the status of the given node.

# File lib/arborist/command/tree.rb, line 181
def status_description( node )
        status = node['status'] or return '-'
        return hl.decorate( status, status.to_sym ) rescue status
end
anchor
warnings_description( node )

Return the warnings from the specified node in a single line.

# File lib/arborist/command/tree.rb, line 196
def warnings_description( node )
        warnings = node['warnings'] or return ''
        return '  ' + warnings.map do |monid, error|
                "%s: %s" % [ monid, error ]
        end.join( '; ' )
end