Skip to content

Commit

Permalink
attempt
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 committed Apr 1, 2024
1 parent bba2abc commit 2f22b7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 8 additions & 6 deletions cmd/oras/internal/option/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
const (
ImageSpecV1_1 = "v1.1"
ImageSpecV1_0 = "v1.0"
ImageSpecAuto = "auto"
)

const (
Expand All @@ -36,15 +37,15 @@ const (

// ImageSpec option struct which implements pflag.Value interface.
type ImageSpec struct {
flag string
Flag string
PackVersion oras.PackManifestVersion
}

// Set validates and sets the flag value from a string argument.
func (is *ImageSpec) Set(value string) error {
is.flag = value
is.Flag = value
switch value {
case ImageSpecV1_1:
case ImageSpecV1_1, ImageSpecAuto:
is.PackVersion = oras.PackManifestVersion1_1
case ImageSpecV1_0:
is.PackVersion = oras.PackManifestVersion1_0
Expand All @@ -67,19 +68,20 @@ func (is *ImageSpec) Options() string {
return strings.Join([]string{
ImageSpecV1_1,
ImageSpecV1_0,
ImageSpecAuto,
}, ", ")
}

// String returns the string representation of the flag.
func (is *ImageSpec) String() string {
return is.flag
return is.Flag
}

// ApplyFlags applies flags to a command flag set.
func (is *ImageSpec) ApplyFlags(fs *pflag.FlagSet) {
// default to v1.1-rc.4
// default to auto
is.PackVersion = oras.PackManifestVersion1_1
defaultFlag := ImageSpecV1_1
defaultFlag := ImageSpecAuto
fs.Var(is, "image-spec", fmt.Sprintf(`[Experimental] specify manifest type for building artifact. Options: %s (default %q)`, is.Options(), defaultFlag))
}

Expand Down
15 changes: 7 additions & 8 deletions cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ Example - Push file "hi.txt" into an OCI image layout folder 'layout-dir' with t
return err
}

// if --config is not used, image spec version is automatically set
// to 1.0; otherwise the version is set to 1.1.
if opts.manifestConfigRef == "" {
opts.PackVersion = oras.PackManifestVersion1_0
} else {
opts.PackVersion = oras.PackManifestVersion1_1
if opts.manifestConfigRef != "" && opts.artifactType == "" {
switch opts.Flag {
case option.ImageSpecAuto:
opts.PackVersion = oras.PackManifestVersion1_0
case option.ImageSpecV1_1:
return errors.New("--artifact-type must be set for 1.1 OCI image")

Check warning on line 117 in cmd/oras/root/push.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/push.go#L114-L117

Added lines #L114 - L117 were not covered by tests
}
}

switch opts.PackVersion {
Expand All @@ -125,8 +126,6 @@ Example - Push file "hi.txt" into an OCI image layout folder 'layout-dir' with t
case oras.PackManifestVersion1_1:
if opts.manifestConfigRef == "" && opts.artifactType == "" {
opts.artifactType = oras.MediaTypeUnknownArtifact
} else if opts.artifactType == "" {
return errors.New("--artifact-type must be set for 1.1 OCI image")
}
}
return nil
Expand Down

0 comments on commit 2f22b7d

Please sign in to comment.