Skip to content

Commit

Permalink
Merge branch 'verbose_refactor' into verbose_refactor_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Wwwsylvia committed Nov 25, 2024
2 parents 49dfa17 + a892087 commit 66501f3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cmd/oras/internal/option/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ const NoTTYFlag = "no-tty"

// Common option struct.
type Common struct {
Debug bool
Verbose bool // deprecated, the current default behavior is equivalent to verbose=true TODO: better doc
TTY *os.File
Debug bool
// SuppressUntitled suppresses the status output for untitled blobs.
SuppressUntitled bool
TTY *os.File
*output.Printer
noTTY bool
SuppressUntitled bool // equivalent to verbose=false TODO: better doc
noTTY bool

// Deprecated: Verbose is deprecated. Use SuppressUntitled instead (SuppressUntitled=false is equivalent to Verbose=true).
Verbose bool
}

// ApplyFlags applies flags to a command flag set.
Expand All @@ -42,7 +45,7 @@ func (opts *Common) ApplyFlags(fs *pflag.FlagSet) {
fs.BoolVarP(&opts.Verbose, "verbose", "v", false, "[Deprecated] verbose output")
fs.BoolVarP(&opts.noTTY, NoTTYFlag, "", false, "[Preview] do not show progress output")

fs.MarkDeprecated("verbose", "and may be removed in a future release.") // TODO: remove -v in e2e test; test deprecation message
fs.MarkDeprecated("verbose", "and may be removed in a future release.") // TODO: test deprecation message
}

// Parse gets target options from user input.
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/suite/command/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ var _ = Describe("ORAS beginners:", func() {
MatchDefaultFlagValue("format", "text", "pull")
})

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

It("should show deprecation message for --verbose", func() {
tempDir := PrepareTempFiles()
ref := RegistryRef(ZOTHost, ImageRepo, foobar.Tag)
ORAS("pull", ref, "--verbose").
WithWorkDir(tempDir).
MatchErrKeyWords("Flag --verbose has been deprecated")
})

hintMsg := func(reference string) string {
return fmt.Sprintf("Skipped pulling layers without file name in \"org.opencontainers.image.title\"\nUse 'oras copy %s --to-oci-layout <layout-dir>' to pull all layers.\n", reference)
}
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/suite/command/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ var _ = Describe("ORAS beginners:", func() {
MatchDefaultFlagValue("format", "text", "push")
})

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 for --verbose", func() {
repo := pushTestRepo("test-verbose")
tag := "e2e"
tempDir := PrepareTempFiles()

ORAS("push", RegistryRef(ZOTHost, repo, tag), "--verbose").
WithWorkDir(tempDir).
MatchErrKeyWords("Flag --verbose has been deprecated")
})

It("should fail and show detailed error description if no argument provided", func() {
err := ORAS("push").ExpectFailure().Exec().Err
gomega.Expect(err).Should(gbytes.Say("Error"))
Expand Down

0 comments on commit 66501f3

Please sign in to comment.