Skip to content

Commit 4e171cb

Browse files
committed
Output of cvdr list is clear to know the name of host, group, instance.
1 parent 845e5d9 commit 4e171cb

3 files changed

Lines changed: 37 additions & 32 deletions

File tree

e2etests/cvdr/cvdr_create_with_branch_test.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ cvdr create \
1818
# Check the output of cvdr list
1919
# TODO(b/448209030): cvdr list should print proper ADB connection status.
2020
ACTUAL_OUTPUT=$(cvdr list --host ${HOSTNAME})
21-
EXPECTED_OUTPUT="${HOSTNAME} (http://localhost:8080/v1/zones/local/hosts/${HOSTNAME}/)
22-
cvd/1
23-
Status: Running
24-
ADB: not connected
25-
Displays: [720 x 1280 ( 320 )]
26-
Logs: http://localhost:8080/v1/zones/local/hosts/${HOSTNAME}/cvds/cvd/1/logs/"
21+
EXPECTED_OUTPUT="Host: ${HOSTNAME}
22+
WebUI: http://localhost:8080/v1/zones/local/hosts/${HOSTNAME}/
23+
Group: cvd
24+
Instance: 1
25+
Status: Running
26+
ADB: not connected
27+
Displays: [720 x 1280 ( 320 )]
28+
Logs: http://localhost:8080/v1/zones/local/hosts/${HOSTNAME}/cvds/cvd/1/logs/"
2729
diff <(echo ${EXPECTED_OUTPUT}) <(echo ${ACTUAL_OUTPUT})
2830

2931
# Check ADB connection

e2etests/cvdr/cvdr_create_with_local_srcs_test.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ cvdr create \
2929
# Check the output of cvdr list
3030
# TODO(b/448209030): cvdr list should print proper ADB connection status.
3131
ACTUAL_OUTPUT=$(cvdr list --host ${HOSTNAME})
32-
EXPECTED_OUTPUT="${HOSTNAME} (http://localhost:8080/v1/zones/local/hosts/${HOSTNAME}/)
33-
cvd_1/1
34-
Status: Running
35-
ADB: not connected
36-
Displays: [720 x 1280 ( 320 )]
37-
Logs: http://localhost:8080/v1/zones/local/hosts/${HOSTNAME}/cvds/cvd_1/1/logs/"
32+
EXPECTED_OUTPUT="Host: ${HOSTNAME}
33+
WebUI: http://localhost:8080/v1/zones/local/hosts/${HOSTNAME}/
34+
Group: cvd_1
35+
Instance: 1
36+
Status: Running
37+
ADB: not connected
38+
Displays: [720 x 1280 ( 320 )]
39+
Logs: http://localhost:8080/v1/zones/local/hosts/${HOSTNAME}/cvds/cvd_1/1/logs/"
3840
diff <(echo ${EXPECTED_OUTPUT}) <(echo ${ACTUAL_OUTPUT})
3941

4042
# Check ADB connection

pkg/cli/cli.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -313,34 +313,35 @@ func (c *command) Parent() *command {
313313

314314
func WriteListCVDsOutput(w io.Writer, hosts []*RemoteHost) {
315315
for _, host := range hosts {
316-
fmt.Fprintln(w, hostOutput(host))
317-
if len(host.CVDs) == 0 {
318-
fmt.Fprintln(w, " ~~Empty~~ ")
319-
fmt.Fprintln(w, "")
320-
continue
321-
}
316+
hostOutput(w, host)
317+
cvdMap := make(map[string][]*RemoteCVD)
322318
for _, cvd := range host.CVDs {
323-
lines := cvdOutput(host, cvd)
324-
for _, l := range lines {
325-
fmt.Fprintln(w, " "+l)
319+
cvdMap[cvd.Group] = append(cvdMap[cvd.Group], cvd)
320+
}
321+
for group, cvds := range cvdMap {
322+
groupOutput(w, group)
323+
for _, cvd := range cvds {
324+
cvdOutput(w, host, cvd)
326325
}
327-
fmt.Fprintln(w)
328326
}
329327
}
330328
}
331329

332-
func hostOutput(h *RemoteHost) string {
333-
return fmt.Sprintf("%s (%s/)", h.Name, h.ServiceURL)
330+
func hostOutput(w io.Writer, h *RemoteHost) {
331+
fmt.Fprintf(w, "Host: %s\n", h.Name)
332+
fmt.Fprintf(w, " WebUI: %s/\n", h.ServiceURL)
334333
}
335334

336-
func cvdOutput(h *RemoteHost, c *RemoteCVD) []string {
337-
return []string{
338-
fmt.Sprintf("%s/%s", c.Group, c.Name),
339-
"Status: " + c.Status,
340-
"ADB: " + adbStateStr(c),
341-
"Displays: " + fmt.Sprintf("%v", c.Displays),
342-
"Logs: " + fmt.Sprintf("%s/cvds/%s/%s/logs/", h.ServiceURL, c.Group, c.Name),
343-
}
335+
func groupOutput(w io.Writer, group string) {
336+
fmt.Fprintf(w, " Group: %s\n", group)
337+
}
338+
339+
func cvdOutput(w io.Writer, h *RemoteHost, c *RemoteCVD) {
340+
fmt.Fprintf(w, " Instance: %s\n", c.Name)
341+
fmt.Fprintf(w, " Status: %s\n", c.Status)
342+
fmt.Fprintf(w, " ADB: %s\n", adbStateStr(c))
343+
fmt.Fprintf(w, " Displays: %v\n", c.Displays)
344+
fmt.Fprintf(w, " Logs: %s/cvds/%s/%s/logs/\n", h.ServiceURL, c.Group, c.Name)
344345
}
345346

346347
func adbStateStr(c *RemoteCVD) string {

0 commit comments

Comments
 (0)