diff --git a/cmd/nvidia-ctk/cdi/generate/generate.go b/cmd/nvidia-ctk/cdi/generate/generate.go index 5b59de78..c3992d5b 100644 --- a/cmd/nvidia-ctk/cdi/generate/generate.go +++ b/cmd/nvidia-ctk/cdi/generate/generate.go @@ -122,7 +122,7 @@ func (m command) run(c *cli.Context, cfg *config) error { } } - _, err = outputTo.Write(data) + err = writeToOutput(cfg.jsonMode, data, outputTo) if err != nil { return fmt.Errorf("failed to write output: %v", err) } @@ -130,6 +130,22 @@ func (m command) run(c *cli.Context, cfg *config) error { return nil } +func writeToOutput(jsonMode bool, data []byte, output io.Writer) error { + if !jsonMode { + _, err := output.Write([]byte("---\n")) + if err != nil { + return fmt.Errorf("failed to write YAML separator: %v", err) + } + + } + _, err := output.Write(data) + if err != nil { + return fmt.Errorf("failed to write data: %v", err) + } + + return nil +} + func (m command) generateSpec() (*specs.Spec, error) { nvmllib := nvml.New() if r := nvmllib.Init(); r != nvml.SUCCESS {