Files
nomad/vendor/github.com/mitchellh/go-glint/tree.go
Isabel Suchanek 0edda116ad cli: add monitor flag to deployment status
Adding '-verbose' will print out the allocation information for the
deployment. This also changes the job run command so that it now blocks
until deployment is complete and adds timestamps to the output so that
it's more in line with the output of node drain.

This uses glint to print in place in running in a tty. Because glint
doesn't yet support cmd/powershell, Windows workflows use a different
library to print in place, which results in slightly different
formatting: 1) different margins, and 2) no spinner indicating
deployment in progress.
2021-06-09 16:18:45 -07:00

88 lines
1.6 KiB
Go

package glint
import (
"context"
"github.com/mitchellh/go-glint/flex"
)
func tree(
ctx context.Context,
parent *flex.Node,
c Component,
finalize bool,
) {
// Don't do anything with no component
if c == nil {
return
}
// Fragments don't create a node
switch c := c.(type) {
case *contextComponent:
for i := 0; i < len(c.pairs); i += 2 {
ctx = context.WithValue(ctx, c.pairs[i], c.pairs[i+1])
}
tree(ctx, parent, c.inner, finalize)
return
case *fragmentComponent:
for _, c := range c.List {
tree(ctx, parent, c, finalize)
}
return
}
// Setup our node
node := flex.NewNodeWithConfig(parent.Config)
parent.InsertChild(node, len(parent.Children))
// Setup our default context
parentCtx := &parentContext{C: c}
node.Context = parentCtx
// Check if we're finalized and note it
if _, ok := c.(*finalizedComponent); ok {
parentCtx.Finalized = true
}
// Finalize
if finalize {
if c, ok := c.(ComponentFinalizer); ok {
c.Finalize()
}
}
// Setup a custom layout
if c, ok := c.(componentLayout); ok {
c.Layout().Apply(node)
}
switch c := c.(type) {
case *TextComponent:
node.Context = &TextNodeContext{C: c, Context: ctx}
node.StyleSetFlexShrink(1)
node.StyleSetFlexGrow(0)
node.StyleSetFlexDirection(flex.FlexDirectionRow)
node.SetMeasureFunc(MeasureTextNode)
default:
// If this is not terminal then we nest.
tree(ctx, node, c.Body(ctx), finalize)
}
}
type parentContext struct {
C Component
Finalized bool
}
func (c *parentContext) Component() Component { return c.C }
type treeContext interface {
Component() Component
}