diff --git a/cmd/oras/root/manifest/fetch.go b/cmd/oras/root/manifest/fetch.go index 9b60cb991..0e6edd104 100644 --- a/cmd/oras/root/manifest/fetch.go +++ b/cmd/oras/root/manifest/fetch.go @@ -74,8 +74,11 @@ Example - Fetch raw manifest from an OCI layout archive file 'layout.tar': switch { case opts.outputPath == "-" && opts.Template != "": return fmt.Errorf("`--output -` cannot be used with `--format %s` at the same time", opts.Template) - case opts.OutputDescriptor && opts.outputPath == "-": + case opts.outputPath == "-" && opts.OutputDescriptor: return fmt.Errorf("`--descriptor` cannot be used with `--output -` at the same time") + // ignore --pretty when output to a file + case opts.outputPath != "" && opts.outputPath != "-": + opts.Pretty.Pretty = false } if err := oerrors.CheckMutuallyExclusiveFlags(cmd.Flags(), "format", "pretty"); err != nil { return err diff --git a/test/e2e/suite/command/manifest.go b/test/e2e/suite/command/manifest.go index fafe683a8..ca92e4abe 100644 --- a/test/e2e/suite/command/manifest.go +++ b/test/e2e/suite/command/manifest.go @@ -232,6 +232,13 @@ var _ = Describe("1.1 registry users:", func() { MatchFile(fetchPath, multi_arch.Manifest, DefaultTimeout) }) + It("should ignore --pretty when fetching manifest to a file", func() { + fetchPath := filepath.Join(GinkgoT().TempDir(), "fetchedImage") + ORAS("manifest", "fetch", RegistryRef(ZOTHost, ImageRepo, multi_arch.Tag), "--output", fetchPath, "--pretty"). + Exec() + MatchFile(fetchPath, multi_arch.Manifest, DefaultTimeout) + }) + It("should fetch manifest to file and output json", func() { fetchPath := filepath.Join(GinkgoT().TempDir(), "fetchedImage") digest := multi_arch.LinuxAMD64.Digest.String()