Skip to content

Commit 0620366

Browse files
committed
refactor: Consolidate handling of output to stdout
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent f2fdcc0 commit 0620366

3 files changed

Lines changed: 5 additions & 19 deletions

File tree

cmd/nvidia-ctk/cdi/generate/generate.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"os"
2423
"path/filepath"
2524
"slices"
2625
"strings"
@@ -352,14 +351,6 @@ type generatedSpecs struct {
352351
func (g *generatedSpecs) Save(filename string) error {
353352
filename = g.updateFilename(filename)
354353

355-
if filename == "" {
356-
_, err := g.WriteTo(os.Stdout)
357-
if err != nil {
358-
return fmt.Errorf("failed to write CDI spec to STDOUT: %v", err)
359-
}
360-
return nil
361-
}
362-
363354
return g.Interface.Save(filename)
364355
}
365356

cmd/nvidia-ctk/cdi/transform/root/root.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,5 @@ func (o transformOptions) getContents() ([]byte, error) {
159159

160160
// Save saves the CDI specification to the output file
161161
func (o transformOptions) Save(s spec.Interface) error {
162-
if o.output == "" {
163-
_, err := s.WriteTo(os.Stdout)
164-
if err != nil {
165-
return fmt.Errorf("failed to write CDI spec to STDOUT: %v", err)
166-
}
167-
return nil
168-
}
169-
170162
return s.Save(o.output)
171163
}

pkg/nvcdi/spec/spec.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ func (s *spec) Save(path string) error {
9191
s.producerOptions()...,
9292
)
9393
}
94-
_, err := s.WriteTo(os.Stdout)
95-
return err
94+
if _, err := s.WriteTo(os.Stdout); err != nil {
95+
fmt.Errorf("failed to write CDI spec to STDOUT: %w", err)
96+
}
97+
98+
return nil
9699
}
97100

98101
// WriteTo writes the spec to the specified writer.

0 commit comments

Comments
 (0)