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

chore: Add format type text #1397

Merged
merged 11 commits into from
Jun 18, 2024
Merged

Conversation

TerryHowe
Copy link
Member

@TerryHowe TerryHowe commented May 29, 2024

What this PR does / why we need it:

Introduce text as default format type for pull, push, manifest fetch and attach commands.

The only change in E2E experience is in the help document. Taking oras attach as an example:

Before

> 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
...

After

> 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
                                                    'text':         Print in text format (default "text")
...

Copy link

codecov bot commented May 29, 2024

Codecov Report

Attention: Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 85.32%. Comparing base (2aa005c) to head (40ca076).

Files Patch % Lines
cmd/oras/internal/display/handler.go 62.50% 0 Missing and 3 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

@qweeah qweeah requested a review from FeynmanZhou June 4, 2024 02:23
Copy link
Contributor

@qweeah qweeah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify: For this PR, which of the following is matches your expectation:

  1. Make the format selection code more readable, or
  2. Define the behavior of text output in command help doc. E.g. for v.1.2.0 the help doc of oras attach is
> 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

@TerryHowe TerryHowe force-pushed the create-format-object branch 2 times, most recently from 5934c1d to 8a8027c Compare June 9, 2024 11:14
@TerryHowe TerryHowe force-pushed the create-format-object branch from 8a8027c to 1a64e75 Compare June 9, 2024 11:31
Copy link
Contributor

@qweeah qweeah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should exclude FormatTypeText from oras discover

cmd/oras/root/discover.go Outdated Show resolved Hide resolved
@qweeah
Copy link
Contributor

qweeah commented Jun 12, 2024

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 oras attach as an example, code changes in command with default text output would be like:

- opts.AllowedTypes = []*option.FormatType{option.FormatTypeJSON, option.FormatTypeGoTemplate}
+ opts.SetTypes(option.FormatTypeText, option.FormatTypeJSON, option.FormatTypeGoTemplate)

For oras discover, the changes can be:

- 	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"),
-	}
+	)

Copy link
Member Author

@TerryHowe TerryHowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Nice, thanks!

@TerryHowe TerryHowe requested a review from qweeah June 17, 2024 15:10
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with suggestions and questions.

cmd/oras/internal/option/format.go Outdated Show resolved Hide resolved
cmd/oras/internal/option/format.go Outdated Show resolved Hide resolved
Copy link
Contributor

@qweeah qweeah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TerryHowe TerryHowe merged commit 4440be1 into oras-project:main Jun 18, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants