column

package
v1.229.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildColumnFuncMap

func BuildColumnFuncMap() template.FuncMap

BuildColumnFuncMap returns template functions for column templates. These functions are safe for use in column value extraction.

func EnsureSection

func EnsureSection(sections []string, name string) []string

EnsureSection returns sections with name added if not already present, preserving a non-nil result: an empty (but non-nil) input slice stays non-nil, matching isSectionRequired's contract that a non-nil filter -- even an empty one -- means "gating is active," never "no filter".

Callers use this to fold in a section their row-extraction pipeline always needs regardless of column selection (e.g. `metadata`, which list components/instances always read for enabled/locked/tags/labels/status derivation -- see cmd/list/components.go and pkg/list/list_instances.go) into the result of RequiredSections.

func RequiredSections

func RequiredSections(columns []Config) (sections []string, ok bool)

RequiredSections statically determines which top-level Atmos component sections (vars, settings, metadata, env, backend) the given column templates actually reference, by walking each column's parsed Go-template AST for field references (see pkg/template.ExtractFieldRefs) whose first path segment names a section.

Returns ok=false whenever any column can't be statically resolved this way: a catch-all `.raw` reference (which exposes the entire row, including every section), a bare root reference like `{{ . }}` (which likewise exposes the entire row — see pkg/template.HasRootReference), a `range`/`with` block (which rebinds "." — see pkg/template.HasDynamicScope), an unparseable template, or any top-level field this function does not recognize as either section-backed or derived. Callers MUST treat ok=false as "pass nil / evaluate everything": under-computing the required set is far worse than over-computing it, since a displayed column would then show raw, unevaluated text instead of falling back cleanly to full evaluation.

A true result with an empty (non-nil) `sections` slice is a real, meaningful answer — "no section is required" — and is distinct from a nil slice. Callers MUST preserve that distinction (e.g. by passing the returned slice through unchanged, never coalescing an empty result to nil) since downstream evaluation-gating treats nil as "no filter" (see internal/exec's isSectionRequired).

Types

type Config

type Config struct {
	Name  string `yaml:"name" json:"name" mapstructure:"name"`    // Display header
	Value string `yaml:"value" json:"value" mapstructure:"value"` // Go template string
	Width int    `yaml:"width" json:"width" mapstructure:"width"` // Optional width override
}

Config defines a column with name, Go template for value extraction, and optional width.

type Selector

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

Selector manages column extraction with template evaluation. Templates are evaluated during Extract(), not at config load time.

func NewSelector

func NewSelector(configs []Config, funcMap template.FuncMap) (*Selector, error)

NewSelector creates a selector with Go template support. Templates are pre-parsed for performance but NOT evaluated until Extract(). FuncMap should include functions like atmos.Component, toString, get, etc.

func (*Selector) Extract

func (s *Selector) Extract(data []map[string]any) (headers []string, rows [][]string, err error)

Extract evaluates templates against data and returns table rows. ⚠️ CRITICAL: This is where Go template evaluation happens (NOT at config load). Each row is processed with its full data as template context.

func (*Selector) Headers

func (s *Selector) Headers() []string

Headers returns the header row based on selected columns.

func (*Selector) Select

func (s *Selector) Select(columnNames []string) error

Select restricts which columns to display. Pass nil or empty slice to display all columns.

type TemplateContext

type TemplateContext struct {
	// Standard fields available in all templates
	AtmosComponent     string `json:"atmos_component"`
	AtmosStack         string `json:"atmos_stack"`
	AtmosComponentType string `json:"atmos_component_type"`

	// Component configuration
	Vars     map[string]any `json:"vars"`
	Settings map[string]any `json:"settings"`
	Metadata map[string]any `json:"metadata"`
	Env      map[string]any `json:"env"`

	// Flags
	Enabled  bool `json:"enabled"`
	Locked   bool `json:"locked"`
	Abstract bool `json:"abstract"`

	// Full raw data for advanced templates
	Raw map[string]any `json:"raw"`
}

TemplateContext provides data available to column templates during evaluation.

Jump to

Keyboard shortcuts

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