Skip to content

Commit 856f0bc

Browse files
authored
Addressing additional feedback from PR 1015 (#1017)
Signed-off-by: Catherine Chan-Tse <[email protected]> Signed-off-by: Catherine Chan-Tse <[email protected]>
1 parent 52e35f0 commit 856f0bc

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

alpha/veneer/semver/semver.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ func buildBundleList(bundles *[]semverVeneerBundleEntry, dict *map[string]struct
128128
}
129129
}
130130

131-
func readFile(data io.Reader) (*semverVeneer, error) {
132-
fileData, err := io.ReadAll(data)
131+
func readFile(reader io.Reader) (*semverVeneer, error) {
132+
data, err := io.ReadAll(reader)
133133
if err != nil {
134134
return nil, err
135135
}
@@ -140,7 +140,7 @@ func readFile(data io.Reader) (*semverVeneer, error) {
140140
GenerateMinorChannels: true,
141141
AvoidSkipPatch: false,
142142
}
143-
if err := yaml.Unmarshal(fileData, &sv); err != nil {
143+
if err := yaml.Unmarshal(data, &sv); err != nil {
144144
return nil, err
145145
}
146146
return &sv, nil

cmd/opm/alpha/veneer/semver.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,13 @@ func newSemverCmd() *cobra.Command {
2323
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",
2424
Args: cobra.MaximumNArgs(1),
2525
RunE: func(cmd *cobra.Command, args []string) error {
26-
var (
27-
data io.Reader
28-
err error
29-
)
30-
3126
// Handle different input argument types
32-
if len(args) == 0 || args[0] == "-" {
33-
// When no arguments or "-" is passed to the command,
34-
// assume input is coming from stdin
35-
data = cmd.InOrStdin()
36-
} else {
37-
// Otherwise open the file passed to the command
38-
data, err = os.Open(args[0])
39-
if err != nil {
40-
return err
41-
}
27+
// When no arguments or "-" is passed to the command,
28+
// assume input is coming from stdin
29+
// Otherwise open the file passed to the command
30+
data, err := openFileOrReadStdin(cmd, args)
31+
if err != nil {
32+
return err
4233
}
4334

4435
var write func(declcfg.DeclarativeConfig, io.Writer) error
@@ -86,3 +77,10 @@ func newSemverCmd() *cobra.Command {
8677
cmd.Flags().StringVarP(&output, "output", "o", "json", "Output format (json|yaml|mermaid)")
8778
return cmd
8879
}
80+
81+
func openFileOrReadStdin(cmd *cobra.Command, args []string) (io.Reader, error) {
82+
if len(args) == 0 || args[0] == "-" {
83+
return cmd.InOrStdin(), nil
84+
}
85+
return os.Open(args[0])
86+
}

0 commit comments

Comments
 (0)