mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-18 08:09:58 +00:00
Allow YAML printer to separate multiple printed objects
This commit is contained in:
parent
39c20fdcf1
commit
6e8012bac9
@ -68,7 +68,10 @@ func (p *JSONPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
|
|||||||
// YAMLPrinter is an implementation of ResourcePrinter which outputs an object as YAML.
|
// YAMLPrinter is an implementation of ResourcePrinter which outputs an object as YAML.
|
||||||
// The input object is assumed to be in the internal version of an API and is converted
|
// The input object is assumed to be in the internal version of an API and is converted
|
||||||
// to the given version first.
|
// to the given version first.
|
||||||
type YAMLPrinter struct{}
|
// If PrintObj() is called multiple times, objects are separated with a '---' separator.
|
||||||
|
type YAMLPrinter struct {
|
||||||
|
printCount int64
|
||||||
|
}
|
||||||
|
|
||||||
// PrintObj prints the data as YAML.
|
// PrintObj prints the data as YAML.
|
||||||
func (p *YAMLPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
|
func (p *YAMLPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
|
||||||
@ -79,6 +82,13 @@ func (p *YAMLPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
|
|||||||
return fmt.Errorf(InternalObjectPrinterErr)
|
return fmt.Errorf(InternalObjectPrinterErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count := atomic.AddInt64(&p.printCount, 1)
|
||||||
|
if count > 1 {
|
||||||
|
if _, err := w.Write([]byte("---\n")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch obj := obj.(type) {
|
switch obj := obj.(type) {
|
||||||
case *runtime.Unknown:
|
case *runtime.Unknown:
|
||||||
data, err := yaml.JSONToYAML(obj.Raw)
|
data, err := yaml.JSONToYAML(obj.Raw)
|
||||||
|
Loading…
Reference in New Issue
Block a user