-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline.go
More file actions
43 lines (36 loc) · 1.14 KB
/
Copy pathpipeline.go
File metadata and controls
43 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"io"
"sigs.k8s.io/kustomize/kyaml/kio"
"github.com/tobiash/k8q/internal/prompt"
k8qdiff "github.com/tobiash/k8q/pkg/diff"
"github.com/tobiash/k8q/pkg/engine"
)
// runPipeline executes the YAML pipeline with automatic field reordering
// and optional colorization. It appends ReorderFilter to the filter chain
// and wraps the output writer for ANSI colors when writing to a terminal.
func runPipeline(g *Globals, in io.Reader, filters ...kio.Filter) error {
// Always reorder fields for consistent output.
allFilters := append(filters, kio.FilterFunc(k8qdiff.ReorderFilter()))
// Wrap output for colorization when appropriate.
out := g.Out
if cw := maybeColorWriter(g); cw != nil {
out = cw
defer func() { _ = cw.Close() }()
}
return engine.Pipeline(in, out, allFilters...)
}
// maybeColorWriter returns a ColorWriter if colorization should be active,
// or nil if output should pass through unmodified.
func maybeColorWriter(g *Globals) *prompt.ColorWriter {
if g.NoColor {
return nil
}
if prompt.NoColorEnv() {
return nil
}
if !prompt.IsTerminal(g.Out) {
return nil
}
return prompt.NewColorWriter(g.Out, true)
}