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

feat: support --format in manifest fetch command #1295

Merged
merged 46 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
67dad87
feat: support `--format` in `manifest fetch` command
qweeah Mar 18, 2024
fa0f2a1
add comment
qweeah Mar 18, 2024
d832fbe
Merge remote-tracking branch 'upstream/main' into format-manifest-fetch
qweeah Mar 19, 2024
3669aff
Merge remote-tracking branch 'upstream/main' into format-manifest-fetch
qweeah Mar 19, 2024
fc2bccc
Merge remote-tracking branch 'upstream/main' into format-manifest-fetch
qweeah Apr 1, 2024
e9c1226
refactor
qweeah Apr 1, 2024
9c73b0d
Merge remote-tracking branch 'upstream/main' into format-manifest-fetch
qweeah Apr 1, 2024
6614c92
use new printer
qweeah Apr 1, 2024
eb5f62d
bug fix
qweeah Apr 1, 2024
ce6bc89
fix struct fields with json tags
qweeah Apr 2, 2024
5dc8583
Merge remote-tracking branch 'upstream/main' into format-manifest-fetch
qweeah Apr 3, 2024
c13ee29
remove raw discarder
qweeah Apr 3, 2024
4b1e2f9
fix e2e
qweeah Apr 3, 2024
5689580
Merge remote-tracking branch 'upstream/main' into format-manifest-fetch
qweeah Apr 7, 2024
c7488d6
fix e2e
qweeah Apr 7, 2024
42ab0a3
refactor
qweeah Apr 7, 2024
d954405
add discard handler for raw output
qweeah Apr 7, 2024
00a5895
Merge remote-tracking branch 'upstream/main' into format-manifest-fetch
qweeah Apr 7, 2024
7460060
revert focus
qweeah Apr 7, 2024
de6acf1
rename to content handler
qweeah Apr 7, 2024
4709b62
fix e2e
qweeah Apr 7, 2024
3fcab69
add e2e
qweeah Apr 7, 2024
f8c2dbf
fix e2e
qweeah Apr 7, 2024
90a3141
use unmarshal and enhance e2e
qweeah Apr 8, 2024
ca0f082
code clean
qweeah Apr 8, 2024
a1addb4
resolve comments
qweeah Apr 8, 2024
998ad76
fix e2e
qweeah Apr 8, 2024
f93ba89
code clean
qweeah Apr 8, 2024
e66ed8e
Merge remote-tracking branch 'upstream/main' into format-manifest-fetch
qweeah Apr 8, 2024
a7656be
Merge remote-tracking branch 'upstream/main' into format-manifest-fetch
qweeah Apr 8, 2024
b54a2e6
code clean
qweeah Apr 8, 2024
e682458
code clean
qweeah Apr 8, 2024
faa8c63
code clean
qweeah Apr 8, 2024
9c3a426
Merge remote-tracking branch 'upstream/main' into format-manifest-fetch
qweeah Apr 9, 2024
4eb5b9f
add fetched model
qweeah Apr 10, 2024
3cbbf9b
add experimental mark
qweeah Apr 10, 2024
7b09792
fix e2e
qweeah Apr 10, 2024
cb98a26
fix e2e
qweeah Apr 10, 2024
6615478
resolve comments
qweeah Apr 10, 2024
a8c3de8
add json test
qweeah Apr 10, 2024
1dfd284
fix e2e
qweeah Apr 10, 2024
dfb8dce
resolve comments
qweeah Apr 10, 2024
6c5e2cf
resolve comments
qweeah Apr 10, 2024
bb69b39
add e2e coverage
qweeah Apr 10, 2024
57d2078
remove used code
qweeah Apr 10, 2024
4ec65f9
use create file instead of open file
qweeah Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
code clean
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Apr 8, 2024
commit faa8c636ac88c81752415b18f91fb893e5020db6
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
"oras.land/oras/cmd/oras/internal/display/utils"
)

// ManifestFetchHandler handles metadata descriptor output.
type ManifestFetch struct {
// manifestFetchHandler handles metadata descriptor output.
type manifestFetchHandler struct {
pretty bool
out io.Writer
}

// OnFetched implements ManifestFetchHandler.
func (h *ManifestFetch) OnFetched(desc ocispec.Descriptor, _ []byte) error {
func (h *manifestFetchHandler) OnFetched(desc ocispec.Descriptor, _ []byte) error {
descBytes, err := json.Marshal(desc)
if err != nil {
return fmt.Errorf("invalid descriptor: %w", err)

Check warning on line 38 in cmd/oras/internal/display/metadata/descriptor/manifest_fetch.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/metadata/descriptor/manifest_fetch.go#L38

Added line #L38 was not covered by tests
}
return utils.Output(h.out, descBytes, h.pretty)
}

// NewManifestFetchHandler creates a new handler.
func NewManifestFetchHandler(out io.Writer, pretty bool) metadata.ManifestFetchHandler {
return &ManifestFetch{
return &manifestFetchHandler{
pretty: pretty,
out: out,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@
"oras.land/oras/cmd/oras/internal/display/metadata"
)

// ManifestFetchHandler handles JSON metadata output for manifest fetch events.
type ManifestFetchHandler struct {
// manifestFetchHandler handles JSON metadata output for manifest fetch events.
type manifestFetchHandler struct {
template string
out io.Writer
}

// NewManifestFetchHandler creates a new handler for manifest fetch events.
func NewManifestFetchHandler(out io.Writer, template string) metadata.ManifestFetchHandler {
return &ManifestFetchHandler{
return &manifestFetchHandler{
template: template,
out: out,
}
}

// OnFetched is called after the manifest fetch is completed.
func (h *ManifestFetchHandler) OnFetched(desc ocispec.Descriptor, content []byte) error {
func (h *manifestFetchHandler) OnFetched(desc ocispec.Descriptor, content []byte) error {
var manifest map[string]any
if err := json.Unmarshal(content, &manifest); err != nil {
return err

Check warning on line 44 in cmd/oras/internal/display/metadata/template/manifest_fetch.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/metadata/template/manifest_fetch.go#L44

Added line #L44 was not covered by tests
}
// return parseAndWrite(h.out, model.ToMappable(reflect.ValueOf(manifest)), h.template)
qweeah marked this conversation as resolved.
Show resolved Hide resolved
return parseAndWrite(h.out, manifest, h.template)
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/internal/display/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
"fmt"
"io"

v1 "github.com/opencontainers/image-spec/specs-go/v1"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

// GenerateContentKey generates a unique key for each content descriptor, using
// its digest and name if applicable.
func GenerateContentKey(desc v1.Descriptor) string {
return desc.Digest.String() + desc.Annotations[v1.AnnotationTitle]
func GenerateContentKey(desc ocispec.Descriptor) string {
return desc.Digest.String() + desc.Annotations[ocispec.AnnotationTitle]

Check warning on line 30 in cmd/oras/internal/display/utils/utils.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/utils/utils.go#L29-L30

Added lines #L29 - L30 were not covered by tests
}

const (
Expand All @@ -42,12 +42,12 @@
// Output writes the data to the output stream, optionally prettifying it.
func Output(out io.Writer, data []byte, pretty bool) error {
qweeah marked this conversation as resolved.
Show resolved Hide resolved
if pretty {
buf := bytes.NewBuffer(nil)
if err := json.Indent(buf, data, "", " "); err != nil {
return fmt.Errorf("failed to prettify: %w", err)

Check warning on line 47 in cmd/oras/internal/display/utils/utils.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/utils/utils.go#L45-L47

Added lines #L45 - L47 were not covered by tests
}
buf.WriteByte('\n')
data = buf.Bytes()

Check warning on line 50 in cmd/oras/internal/display/utils/utils.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/utils/utils.go#L49-L50

Added lines #L49 - L50 were not covered by tests
}
_, err := out.Write(data)
return err
Expand Down
Loading