chore: Add format type text#1397
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1397 +/- ##
==========================================
+ Coverage 85.14% 85.32% +0.17%
==========================================
Files 107 107
Lines 3790 3795 +5
==========================================
+ Hits 3227 3238 +11
+ Misses 336 333 -3
+ Partials 227 224 -3 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Just to clarify: For this PR, which of the following is matches your expectation:
- Make the format selection code more readable, or
- Define the behavior of text output in command help doc. E.g. for v.1.2.0 the help doc of
oras attachis
> oras attach -h
...
--format string [Experimental] Format output using a custom template:
'json': Print in JSON format
'go-template': Print output using the given Go template
...And you are trying to change it to:
> oras attach -h
...
--format string [Experimental] Format output using a custom template:
'': Print in text format
'json': Print in JSON format
'go-template': Print output using the given Go template
.../cc @FeynmanZhou
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
5934c1d to
8a8027c
Compare
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
8a8027c to
1a64e75
Compare
qweeah
left a comment
There was a problem hiding this comment.
Should exclude FormatTypeText from oras discover
|
Since this PR unifies default value for format type, I am thinking maybe we should take a step further and add a new function to set default and optional allowed types, e.g. // Format contains input and parsed options for formatted output flags.
type Format struct {
FormatFlag string
Type string
Template string
defaultType *FormatType
allowedTypes []*FormatType
}
// SetTypes sets the default format type and allowed format types.
func (opts *Format) SetTypes(defaultType *FormatType, allowedTypes ...*FormatType) {
opts.defaultType = defaultType
opts.allowedTypes = append(allowedTypes, defaultType)
}So taking - opts.AllowedTypes = []*option.FormatType{option.FormatTypeJSON, option.FormatTypeGoTemplate}
+ opts.SetTypes(option.FormatTypeText, option.FormatTypeJSON, option.FormatTypeGoTemplate)For - opts.AllowedTypes = []*option.FormatType{
+ opts.SetType(
option.FormatTypeTree,
option.FormatTypeTable,
option.FormatTypeJSON.WithUsage("Get direct referrers and output in JSON format"),
option.FormatTypeGoTemplate.WithUsage("Print direct referrers using the given Go template"),
- }
+ ) |
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
shizhMSFT
left a comment
There was a problem hiding this comment.
LGTM with suggestions and questions.
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
What this PR does / why we need it:
Introduce
textas default format type forpull,push,manifest fetchandattachcommands.The only change in E2E experience is in the help document. Taking
oras attachas an example:Before
After