Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions alpha/veneer/semver/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ func buildBundleList(bundles *[]semverVeneerBundleEntry, dict *map[string]struct
}
}

func readFile(data io.Reader) (*semverVeneer, error) {
fileData, err := io.ReadAll(data)
func readFile(reader io.Reader) (*semverVeneer, error) {
data, err := io.ReadAll(reader)
if err != nil {
return nil, err
}
Expand All @@ -140,7 +140,7 @@ func readFile(data io.Reader) (*semverVeneer, error) {
GenerateMinorChannels: true,
AvoidSkipPatch: false,
}
if err := yaml.Unmarshal(fileData, &sv); err != nil {
if err := yaml.Unmarshal(data, &sv); err != nil {
return nil, err
}
return &sv, nil
Expand Down
28 changes: 13 additions & 15 deletions cmd/opm/alpha/veneer/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,13 @@ func newSemverCmd() *cobra.Command {
Long: "Generate a file-based catalog from a single 'semver veneer' file \nWhen FILE is '-' or not provided, the veneer is read from standard input",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var (
data io.Reader
err error
)

// Handle different input argument types
if len(args) == 0 || args[0] == "-" {
// When no arguments or "-" is passed to the command,
// assume input is coming from stdin
data = cmd.InOrStdin()
} else {
// Otherwise open the file passed to the command
data, err = os.Open(args[0])
if err != nil {
return err
}
// When no arguments or "-" is passed to the command,
// assume input is coming from stdin
// Otherwise open the file passed to the command
data, err := openFileOrReadStdin(cmd, args)
if err != nil {
return err
}

var write func(declcfg.DeclarativeConfig, io.Writer) error
Expand Down Expand Up @@ -86,3 +77,10 @@ func newSemverCmd() *cobra.Command {
cmd.Flags().StringVarP(&output, "output", "o", "json", "Output format (json|yaml|mermaid)")
return cmd
}

func openFileOrReadStdin(cmd *cobra.Command, args []string) (io.Reader, error) {
if len(args) == 0 || args[0] == "-" {
return cmd.InOrStdin(), nil
}
return os.Open(args[0])
}