Skip to content

Commit 7bfc4c1

Browse files
author
zhouhao
committed
validate.go: Modify the output mode
Signed-off-by: zhouhao <[email protected]>
1 parent f3b94b3 commit 7bfc4c1

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

cmd/oci-image-tool/validate.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@ func validateHandler(context *cli.Context) error {
4949
}
5050

5151
v = validateCmd{
52-
typ: context.String("type"),
53-
refs: context.StringSlice("ref"),
52+
stdout: log.New(os.Stdout, "", 0),
53+
typ: context.String("type"),
54+
refs: context.StringSlice("ref"),
5455
}
5556

5657
var errs []string
5758
for _, arg := range context.Args() {
5859
err := validatePath(arg)
5960

6061
if err == nil {
61-
fmt.Printf("%s: OK\n", arg)
62+
v.stdout.Printf("%s: OK\n", arg)
6263
continue
6364
}
6465

@@ -77,7 +78,7 @@ func validateHandler(context *cli.Context) error {
7778
if len(errs) > 0 {
7879
return fmt.Errorf("%d errors detected: \n%s", len(errs), strings.Join(errs, "\n"))
7980
}
80-
fmt.Println("Validation succeeded")
81+
v.stdout.Println("Validation succeeded")
8182
return nil
8283
}
8384

@@ -93,10 +94,6 @@ func validatePath(name string) error {
9394
}
9495
}
9596

96-
if v.stdout == nil {
97-
v.stdout = log.New(os.Stdout, "oci-image-tool: ", 0)
98-
}
99-
10097
switch typ {
10198
case image.TypeImageLayout:
10299
return image.ValidateLayout(name, v.refs, v.stdout)
@@ -105,7 +102,7 @@ func validatePath(name string) error {
105102
}
106103

107104
if len(v.refs) != 0 {
108-
fmt.Printf("WARNING: type %q does not support refs, which are only appropriate if type is image or imageLayout.\n", typ)
105+
v.stdout.Printf("WARNING: type %q does not support refs, which are only appropriate if type is image or imageLayout.\n", typ)
109106
}
110107

111108
f, err := os.Open(name)

image/image.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func validate(w walker, refs []string, out *log.Logger) error {
115115
}
116116

117117
if len(index.Manifests) == 0 {
118-
fmt.Println("warning: no manifests found")
118+
out.Println("warning: no manifests found")
119119
return nil
120120
}
121121

0 commit comments

Comments
 (0)