Files
eb3f08fa75 Redo tempo-cli with basic command structure and improvements (#385)
* Convert tempo-cli to kong cli parser, add some basic command structure

* Rename commands to 'list block' 'list bucket'

* Update list bucket command to put index analysis behind --load-index flag, print results more dynamically

* Rename list bucket to list blocks, improve parameter descriptions and locations

* vendor-check fixes

* ignore tempo-cli binary

* Fix lint re: unused values

* Add tempo-cli section to docs website.  Update readme.md to point to docs for tempo-cli

* Apply suggestions from code review

Co-authored-by: achatterjee-grafana <[email protected]>

* Apply suggestions from code review

* Update changelog

* Wording tweak based on feedback

Co-authored-by: achatterjee-grafana <[email protected]>
2020-12-03 14:29:15 -05:00

59 lines
1.2 KiB
Go

package kong
import (
"fmt"
)
// Next should be called by Visitor to proceed with the walk.
//
// The walk will terminate if "err" is non-nil.
type Next func(err error) error
// Visitor can be used to walk all nodes in the model.
type Visitor func(node Visitable, next Next) error
// Visit all nodes.
func Visit(node Visitable, visitor Visitor) error {
return visitor(node, func(err error) error {
if err != nil {
return err
}
switch node := node.(type) {
case *Application:
return visitNodeChildren(node.Node, visitor)
case *Node:
return visitNodeChildren(node, visitor)
case *Value:
case *Flag:
return Visit(node.Value, visitor)
default:
panic(fmt.Sprintf("unsupported node type %T", node))
}
return nil
})
}
func visitNodeChildren(node *Node, visitor Visitor) error {
if node.Argument != nil {
if err := Visit(node.Argument, visitor); err != nil {
return err
}
}
for _, flag := range node.Flags {
if err := Visit(flag, visitor); err != nil {
return err
}
}
for _, pos := range node.Positional {
if err := Visit(pos, visitor); err != nil {
return err
}
}
for _, child := range node.Children {
if err := Visit(child, visitor); err != nil {
return err
}
}
return nil
}