File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
352351func (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
Original file line number Diff line number Diff line change @@ -159,13 +159,5 @@ func (o transformOptions) getContents() ([]byte, error) {
159159
160160// Save saves the CDI specification to the output file
161161func (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}
Original file line number Diff line number Diff line change @@ -86,11 +86,16 @@ func (t *transfromAsValidator) Validate(s *specs.Spec) error {
8686
8787// Save writes the spec to the specified path and overwrites the file if it exists.
8888func (s * spec ) Save (path string ) error {
89- pathWithExtension := s .ensureExtension (path )
89+ if pathWithExtension := s .ensureExtension (path ); pathWithExtension != "" {
90+ return producer .Save (s .Raw (), pathWithExtension ,
91+ s .producerOptions ()... ,
92+ )
93+ }
94+ if _ , err := s .WriteTo (os .Stdout ); err != nil {
95+ return fmt .Errorf ("failed to write CDI spec to STDOUT: %w" , err )
96+ }
9097
91- return producer .Save (s .Raw (), pathWithExtension ,
92- s .producerOptions ()... ,
93- )
98+ return nil
9499}
95100
96101// WriteTo writes the spec to the specified writer.
You can’t perform that action at this time.
0 commit comments