Skip to content

Commit 4a8f5e5

Browse files
wangxiaoxuan273Xiaoxuan WangTerryHowe
authored
refactor: deprecate table format (#1656)
Signed-off-by: Xiaoxuan Wang <[email protected]> Co-authored-by: Xiaoxuan Wang <[email protected]> Co-authored-by: Terry Howe <[email protected]>
1 parent dfd8b1e commit 4a8f5e5

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

cmd/oras/internal/option/format.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ var (
5656
Usage: "Print output using the given Go template",
5757
HasParams: true,
5858
}
59+
// the table format is deprecated
5960
FormatTypeTable = &FormatType{
6061
Name: "table",
61-
Usage: "Get direct referrers and output in table format",
62+
Usage: "[Deprecated] Get direct referrers and output in table format",
6263
}
6364
FormatTypeTree = &FormatType{
6465
Name: "tree",
@@ -98,7 +99,11 @@ func (opts *Format) ApplyFlags(fs *pflag.FlagSet) {
9899
}
99100

100101
// Parse parses the input format flag.
101-
func (opts *Format) Parse(_ *cobra.Command) error {
102+
func (opts *Format) Parse(cmd *cobra.Command) error {
103+
// print deprecation message for table format
104+
if opts.FormatFlag == FormatTypeTable.Name {
105+
fmt.Fprint(cmd.ErrOrStderr(), "Format \"table\" is deprecated and will be removed in a future release.\n")
106+
}
102107
if err := opts.parseFlag(); err != nil {
103108
return err
104109
}

test/e2e/internal/testdata/feature/feature.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
package feature
1717

1818
const DeprecationMessageVerboseFlag = "Flag --verbose has been deprecated, and will be removed in a future release."
19+
const DeprecationMessageTableFormat = "Format \"table\" is deprecated and will be removed in a future release.\n"
1920

2021
var (
2122
Preview = struct {

test/e2e/suite/command/discover.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ var _ = Describe("ORAS beginners:", func() {
5656
gomega.Expect(out).Should(gbytes.Say("--distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark)))
5757
})
5858

59-
It("should show text as default format type in help doc", func() {
59+
It("should show tree as default format type in help doc", func() {
6060
MatchDefaultFlagValue("format", "tree", "discover")
6161
})
6262

63+
It("should show deprecation message when using table format", func() {
64+
ORAS("discover", RegistryRef(ZOTHost, ImageRepo, foobar.Tag), "--format", "table").MatchErrKeyWords(feature.DeprecationMessageTableFormat).Exec()
65+
})
66+
6367
It("should fail when no subject reference provided", func() {
6468
ORAS("discover").ExpectFailure().MatchErrKeyWords("Error:").Exec()
6569
})
@@ -192,7 +196,7 @@ var _ = Describe("1.1 registry users:", func() {
192196
})
193197
When("running discover command with table output", func() {
194198
format := "table"
195-
It("should all referrers of a subject with deprecation hint", func() {
199+
It("should show all referrers of a subject with deprecation hint", func() {
196200
referrers := []ocispec.Descriptor{foobar.SBOMImageReferrer, foobar.SBOMImageReferrer}
197201
ORAS("discover", subjectRef, "-o", format).
198202
MatchErrKeyWords(feature.Deprecated.Mark).
@@ -204,7 +208,7 @@ var _ = Describe("1.1 registry users:", func() {
204208
err := ORAS("discover", subjectRef, "--format", format).
205209
MatchKeyWords(append(discoverKeyWords(false, referrers...), foobar.Digest)...).
206210
Exec().Err
207-
Expect(err).NotTo(gbytes.Say(feature.Deprecated.Mark))
211+
Expect(err).To(gbytes.Say(feature.Deprecated.Mark))
208212
})
209213
})
210214
When("running discover command with go-template output", func() {

0 commit comments

Comments
 (0)