Output YAML separator

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2022-11-02 14:59:04 +01:00
parent 3d2328bdfd
commit c793fc27d8

View File

@ -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 {