Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: mark --verbose as deprecated #1558

Merged
merged 11 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/oras/root/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ type attachOptions struct {

artifactType string
concurrency int
verbose bool
// Deprecated: verbose is deprecated and will be removed in the future.
verbose bool
}

func attachCmd() *cobra.Command {
Expand Down Expand Up @@ -117,9 +118,10 @@ Example - Attach file to the manifest tagged 'v1' in an OCI image layout folder

cmd.Flags().StringVarP(&opts.artifactType, "artifact-type", "", "", "artifact type")
cmd.Flags().IntVarP(&opts.concurrency, "concurrency", "", 5, "concurrency level")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "print status output for unnamed blobs")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", true, "print status output for unnamed blobs")
opts.FlagDescription = "[Preview] attach to an arch-specific subject"
_ = cmd.MarkFlagRequired("artifact-type")
_ = cmd.Flags().MarkDeprecated("verbose", "and will be removed in a future release.")
opts.EnableDistributionSpecFlag()
opts.SetTypes(option.FormatTypeText, option.FormatTypeJSON, option.FormatTypeGoTemplate)
option.ApplyFlags(&opts, cmd.Flags())
Expand Down
6 changes: 4 additions & 2 deletions cmd/oras/root/blob/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type pushBlobOptions struct {
fileRef string
mediaType string
size int64
verbose bool
// Deprecated: verbose is deprecated and will be removed in the future.
verbose bool
}

func pushCmd() *cobra.Command {
Expand Down Expand Up @@ -98,7 +99,8 @@ Example - Push blob 'hi.txt' into an OCI image layout folder 'layout-dir':

cmd.Flags().Int64VarP(&opts.size, "size", "", -1, "provide the blob size")
cmd.Flags().StringVarP(&opts.mediaType, "media-type", "", ocispec.MediaTypeImageLayer, "specify the returned media type in the descriptor if --descriptor is used")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "print status output for unnamed blobs")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", true, "print status output for unnamed blobs")
_ = cmd.Flags().MarkDeprecated("verbose", "and will be removed in a future release.")
option.ApplyFlags(&opts, cmd.Flags())
return oerrors.Command(cmd, &opts.Target)
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/oras/root/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ type copyOptions struct {
recursive bool
concurrency int
extraRefs []string
verbose bool
// Deprecated: verbose is deprecated and will be removed in the future.
verbose bool
}

func copyCmd() *cobra.Command {
Expand Down Expand Up @@ -104,7 +105,8 @@ Example - Copy an artifact with multiple tags with concurrency tuned:
}
cmd.Flags().BoolVarP(&opts.recursive, "recursive", "r", false, "[Preview] recursively copy the artifact and its referrer artifacts")
cmd.Flags().IntVarP(&opts.concurrency, "concurrency", "", 3, "concurrency level")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "print status output for unnamed blobs")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", true, "print status output for unnamed blobs")
_ = cmd.Flags().MarkDeprecated("verbose", "and will be removed in a future release.")
opts.EnableDistributionSpecFlag()
option.ApplyFlags(&opts, cmd.Flags())
return oerrors.Command(cmd, &opts.BinaryTarget)
Expand Down
6 changes: 4 additions & 2 deletions cmd/oras/root/manifest/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ type pushOptions struct {
extraRefs []string
fileRef string
mediaType string
verbose bool
// Deprecated: verbose is deprecated and will be removed in the future.
verbose bool
}

func pushCmd() *cobra.Command {
Expand Down Expand Up @@ -109,7 +110,8 @@ Example - Push a manifest to an OCI image layout folder 'layout-dir' and tag wit
option.ApplyFlags(&opts, cmd.Flags())
cmd.Flags().StringVarP(&opts.mediaType, "media-type", "", "", "media type of manifest")
cmd.Flags().IntVarP(&opts.concurrency, "concurrency", "", 5, "concurrency level")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "print status output for unnamed blobs")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", true, "print status output for unnamed blobs")
_ = cmd.Flags().MarkDeprecated("verbose", "and will be removed in a future release.")
return oerrors.Command(cmd, &opts.Target)
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/oras/root/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type pullOptions struct {
PathTraversal bool
Output string
ManifestConfigRef string
verbose bool
// Deprecated: verbose is deprecated and will be removed in the future.
verbose bool
}

func pullCmd() *cobra.Command {
Expand Down Expand Up @@ -113,7 +114,8 @@ Example - Pull artifact files from an OCI layout archive 'layout.tar':
cmd.Flags().StringVarP(&opts.Output, "output", "o", ".", "output directory")
cmd.Flags().StringVarP(&opts.ManifestConfigRef, "config", "", "", "output manifest config file")
cmd.Flags().IntVarP(&opts.concurrency, "concurrency", "", 3, "concurrency level")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "print status output for unnamed blobs")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", true, "print status output for unnamed blobs")
_ = cmd.Flags().MarkDeprecated("verbose", "and will be removed in a future release.")
opts.SetTypes(option.FormatTypeText, option.FormatTypeJSON, option.FormatTypeGoTemplate)
option.ApplyFlags(&opts, cmd.Flags())
return oerrors.Command(cmd, &opts.Target)
Expand Down
6 changes: 4 additions & 2 deletions cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type pushOptions struct {
manifestConfigRef string
artifactType string
concurrency int
verbose bool
// Deprecated: verbose is deprecated and will be removed in the future.
verbose bool
}

func pushCmd() *cobra.Command {
Expand Down Expand Up @@ -165,7 +166,8 @@ Example - Push file "hi.txt" into an OCI image layout folder 'layout-dir' with t
cmd.Flags().StringVarP(&opts.manifestConfigRef, "config", "", "", "`path` of image config file")
cmd.Flags().StringVarP(&opts.artifactType, "artifact-type", "", "", "artifact type")
cmd.Flags().IntVarP(&opts.concurrency, "concurrency", "", 5, "concurrency level")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "print status output for unnamed blobs")
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", true, "print status output for unnamed blobs")
_ = cmd.Flags().MarkDeprecated("verbose", "and will be removed in a future release.")
opts.SetTypes(option.FormatTypeText, option.FormatTypeJSON, option.FormatTypeGoTemplate)
option.ApplyFlags(&opts, cmd.Flags())
return oerrors.Command(cmd, &opts.Target)
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/internal/testdata/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ limitations under the License.

package feature

const DeprecationMessageVerboseFlag = "Flag --verbose has been deprecated, and will be removed in a future release."

var (
Preview = struct {
Mark string
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/internal/utils/match/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func newStateMachine(cmd string) *stateMachine {
sm.addPath("Skipped")
sm.addPath("Exists")
sm.addPath("Mounted")
case "manifest", "blob": // for `manifest push` and `blob push`
Wwwsylvia marked this conversation as resolved.
Show resolved Hide resolved
// TODO: refactor the matcher to match full command like `manifest push`, `manifest delete`, etc.
// Tracking issue: https://github.com/oras-project/oras/issues/1571
sm.addPath("Uploading", "Uploaded")
sm.addPath("Exists")
default:
ginkgo.Fail("Unrecognized cmd name " + cmd)
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ var _ = Describe("Common registry user", func() {
src := RegistryRef(ZOTHost, ArtifactRepo, foobar.Tag)
dst := RegistryRef(ZOTHost, fmt.Sprintf("command/auth/%d/copy", GinkgoRandomSeed()), foobar.Tag)
foobarStates := append(foobar.ImageLayerStateKeys, foobar.ManifestStateKey, foobar.ImageConfigStateKey(oras.MediaTypeUnknownConfig))
ORAS("cp", src, dst, "-v", "--from-registry-config", LegacyConfigPath, "--to-registry-config", LegacyConfigPath).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
ORAS("cp", src, dst, "--from-registry-config", LegacyConfigPath, "--to-registry-config", LegacyConfigPath).MatchStatus(foobarStates, true, len(foobarStates)).Exec()
})
})
})
Expand Down
33 changes: 32 additions & 1 deletion test/e2e/suite/command/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,41 @@ var _ = Describe("ORAS beginners:", func() {
RunAndShowPreviewInHelp([]string{"attach"})

It("should show preview and help doc", func() {
out := ORAS("attach", "--help").MatchKeyWords(feature.Preview.Mark+" Attach", feature.Preview.Description, ExampleDesc).Exec()
out := ORAS("attach", "--help").MatchKeyWords(feature.Preview.Mark+" Attach", feature.Preview.Description, ExampleDesc).Exec().Out
gomega.Expect(out).Should(gbytes.Say("--distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark)))
})

It("should not show --verbose in help doc", func() {
out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out
gomega.Expect(out).ShouldNot(gbytes.Say("--verbose"))
})

It("should show deprecation message and print unnamed status output for --verbose", func() {
testRepo := attachTestRepo("test-verbose")
CopyZOTRepo(ImageRepo, testRepo)
subjectRef := RegistryRef(ZOTHost, testRepo, foobar.Tag)
stateKeys := []match.StateKey{
foobar.AttachFileStateKey,
{Digest: "44136fa355b3", Name: "application/vnd.oci.empty.v1+json"},
}
ORAS("attach", "--artifact-type", "test/attach", "--verbose", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)).
WithWorkDir(PrepareTempFiles()).
MatchErrKeyWords(feature.DeprecationMessageVerboseFlag).
MatchStatus(stateKeys, true, len(stateKeys)).Exec()
})

It("should show deprecation message and should NOT print unnamed status output for --verbose=false", func() {
testRepo := attachTestRepo("test-verbose-false")
CopyZOTRepo(ImageRepo, testRepo)
subjectRef := RegistryRef(ZOTHost, testRepo, foobar.Tag)
stateKeys := []match.StateKey{foobar.AttachFileStateKey}
out := ORAS("attach", "--artifact-type", "test/attach", "--verbose=false", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)).
WithWorkDir(PrepareTempFiles()).
MatchErrKeyWords(feature.DeprecationMessageVerboseFlag).
MatchStatus(stateKeys, false, len(stateKeys)).Exec().Out
gomega.Expect(out).ShouldNot(gbytes.Say("application/vnd.oci.empty.v1+json"))
})

It("should show text as default format type in help doc", func() {
MatchDefaultFlagValue("format", "text", "attach")
})
Expand Down
34 changes: 31 additions & 3 deletions test/e2e/suite/command/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"oras.land/oras/test/e2e/internal/testdata/feature"
"oras.land/oras/test/e2e/internal/testdata/foobar"
. "oras.land/oras/test/e2e/internal/utils"
"oras.land/oras/test/e2e/internal/utils/match"
)

const (
Expand All @@ -39,6 +41,30 @@ var _ = Describe("ORAS beginners:", func() {
repoFmt := fmt.Sprintf("command/blob/%%s/%d/%%s", GinkgoRandomSeed())
When("running blob command", func() {
When("running `blob push`", func() {
It("should not show --verbose in help doc", func() {
out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out
gomega.Expect(out).ShouldNot(gbytes.Say("--verbose"))
})

It("should show deprecation message and print unnamed status output for --verbose", func() {
repo := fmt.Sprintf(repoFmt, "push", "test-verbose")
ORAS("blob", "push", RegistryRef(ZOTHost, repo, pushDigest), "-", "--size", strconv.Itoa(len(pushContent)), "--verbose").
WithInput(strings.NewReader(pushContent)).
MatchErrKeyWords(feature.DeprecationMessageVerboseFlag).
MatchStatus([]match.StateKey{{Digest: "e1ca41574914", Name: "application/vnd.oci.image.layer.v1.tar"}}, true, 1).
Exec()
})

It("should show deprecation message and should NOT print unnamed status output for --verbose=false", func() {
repo := fmt.Sprintf(repoFmt, "push", "test-verbose-false")
out := ORAS("blob", "push", RegistryRef(ZOTHost, repo, pushDigest), "-", "--size", strconv.Itoa(len(pushContent)), "--verbose=false").
WithInput(strings.NewReader(pushContent)).
MatchErrKeyWords(feature.DeprecationMessageVerboseFlag).
Exec().Out
// should not print status output for unnamed blobs
gomega.Expect(out).ShouldNot(gbytes.Say("application/vnd.oci.image.layer.v1.tar"))
Wwwsylvia marked this conversation as resolved.
Show resolved Hide resolved
})

It("should fail to read blob content and password from stdin at the same time", func() {
repo := fmt.Sprintf(repoFmt, "push", "password-stdin")
ORAS("blob", "push", RegistryRef(ZOTHost, repo, ""), "--password-stdin", "-").
Expand Down Expand Up @@ -236,9 +262,11 @@ var _ = Describe("1.1 registry users:", func() {
MatchContent(fmt.Sprintf(pushDescFmt, mediaType)).Exec()
ORAS("blob", "fetch", RegistryRef(ZOTHost, repo, pushDigest), "--output", "-").MatchContent(pushContent).Exec()

ORAS("blob", "push", RegistryRef(ZOTHost, repo, ""), blobPath, "-v").
ORAS("blob", "push", RegistryRef(ZOTHost, repo, ""), blobPath).
WithDescription("skip the pushing if the blob already exists in the target repo").
MatchKeyWords("Exists").Exec()
MatchStatus([]match.StateKey{{Digest: "e1ca41574914", Name: "application/vnd.oci.image.layer.v1.tar"}}, true, 1).
MatchKeyWords("Exists").
Exec()
})

It("should push a blob from a stdin and output the descriptor with specific media-type", func() {
Expand Down Expand Up @@ -347,7 +375,7 @@ var _ = Describe("OCI image layout users:", func() {
// test
ORAS("blob", "push", Flags.Layout, LayoutRef(tmpRoot, pushDigest), blobPath, "--media-type", mediaType, "--descriptor").
MatchContent(fmt.Sprintf(pushDescFmt, mediaType)).Exec()
ORAS("blob", "push", Flags.Layout, LayoutRef(tmpRoot, pushDigest), blobPath, "-v").
ORAS("blob", "push", Flags.Layout, LayoutRef(tmpRoot, pushDigest), blobPath).
WithDescription("skip pushing if the blob already exists in the target repo").
MatchKeyWords("Exists").Exec()
// validate
Expand Down
Loading
Loading