Skip to content

Commit 046d2e0

Browse files
authored
Add Description field to lib list output (#845)
* Add Description field to lib list output * [skip changelog] Fix lib list output Output columns are now smaller, sentence is cut if too long and renamed Sentence column to Description. * [skip changelog] Fixed lib list output on Windows
1 parent e2af8d5 commit 046d2e0

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

cli/lib/list.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ func (ir installedResult) String() string {
9090
}
9191

9292
t := table.New()
93-
t.SetHeader("Name", "Installed", "Available", "Location")
93+
t.SetHeader("Name", "Installed", "Available", "Location", "Description")
94+
t.SetColumnWidthMode(1, table.Average)
95+
t.SetColumnWidthMode(2, table.Average)
96+
t.SetColumnWidthMode(4, table.Average)
9497

9598
lastName := ""
9699
for _, libMeta := range ir.installedLibs {
@@ -109,11 +112,17 @@ func (ir installedResult) String() string {
109112

110113
if libMeta.GetRelease() != nil {
111114
available := libMeta.GetRelease().GetVersion()
112-
if available != "" {
113-
t.AddRow(name, lib.Version, available, location)
114-
} else {
115-
t.AddRow(name, lib.Version, "-", location)
115+
if available == "" {
116+
available = "-"
116117
}
118+
sentence := lib.Sentence
119+
if sentence == "" {
120+
sentence = "-"
121+
} else if len(sentence) > 40 {
122+
sentence = sentence[:37] + "..."
123+
}
124+
125+
t.AddRow(name, lib.Version, available, location, sentence)
117126
}
118127
}
119128

test/test_lib.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ def test_list(run_command):
3939
assert "" == result.stderr
4040
lines = result.stdout.strip().splitlines()
4141
assert 2 == len(lines)
42-
toks = [t.strip() for t in lines[1].split()]
42+
toks = [t.strip() for t in lines[1].split(maxsplit=4)]
43+
# Verifies the expected number of field
44+
assert 5 == len(toks)
4345
# be sure line contain the current version AND the available version
4446
assert "" != toks[1]
4547
assert "" != toks[2]
48+
# Verifies library sentence
49+
assert "An efficient and elegant JSON library..." == toks[4]
4650

4751
# Look at the JSON output
4852
result = run_command("lib list --format json")

0 commit comments

Comments
 (0)