Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Make image inspect more in line with other tables #701

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
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
28 changes: 7 additions & 21 deletions internal/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,43 +92,43 @@ func printTable(out io.Writer, appInfo appInfo) error {
for _, service := range appInfo.Services {
fmt.Fprintf(w, "%s\t%d\t%s\t%s\n", service.Name, service.Replicas, service.Ports, service.Image)
}
}, "Service", "Replicas", "Ports", "Image")
}, "SERVICE", "REPLICAS", "PORTS", "IMAGE")

// Add Network section
printSection(out, len(appInfo.Networks), func(w io.Writer) {
for _, name := range appInfo.Networks {
fmt.Fprintln(w, name)
}
}, "Network")
}, "NETWORK")

// Add Volume section
printSection(out, len(appInfo.Volumes), func(w io.Writer) {
for _, name := range appInfo.Volumes {
fmt.Fprintln(w, name)
}
}, "Volume")
}, "VOLUME")

// Add Secret section
printSection(out, len(appInfo.Secrets), func(w io.Writer) {
for _, name := range appInfo.Secrets {
fmt.Fprintln(w, name)
}
}, "Secret")
}, "SECRET")

// Add Parameter section
printSection(out, len(appInfo.parametersKeys), func(w io.Writer) {
for _, k := range appInfo.parametersKeys {
fmt.Fprintf(w, "%s\t%s\n", k, appInfo.Parameters[k])
}
}, "Parameter", "Value")
}, "PARAMETER", "VALUE")

// Add Attachments section
printSection(out, len(appInfo.Attachments), func(w io.Writer) {
for _, attachment := range appInfo.Attachments {
sizeString := units.HumanSize(float64(attachment.Size))
fmt.Fprintf(w, "%s\t%s\n", attachment.Path, sizeString)
}
}, "Attachment", "Size")
}, "ATTACHMENT", "SIZE")
return nil
}

Expand All @@ -146,25 +146,11 @@ func printSection(out io.Writer, len int, printer func(io.Writer), headers ...st
}
fmt.Fprintln(out)
w := tabwriter.NewWriter(out, 0, 0, 1, ' ', 0)
var plural string
Copy link
Contributor

Choose a reason for hiding this comment

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

😢

Copy link
Member Author

Choose a reason for hiding this comment

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

Buh-bye 👋

if len > 1 {
plural = "s"
}
headers[0] = fmt.Sprintf("%s%s (%d)", headers[0], plural, len)
printHeaders(w, headers...)
fmt.Fprintln(w, strings.Join(headers, "\t"))
printer(w)
w.Flush()
}

func printHeaders(w io.Writer, headers ...string) {
fmt.Fprintln(w, strings.Join(headers, "\t"))
dashes := make([]string, len(headers))
for i, h := range headers {
dashes[i] = strings.Repeat("-", len(h))
}
fmt.Fprintln(w, strings.Join(dashes, "\t"))
}

func getAppInfo(app *types.App, config *composetypes.Config, argParameters map[string]string) (appInfo, error) {
services := []service{}
for _, s := range config.Services {
Expand Down
28 changes: 11 additions & 17 deletions internal/inspect/testdata/inspect-full.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,25 @@ maintainers:
email: dev@example.com


Services (2) Replicas Ports Image
------------ -------- ----- -----
web1 2 8080-8100 nginx:latest
web2 2 9080-9100 nginx:latest
SERVICE REPLICAS PORTS IMAGE
web1 2 8080-8100 nginx:latest
web2 2 9080-9100 nginx:latest

Networks (2)
------------
NETWORK
my-network1
my-network2

Volumes (2)
-----------
VOLUME
my-volume1
my-volume2

Secrets (2)
-----------
SECRET
my-secret1
my-secret2

Parameters (2) Value
-------------- -----
port 8080
text hello
PARAMETER VALUE
port 8080
text hello

Attachment (1) Size
-------------- ----
config.cfg 9B
ATTACHMENT SIZE
config.cfg 9B
10 changes: 4 additions & 6 deletions internal/inspect/testdata/inspect-overridden.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ description: ""
maintainers: []


Service (1) Replicas Ports Image
----------- -------- ----- -----
web 1 80 nginx
SERVICE REPLICAS PORTS IMAGE
web 1 80 nginx

Parameter (1) Value
------------- -----
web.port 80
PARAMETER VALUE
web.port 80