oras-project / oras

OCI registry client - managing content like artifacts, images, packages
https://oras.land
Apache License 2.0
1.33k stars 161 forks source link

refactor: Create Printer object to manage output #1292

Closed TerryHowe closed 2 months ago

TerryHowe commented 3 months ago

What this PR does / why we need it:

Create a printer object to manage output

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 93.10345% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 82.02%. Comparing base (f1d319f) to head (4417131). Report is 19 commits behind head on main.

:exclamation: Current head 4417131 differs from pull request most recent head 1db763f. Consider uploading reports for the commit 1db763f to get more accurate results

Files Patch % Lines
cmd/oras/root/login.go 66.66% 1 Missing and 2 partials :warning:
cmd/oras/root/discover.go 87.50% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1292 +/- ## ========================================== + Coverage 81.94% 82.02% +0.07% ========================================== Files 83 83 Lines 4005 4022 +17 ========================================== + Hits 3282 3299 +17 Misses 500 500 Partials 223 223 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

qweeah commented 3 months ago

@TerryHowe I added a new Printer interface to display package to unify the output into STDOUT.

https://github.com/oras-project/oras/blob/61e0241fe11342ca27065b8e3cb4bf66ba142d15/cmd/oras/internal/display/metadata/view/printer.go#L33-L40

It provides PrintXXX to wrap fmt.FprintXXX utilities, also provides PrintJSON and ParseAndWrite for formatted output

To reflect your changes in #1288, cobra.Command.OutOrStdout can be injected via below interface https://github.com/oras-project/oras/blob/61e0241fe11342ca27065b8e3cb4bf66ba142d15/cmd/oras/internal/display/metadata/view/printer.go#L27-L31

Please help you help review related changes in #1310 and let me know your comment on this design, thanks.

qweeah commented 3 months ago

@TerryHowe I have added another solution in https://github.com/oras-project/oras/pull/1314, please let me know if it meets your expectation.