From ccc2de34b1128cc156ed169776f3f7ff6f3b36ea Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Wed, 10 Apr 2024 06:32:09 +0000 Subject: [PATCH 1/6] ux: improve the usage doc of --image-spec Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/option/spec.go | 13 ++++++------- cmd/oras/root/push.go | 9 ++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cmd/oras/internal/option/spec.go b/cmd/oras/internal/option/spec.go index 67b7bceb8..e31b7595b 100644 --- a/cmd/oras/internal/option/spec.go +++ b/cmd/oras/internal/option/spec.go @@ -27,7 +27,6 @@ import ( const ( ImageSpecV1_1 = "v1.1" ImageSpecV1_0 = "v1.0" - ImageSpecAuto = "auto" ) const ( @@ -45,7 +44,7 @@ type ImageSpec struct { func (is *ImageSpec) Set(value string) error { is.Flag = value switch value { - case ImageSpecV1_1, ImageSpecAuto: + case ImageSpecV1_1: is.PackVersion = oras.PackManifestVersion1_1 case ImageSpecV1_0: is.PackVersion = oras.PackManifestVersion1_0 @@ -68,21 +67,21 @@ 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 + // to avoid printing default value in usage doc + return "" } // ApplyFlags applies flags to a command flag set. func (is *ImageSpec) ApplyFlags(fs *pflag.FlagSet) { - // default to auto + // default to v1.1, unless --config is used and --artifact-type is not used is.PackVersion = oras.PackManifestVersion1_1 - is.Flag = ImageSpecAuto - fs.Var(is, "image-spec", fmt.Sprintf(`[Experimental] specify manifest type for building artifact. Options: %s (default %q)`, is.Options(), ImageSpecAuto)) + is.Flag = ImageSpecV1_1 + fs.Var(is, "image-spec", fmt.Sprintf(`[Experimental] specify manifest type for building artifact. Options: %s (default v1.1, unless --config is used and --artifact-type is not used)`, is.Options())) } // DistributionSpec option struct which implements pflag.Value interface. diff --git a/cmd/oras/root/push.go b/cmd/oras/root/push.go index 7868b2df4..fee6616ea 100644 --- a/cmd/oras/root/push.go +++ b/cmd/oras/root/push.go @@ -110,13 +110,12 @@ Example - Push file "hi.txt" into an OCI image layout folder 'layout-dir' with t } if opts.manifestConfigRef != "" && opts.artifactType == "" { - switch opts.Flag { - case option.ImageSpecAuto: - // switch to v1.0 manifest since artifact type is suggested by OCI v1.1 - // artifact guidance but is not presented + if !cmd.Flags().Changed("image-spec") { + // switch to v1.0 manifest since artifact type is suggested + // by OCI v1.1 artifact guidance but is not presented // see https://github.com/opencontainers/image-spec/blob/e7f7c0ca69b21688c3cea7c87a04e4503e6099e2/manifest.md?plain=1#L170 opts.PackVersion = oras.PackManifestVersion1_0 - case option.ImageSpecV1_1: + } else if opts.Flag == option.ImageSpecV1_1 { return &oerrors.Error{ Err: errors.New(`missing artifact type for OCI image-spec v1.1 artifacts`), Recommendation: "set an artifact type via `--artifact-type` or consider image spec v1.0", From f1287d31246188d1b5ab81bd6d64c75f27292ea4 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Wed, 10 Apr 2024 07:01:09 +0000 Subject: [PATCH 2/6] refinement Signed-off-by: Xiaoxuan Wang --- cmd/oras/root/push.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/oras/root/push.go b/cmd/oras/root/push.go index fee6616ea..12379ce55 100644 --- a/cmd/oras/root/push.go +++ b/cmd/oras/root/push.go @@ -114,6 +114,7 @@ Example - Push file "hi.txt" into an OCI image layout folder 'layout-dir' with t // switch to v1.0 manifest since artifact type is suggested // by OCI v1.1 artifact guidance but is not presented // see https://github.com/opencontainers/image-spec/blob/e7f7c0ca69b21688c3cea7c87a04e4503e6099e2/manifest.md?plain=1#L170 + opts.Flag = option.ImageSpecV1_0 opts.PackVersion = oras.PackManifestVersion1_0 } else if opts.Flag == option.ImageSpecV1_1 { return &oerrors.Error{ From 0c61a43d2428ae61263eca9e6c224cd86916de03 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Wed, 10 Apr 2024 08:26:54 +0000 Subject: [PATCH 3/6] refine the message Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/option/spec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/internal/option/spec.go b/cmd/oras/internal/option/spec.go index e31b7595b..9e9bda9ef 100644 --- a/cmd/oras/internal/option/spec.go +++ b/cmd/oras/internal/option/spec.go @@ -81,7 +81,7 @@ func (is *ImageSpec) ApplyFlags(fs *pflag.FlagSet) { // default to v1.1, unless --config is used and --artifact-type is not used is.PackVersion = oras.PackManifestVersion1_1 is.Flag = ImageSpecV1_1 - fs.Var(is, "image-spec", fmt.Sprintf(`[Experimental] specify manifest type for building artifact. Options: %s (default v1.1, unless --config is used and --artifact-type is not used)`, is.Options())) + fs.Var(is, "image-spec", fmt.Sprintf(`[Experimental] specify manifest type for building artifact. Options: %s (default value is v1.1. The default is overridden to v1.0 if --config is specified and --artifact-type is not specified)`, is.Options())) } // DistributionSpec option struct which implements pflag.Value interface. From 86199155f59903698d1d9b009b35294398734412 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Thu, 11 Apr 2024 02:21:14 +0000 Subject: [PATCH 4/6] refined the message Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/option/spec.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/oras/internal/option/spec.go b/cmd/oras/internal/option/spec.go index 9e9bda9ef..b7bc7a35d 100644 --- a/cmd/oras/internal/option/spec.go +++ b/cmd/oras/internal/option/spec.go @@ -81,7 +81,8 @@ func (is *ImageSpec) ApplyFlags(fs *pflag.FlagSet) { // default to v1.1, unless --config is used and --artifact-type is not used is.PackVersion = oras.PackManifestVersion1_1 is.Flag = ImageSpecV1_1 - fs.Var(is, "image-spec", fmt.Sprintf(`[Experimental] specify manifest type for building artifact. Options: %s (default value is v1.1. The default is overridden to v1.0 if --config is specified and --artifact-type is not specified)`, is.Options())) + fs.Var(is, "image-spec", `[Experimental] specify manifest type for building artifact. Options: v1.1(default), v1.0 +(The default is overridden to v1.0 if --config is specified and --artifact-type is not specified)`) } // DistributionSpec option struct which implements pflag.Value interface. From 42c960cfd07a2e80bfc37723bec3f959802ee5e1 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Thu, 11 Apr 2024 06:22:59 +0000 Subject: [PATCH 5/6] preview Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/option/spec.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/oras/internal/option/spec.go b/cmd/oras/internal/option/spec.go index b7bc7a35d..dd49cf975 100644 --- a/cmd/oras/internal/option/spec.go +++ b/cmd/oras/internal/option/spec.go @@ -81,8 +81,7 @@ func (is *ImageSpec) ApplyFlags(fs *pflag.FlagSet) { // default to v1.1, unless --config is used and --artifact-type is not used is.PackVersion = oras.PackManifestVersion1_1 is.Flag = ImageSpecV1_1 - fs.Var(is, "image-spec", `[Experimental] specify manifest type for building artifact. Options: v1.1(default), v1.0 -(The default is overridden to v1.0 if --config is specified and --artifact-type is not specified)`) + fs.Var(is, "image-spec", `[Preview] specify manifest type for building artifact. Options: v1.1, v1.0 (default v1.1, overridden to v1.0 if --config is used without --artifact-type)`) } // DistributionSpec option struct which implements pflag.Value interface. From 6292d7ec94a696b0fe8d4b6e01539da2873c1f41 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Thu, 11 Apr 2024 06:28:35 +0000 Subject: [PATCH 6/6] revert Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/option/spec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/internal/option/spec.go b/cmd/oras/internal/option/spec.go index dd49cf975..f6a0e24ca 100644 --- a/cmd/oras/internal/option/spec.go +++ b/cmd/oras/internal/option/spec.go @@ -81,7 +81,7 @@ func (is *ImageSpec) ApplyFlags(fs *pflag.FlagSet) { // default to v1.1, unless --config is used and --artifact-type is not used is.PackVersion = oras.PackManifestVersion1_1 is.Flag = ImageSpecV1_1 - fs.Var(is, "image-spec", `[Preview] specify manifest type for building artifact. Options: v1.1, v1.0 (default v1.1, overridden to v1.0 if --config is used without --artifact-type)`) + fs.Var(is, "image-spec", `[Experimental] specify manifest type for building artifact. Options: v1.1, v1.0 (default v1.1, overridden to v1.0 if --config is used without --artifact-type)`) } // DistributionSpec option struct which implements pflag.Value interface.