Skip to content

enhancing artifact view command #485

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
115 changes: 115 additions & 0 deletions pkg/views/artifact/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
}

func ViewArtifact(artifact *models.Artifact) {
showBasicInfo(artifact)
//for extra details
fmt.Println("\n[Artifact Details]")
showExtraInfo(artifact)
//show addon data if available
if artifact.AdditionLinks != nil {
fmt.Println("\n[Additional Information]")
for key := range artifact.AdditionLinks {
fmt.Printf("- %s available\n", key)
}

Check warning on line 49 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L40-L49

Added lines #L40 - L49 were not covered by tests
}
}

func showBasicInfo(artifact *models.Artifact) {

Check warning on line 53 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L53

Added line #L53 was not covered by tests
var rows []table.Row

pushTime, _ := utils.FormatCreatedTime(artifact.PushTime.String())
Expand Down Expand Up @@ -71,3 +85,104 @@
os.Exit(1)
}
}

func showExtraInfo(artifact *models.Artifact) {
fmt.Printf("RepositoryID: %d\n", artifact.RepositoryID)
fmt.Printf("Media Type: %s\n", artifact.MediaType)

if artifact.ExtraAttrs != nil {
var configSection map[string]any
if arch, ok := artifact.ExtraAttrs["architecture"].(string); ok {
fmt.Printf("Architecture: %s\n", arch)
}

Check warning on line 97 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L89-L97

Added lines #L89 - L97 were not covered by tests

if os, ok := artifact.ExtraAttrs["os"].(string); ok {
fmt.Printf("OS: %s\n", os)
}

Check warning on line 101 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L99-L101

Added lines #L99 - L101 were not covered by tests

if config, ok := artifact.ExtraAttrs["config"].(map[string]any); ok {
configSection = config
if author, ok := config["author"].(string); ok {
fmt.Printf("Author: %s\n", author)
}

Check warning on line 107 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L103-L107

Added lines #L103 - L107 were not covered by tests
}

if created, ok := artifact.ExtraAttrs["created"].(string); ok {
fmt.Printf("Created: %s\n", created)
}

Check warning on line 112 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L110-L112

Added lines #L110 - L112 were not covered by tests

if layers, ok := artifact.ExtraAttrs["layers"].([]any); ok {
fmt.Printf("Layers: %d\n", len(layers))
}

Check warning on line 116 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L114-L116

Added lines #L114 - L116 were not covered by tests

if configSection != nil {
fmt.Println("\n[Config Details]")

//for env variables if available
if env, ok := configSection["Env"].([]any); ok && len(env) > 0 {
fmt.Println("Environment Variables:")
for _, e := range env {
fmt.Printf(" - %s\n", e)
}

Check warning on line 126 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L118-L126

Added lines #L118 - L126 were not covered by tests
}

//for exposed ports if available
if ports, ok := configSection["ExposedPorts"].(map[string]any); ok {
fmt.Println("Exposed Ports:")
for port := range ports {
fmt.Printf(" - %s\n", port)
}

Check warning on line 134 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L130-L134

Added lines #L130 - L134 were not covered by tests
}

//for volumes if available
if volumes, ok := configSection["Volumes"].(map[string]any); ok {
fmt.Println("Volumes:")
for volume := range volumes {
fmt.Printf(" - %s\n", volume)
}

Check warning on line 142 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L138-L142

Added lines #L138 - L142 were not covered by tests
}

if entrypoint, ok := configSection["Entrypoint"].([]any); ok {
fmt.Printf("Entrypoint: %v\n", entrypoint)
}

Check warning on line 147 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L145-L147

Added lines #L145 - L147 were not covered by tests

if cmd, ok := configSection["Cmd"].([]any); ok {
fmt.Printf("Command: %v\n", cmd)
}

Check warning on line 151 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L149-L151

Added lines #L149 - L151 were not covered by tests
}

//for labels in config
if configSection != nil {
if labels, ok := configSection["Labels"].(map[string]any); ok && len(labels) > 0 {
fmt.Println("\n[Labels]")
for key, value := range labels {
fmt.Printf("%s: %v\n", key, value)
}

Check warning on line 160 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L155-L160

Added lines #L155 - L160 were not covered by tests
}
}

//for other interesting fields
fmt.Println("\n[Other Attributes]")
for key, value := range artifact.ExtraAttrs {
//skipping already displayed ones
if key == "architecture" || key == "os" || key == "config" ||
key == "created" || key == "layers" {
continue

Check warning on line 170 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L165-L170

Added lines #L165 - L170 were not covered by tests
}

switch v := value.(type) {
case string, bool, int, int64, float64:
fmt.Printf("%s: %v\n", key, v)
default:
fmt.Printf("%s: (complex data available)\n", key)

Check warning on line 177 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L173-L177

Added lines #L173 - L177 were not covered by tests
}
}
}

if len(artifact.References) > 0 {
fmt.Println("\n[References]")
for _, ref := range artifact.References {
fmt.Printf("%s: %s\n", ref.Platform.Architecture, ref.ChildDigest)
}

Check warning on line 186 in pkg/views/artifact/view/view.go

View check run for this annotation

Codecov / codecov/patch

pkg/views/artifact/view/view.go#L182-L186

Added lines #L182 - L186 were not covered by tests
}
}