graph

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCycleError

func NewCycleError(cycle []NodeID) *errors.DependencyError

NewCycleError creates a DependencyError for circular dependencies. The cycle should include the starting node at both the beginning and end.

Types

type Edge

type Edge struct {
	From NodeID // Dependent node
	To   NodeID // Dependency node
}

Edge represents a dependency edge in the graph.

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter exports plan data in various formats.

func NewExporter

func NewExporter(layers []Layer, resourceInfo map[NodeID]ResourceInfo, edges []Edge) *Exporter

NewExporter creates a new Exporter.

func (*Exporter) BuildOutput

func (e *Exporter) BuildOutput() PlanOutput

BuildOutput builds the PlanOutput structure.

func (*Exporter) ExportJSON

func (e *Exporter) ExportJSON(w io.Writer) error

ExportJSON writes the plan as JSON.

func (*Exporter) ExportYAML

func (e *Exporter) ExportYAML(w io.Writer) error

ExportYAML writes the plan as YAML.

type Layer

type Layer struct {
	Nodes []*Node
}

Layer represents a group of nodes that can be executed in parallel.

type Node

type Node struct {
	ID   NodeID        // Kind/Name format (e.g., "Runtime/go", "Tool/ripgrep")
	Kind resource.Kind // Resource kind
	Name string        // Resource name
}

Node represents a resource in the dependency graph.

type NodeID

type NodeID string

NodeID is a unique identifier for a node in the dependency graph.

func NewNodeID

func NewNodeID(kind resource.Kind, name string) NodeID

NewNodeID creates a unique node identifier from kind and name.

func (NodeID) String

func (id NodeID) String() string

String returns the string representation of the NodeID.

type PlanLayer

type PlanLayer struct {
	Index     int      `json:"index" yaml:"index"`
	Resources []string `json:"resources" yaml:"resources"`
}

PlanLayer represents an execution layer in the plan output.

type PlanOutput

type PlanOutput struct {
	Resources []PlanResource `json:"resources" yaml:"resources"`
	Layers    []PlanLayer    `json:"layers" yaml:"layers"`
	Summary   PlanSummary    `json:"summary" yaml:"summary"`
}

PlanOutput represents the structured output of a plan.

type PlanResource

type PlanResource struct {
	Kind         resource.Kind       `json:"kind" yaml:"kind"`
	Name         string              `json:"name" yaml:"name"`
	Version      string              `json:"version,omitempty" yaml:"version,omitempty"`
	Action       resource.ActionType `json:"action" yaml:"action"`
	Layer        int                 `json:"layer" yaml:"layer"`
	Dependencies []string            `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
}

PlanResource represents a resource in the plan output.

type PlanSummary

type PlanSummary struct {
	Total     int `json:"total" yaml:"total"`
	Layers    int `json:"layers" yaml:"layers"`
	Install   int `json:"install" yaml:"install"`
	Upgrade   int `json:"upgrade" yaml:"upgrade"`
	Reinstall int `json:"reinstall" yaml:"reinstall"`
	Remove    int `json:"remove" yaml:"remove"`
	NoChange  int `json:"noChange" yaml:"noChange"`
}

PlanSummary represents the summary of actions in the plan.

type Resolver

type Resolver interface {
	// AddResource adds a resource and its dependencies to the graph.
	AddResource(res resource.Resource)

	// Resolve validates the graph and returns execution layers.
	// Returns an error if circular dependencies are detected.
	Resolve() ([]Layer, error)

	// Validate checks for circular dependencies without computing the full sort.
	Validate() error

	// NodeCount returns the number of nodes in the graph.
	NodeCount() int

	// EdgeCount returns the number of edges in the graph.
	EdgeCount() int

	// GetEdges returns all edges in the graph.
	GetEdges() []Edge

	// GetNodes returns all nodes in the graph.
	GetNodes() []*Node
}

Resolver defines the interface for dependency resolution.

func NewResolver

func NewResolver() Resolver

NewResolver creates a new dependency resolver.

type ResourceInfo

type ResourceInfo struct {
	Kind    resource.Kind
	Name    string
	Version string
	Action  resource.ActionType
}

ResourceInfo holds information about a resource for display.

type TreePrinter

type TreePrinter struct {
	// contains filtered or unexported fields
}

TreePrinter prints dependency graphs as ASCII trees with colors.

func NewTreePrinter

func NewTreePrinter(w io.Writer, noColor bool) *TreePrinter

NewTreePrinter creates a new TreePrinter.

func (*TreePrinter) PrintLayers

func (p *TreePrinter) PrintLayers(layers []Layer, resourceInfo map[NodeID]ResourceInfo)

PrintLayers prints the execution layers.

func (*TreePrinter) PrintSummary

func (p *TreePrinter) PrintSummary(resourceInfo map[NodeID]ResourceInfo)

PrintSummary prints the action summary.

func (*TreePrinter) PrintTree

func (p *TreePrinter) PrintTree(resolver Resolver, resourceInfo map[NodeID]ResourceInfo)

PrintTree prints the dependency graph as an ASCII tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL