diff --git a/cmd/oras/attach.go b/cmd/oras/attach.go index ba26e793e..def456817 100644 --- a/cmd/oras/attach.go +++ b/cmd/oras/attach.go @@ -27,6 +27,7 @@ import ( "oras.land/oras-go/v2/content" "oras.land/oras-go/v2/content/file" "oras.land/oras/cmd/oras/internal/display" + "oras.land/oras/cmd/oras/internal/errors" "oras.land/oras/cmd/oras/internal/option" ) @@ -90,7 +91,7 @@ func runAttach(opts attachOptions) error { return err } if dst.Reference.Reference == "" { - return newErrInvalidReference(dst.Reference) + return errors.NewErrInvalidReference(dst.Reference) } ociSubject, err := dst.Resolve(ctx, dst.Reference.Reference) if err != nil { diff --git a/cmd/oras/copy.go b/cmd/oras/copy.go index 1cb4ba9a7..017197475 100644 --- a/cmd/oras/copy.go +++ b/cmd/oras/copy.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/cobra" "oras.land/oras-go/v2" "oras.land/oras/cmd/oras/internal/display" + "oras.land/oras/cmd/oras/internal/errors" "oras.land/oras/cmd/oras/internal/option" ) @@ -101,7 +102,7 @@ func runCopy(opts copyOptions) error { } if src.Reference.Reference == "" { - return newErrInvalidReference(src.Reference) + return errors.NewErrInvalidReference(src.Reference) } var desc ocispec.Descriptor diff --git a/cmd/oras/discover.go b/cmd/oras/discover.go index 7942568aa..51cb04839 100644 --- a/cmd/oras/discover.go +++ b/cmd/oras/discover.go @@ -30,6 +30,7 @@ import ( ocispec "github.com/opencontainers/image-spec/specs-go/v1" artifactspec "github.com/oras-project/artifacts-spec/specs-go/v1" "github.com/spf13/cobra" + "oras.land/oras/cmd/oras/internal/errors" ) type discoverOptions struct { @@ -79,7 +80,7 @@ func runDiscover(opts discoverOptions) error { return err } if repo.Reference.Reference == "" { - return newErrInvalidReference(repo.Reference) + return errors.NewErrInvalidReference(repo.Reference) } // discover artifacts diff --git a/cmd/oras/errors.go b/cmd/oras/internal/errors/errors.go similarity index 82% rename from cmd/oras/errors.go rename to cmd/oras/internal/errors/errors.go index 9e6e883be..bbd43483d 100644 --- a/cmd/oras/errors.go +++ b/cmd/oras/internal/errors/errors.go @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package errors import ( "fmt" @@ -21,7 +21,7 @@ import ( "oras.land/oras-go/v2/registry" ) -// newErrInvalidReference creates a new error based on the reference string. -func newErrInvalidReference(ref registry.Reference) error { +// NewErrInvalidReference creates a new error based on the reference string. +func NewErrInvalidReference(ref registry.Reference) error { return fmt.Errorf("%s: invalid image reference, expecting ", ref) } diff --git a/cmd/oras/pull.go b/cmd/oras/pull.go index b7086260c..e7dcf96e0 100644 --- a/cmd/oras/pull.go +++ b/cmd/oras/pull.go @@ -27,6 +27,7 @@ import ( "oras.land/oras-go/v2/content/file" "oras.land/oras-go/v2/content/oci" "oras.land/oras/cmd/oras/internal/display" + "oras.land/oras/cmd/oras/internal/errors" "oras.land/oras/cmd/oras/internal/option" "oras.land/oras/internal/cache" ) @@ -88,7 +89,7 @@ func runPull(opts pullOptions) error { return err } if repo.Reference.Reference == "" { - return newErrInvalidReference(repo.Reference) + return errors.NewErrInvalidReference(repo.Reference) } var src oras.Target = repo if opts.cacheRoot != "" { diff --git a/go.mod b/go.mod index 0926d1d6c..2fdf70108 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/sirupsen/logrus v1.9.0 github.com/spf13/cobra v1.5.0 github.com/spf13/pflag v1.0.5 - oras.land/oras-go/v2 v2.0.0-20220804053649-e135557babfa + oras.land/oras-go/v2 v2.0.0-rc.2 ) require ( diff --git a/go.sum b/go.sum index e031b6091..80645092c 100644 --- a/go.sum +++ b/go.sum @@ -67,5 +67,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= -oras.land/oras-go/v2 v2.0.0-20220804053649-e135557babfa h1:/K4LND5cuAwZTGZ793qPQOppK8+vNX1JvSFNIEcUDKM= -oras.land/oras-go/v2 v2.0.0-20220804053649-e135557babfa/go.mod h1:IZRIoIJqkAH6x0pL3tVnpyPUyZgthjSyPcH2kgJvBMo= +oras.land/oras-go/v2 v2.0.0-rc.2 h1:dks9BxPg6HQOxn5+jVNuTFl45FuYvHfLQ6wcP7hVRdE= +oras.land/oras-go/v2 v2.0.0-rc.2/go.mod h1:IZRIoIJqkAH6x0pL3tVnpyPUyZgthjSyPcH2kgJvBMo=