Skip to content

Commit

Permalink
fix: ignore --pretty when --output is used for oras manifest fetch (o…
Browse files Browse the repository at this point in the history
…ras-project#1363)

Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 authored and FeynmanZhou committed May 11, 2024
1 parent 62ce5f9 commit c4bce2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/oras/root/manifest/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/suite/command/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c4bce2c

Please sign in to comment.