Skip to content

Commit 32a06b6

Browse files
cli: Teach oc image mirror to accept a file from stdin
`oc image mirror -f -` should accept file definitions from STDIN like the rest of our commands.
1 parent 027d88e commit 32a06b6

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Diff for: pkg/oc/cli/image/mirror/mappings.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package mirror
33
import (
44
"bufio"
55
"fmt"
6+
"io"
67
"os"
78
"strings"
89
"sync"
@@ -104,14 +105,17 @@ func parseArgs(args []string, overlap map[string]string) ([]Mapping, error) {
104105
return mappings, nil
105106
}
106107

107-
func parseFile(filename string, overlap map[string]string) ([]Mapping, error) {
108+
func parseFile(filename string, overlap map[string]string, in io.Reader) ([]Mapping, error) {
108109
var fileMappings []Mapping
109-
f, err := os.Open(filename)
110-
if err != nil {
111-
return nil, err
110+
if filename != "-" {
111+
f, err := os.Open(filename)
112+
if err != nil {
113+
return nil, err
114+
}
115+
defer f.Close()
116+
in = f
112117
}
113-
defer f.Close()
114-
s := bufio.NewScanner(f)
118+
s := bufio.NewScanner(in)
115119
lineNumber := 0
116120
for s.Scan() {
117121
line := s.Text()

Diff for: pkg/oc/cli/image/mirror/mirror.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (o *MirrorImageOptions) Complete(cmd *cobra.Command, args []string) error {
151151
return err
152152
}
153153
for _, filename := range o.Filenames {
154-
mappings, err := parseFile(filename, overlap)
154+
mappings, err := parseFile(filename, overlap, o.In)
155155
if err != nil {
156156
return err
157157
}

0 commit comments

Comments
 (0)