Skip to content

Commit 00f688f

Browse files
committed
Add some UX improvements to list
1 parent 85a6f8b commit 00f688f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

internal/server/commands/list.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (l *list) Run(tty io.ReadWriter, args ...string) error {
6161
sc := value.(ssh.Conn)
6262
id := fmt.Sprintf("%s", idStr)
6363

64-
if filter == "" || flags['a'] {
64+
if filter == "" {
6565
toReturn = append(toReturn, displayItem{id: id, sc: sc})
6666
return true
6767
}
@@ -92,31 +92,40 @@ func (l *list) Run(tty io.ReadWriter, args ...string) error {
9292
return nil
9393
}
9494

95-
sep := " "
95+
sep := ", "
9696
if flags['l'] {
9797
sep = "\n"
9898
}
9999

100-
for _, tr := range toReturn {
100+
for i, tr := range toReturn {
101101

102102
if !flags['n'] && !flags['i'] && !flags['a'] {
103-
fmt.Fprintf(tty, "%s%s", tr.id, sep)
103+
fmt.Fprint(tty, tr.id)
104+
if i != len(toReturn) {
105+
fmt.Fprint(tty, sep)
106+
}
104107
continue
105108
}
106109

107110
if flags['a'] {
108-
fmt.Fprintf(tty, "%s", tr.id)
111+
fmt.Fprint(tty, tr.id)
109112
}
110113

111114
if flags['n'] || flags['a'] {
112-
fmt.Fprintf(tty, " %s", tr.sc.User())
115+
fmt.Fprint(tty, " "+tr.sc.User())
113116
}
114117

115118
if flags['i'] || flags['a'] {
116-
fmt.Fprintf(tty, " %s", tr.sc.RemoteAddr().String())
119+
fmt.Fprint(tty, " "+tr.sc.RemoteAddr().String())
120+
}
121+
122+
if i != len(toReturn) {
123+
fmt.Fprint(tty, sep)
117124
}
125+
}
118126

119-
fmt.Fprintf(tty, "%s", sep)
127+
if !flags['l'] {
128+
fmt.Fprint(tty, "\n")
120129
}
121130

122131
return nil
@@ -129,7 +138,7 @@ func (l *list) Help(explain bool) string {
129138
return makeHelpText(
130139
"ls [OPTION] [FILTER]",
131140
"Filter uses glob matching against all attributes of a target (hostname, ip, id)",
132-
"\t-a\tShow all attributes of all hosts",
141+
"\t-a\tShow all attributes",
133142
"\t-n\tShow only hostnames",
134143
"\t-i\tShow only IP",
135144
"\t-t\tPrint all attributes in pretty table",

0 commit comments

Comments
 (0)