Skip to content

Commit

Permalink
rename flag
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Jun 1, 2023
1 parent 02781cf commit d37ec9b
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 18 deletions.
8 changes: 4 additions & 4 deletions cmd/oras/internal/option/referrers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ import (

// Referrers option struct.
type Referrers struct {
GC bool
SkipDeleteReferrers bool
}

// ApplyFlags applies flags to a command flag set.
func (opts *Referrers) ApplyFlags(fs *pflag.FlagSet) {
fs.BoolVarP(&opts.GC, "referrers-gc", "", false, "enforce garbage collection when referrers API is not supported")
fs.BoolVarP(&opts.SkipDeleteReferrers, "skip-delete-referrers", "", false, "skip deleting old referrers index, only work on registry when referrers API is not supported")
}

// SetReferrersGC sets the referrers GC option for the passed-in target.
func (opts *Referrers) SetReferrersGC(target any) error {
if repo, ok := target.(*remote.Repository); ok {
repo.SkipReferrersGC = !opts.GC
} else if opts.GC {
repo.SkipReferrersGC = opts.SkipDeleteReferrers
} else if opts.SkipDeleteReferrers {
return errors.New("referrers GC can only be enforced to registry targets")
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/root/manifest/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func deleteManifest(ctx context.Context, opts deleteOptions) error {
if err != nil {
return err
}
repo.SkipReferrersGC = !opts.GC
repo.SkipReferrersGC = opts.SkipDeleteReferrers

if repo.Reference.Reference == "" {
return oerrors.NewErrInvalidReference(repo.Reference)
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module oras.land/oras

go 1.20

replace oras.land/oras-go/v2 => github.com/qweeah/oras-go/v2 v2.0.0-20230529235543-a9c210426e75

require (
github.com/need-being/go-tree v0.1.0
github.com/opencontainers/go-digest v1.0.0
Expand All @@ -14,7 +12,7 @@ require (
github.com/spf13/pflag v1.0.5
golang.org/x/term v0.8.0
gopkg.in/yaml.v3 v3.0.1
oras.land/oras-go/v2 v2.2.0
oras.land/oras-go/v2 v2.2.1-0.20230531090906-7dd0378382c6
)

require (
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ github.com/oras-project/oras-credentials-go v0.1.1 h1:9EHrcJ1LcC7N9w2rfB9n8c1be+
github.com/oras-project/oras-credentials-go v0.1.1/go.mod h1:188MBZBQQbrLlrOZY37hc8Z4Xjl+wP3PaIJkJuk94JM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qweeah/oras-go/v2 v2.0.0-20230529235543-a9c210426e75 h1:kMGjc8rYeWaipvK4SHawreg40cr5v67U8HDVi1rXbDs=
github.com/qweeah/oras-go/v2 v2.0.0-20230529235543-a9c210426e75/go.mod h1:pXjn0+KfarspMHHNR3A56j3tgvr+mxArHuI8qVn59v8=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
Expand All @@ -40,3 +38,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
oras.land/oras-go/v2 v2.2.0 h1:E1fqITD56Eg5neZbxBtAdZVgDHD6wBabJo6xESTcQyo=
oras.land/oras-go/v2 v2.2.0/go.mod h1:pXjn0+KfarspMHHNR3A56j3tgvr+mxArHuI8qVn59v8=
oras.land/oras-go/v2 v2.2.1-0.20230531090906-7dd0378382c6 h1:2P1fjq1znGLo7tjy9PJsZrFF5L+qywbv28IgzKEX62E=
oras.land/oras-go/v2 v2.2.1-0.20230531090906-7dd0378382c6/go.mod h1:pXjn0+KfarspMHHNR3A56j3tgvr+mxArHuI8qVn59v8=
4 changes: 1 addition & 3 deletions test/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ module oras.land/oras/test/e2e

go 1.20

replace oras.land/oras-go/v2 => github.com/qweeah/oras-go/v2 v2.0.0-20230529235543-a9c210426e75

require (
github.com/onsi/ginkgo/v2 v2.9.5
github.com/onsi/gomega v1.27.7
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc.3
gopkg.in/yaml.v2 v2.4.0
oras.land/oras-go/v2 v2.2.0
oras.land/oras-go/v2 v2.2.1-0.20230531090906-7dd0378382c6
)

require (
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ github.com/opencontainers/image-spec v1.1.0-rc.3 h1:GT9Xon8YrLxz6N7sErbN81V8J4lO
github.com/opencontainers/image-spec v1.1.0-rc.3/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qweeah/oras-go/v2 v2.0.0-20230529235543-a9c210426e75 h1:kMGjc8rYeWaipvK4SHawreg40cr5v67U8HDVi1rXbDs=
github.com/qweeah/oras-go/v2 v2.0.0-20230529235543-a9c210426e75/go.mod h1:pXjn0+KfarspMHHNR3A56j3tgvr+mxArHuI8qVn59v8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
Expand All @@ -49,3 +47,5 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
oras.land/oras-go/v2 v2.2.1-0.20230531090906-7dd0378382c6 h1:2P1fjq1znGLo7tjy9PJsZrFF5L+qywbv28IgzKEX62E=
oras.land/oras-go/v2 v2.2.1-0.20230531090906-7dd0378382c6/go.mod h1:pXjn0+KfarspMHHNR3A56j3tgvr+mxArHuI8qVn59v8=
2 changes: 1 addition & 1 deletion test/e2e/suite/command/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ var _ = Describe("OCI image layout users:", func() {
It("should fail to specify referrers garbage collection", func() {
root := PrepareTempFiles()
subjectRef := LayoutRef(root, foobar.Tag)
ORAS("attach", "--artifact-type", "test.attach", "--referrers-gc", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)).
ORAS("attach", "--artifact-type", "test.attach", "--skip-delete-referrers", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)).
ExpectFailure().
MatchContent("Error: referrers GC can only be enforced to registry targets\n").
Exec()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite/command/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ var _ = Describe("OCI spec 1.0 registry users:", func() {
var _ = Describe("OCI layout users:", func() {
When("running `cp`", func() {
It("should fail to specify referrers garbage collection", func() {
ORAS("cp", RegistryRef(Host, ArtifactRepo, foobar.Tag), GinkgoT().TempDir(), Flags.ToLayout, "--referrers-gc").
ORAS("cp", RegistryRef(Host, ArtifactRepo, foobar.Tag), GinkgoT().TempDir(), Flags.ToLayout, "--skip-delete-referrers").
ExpectFailure().
MatchContent("Error: referrers GC can only be enforced to registry targets\n").
Exec()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite/command/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ var _ = Describe("OCI image layout users:", func() {
It("should fail to specify referrers garbage collection", func() {
manifestPath := WriteTempFile("manifest.json", manifest)
root := filepath.Dir(manifestPath)
ORAS("manifest", "push", root, Flags.Layout, manifestPath, "--referrers-gc").
ORAS("manifest", "push", root, Flags.Layout, manifestPath, "--skip-delete-referrers").
WithWorkDir(root).
ExpectFailure().
MatchContent("Error: referrers GC can only be enforced to registry targets\n").Exec()
Expand Down

0 comments on commit d37ec9b

Please sign in to comment.