Skip to content

Commit 31f2e15

Browse files
authored
fix(search): improve output for non-verbose (#248)
supercedes #222 Improves the output of `dbc search` when not using verbose mode: <img width="1979" height="462" alt="image" src="https://github.com/user-attachments/assets/349e4f34-e1dd-4e4a-9b9f-28532db12c87" />
1 parent 689bd62 commit 31f2e15

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

cmd/dbc/driver_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestUnmarshalDriverList(t *testing.T) {
4141
{"less", "[drivers]\nflightsql = {version = '<=1.8.0'}", []dbc.PkgInfo{
4242
{Driver: dbc.Driver{Path: "flightsql"}, Version: semver.MustParse("1.8.0")},
4343
}, nil},
44-
{"greater", "[drivers]\nflightsql = {version = '>=1.8.0'}", []dbc.PkgInfo{
44+
{"greater", "[drivers]\nflightsql = {version = '>=1.8.0, <1.10.0'}", []dbc.PkgInfo{
4545
{Driver: dbc.Driver{Path: "flightsql"}, Version: semver.MustParse("1.9.0")},
4646
}, nil},
4747
}

cmd/dbc/search.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
tea "github.com/charmbracelet/bubbletea"
2323
"github.com/charmbracelet/lipgloss"
2424
"github.com/charmbracelet/lipgloss/list"
25+
"github.com/charmbracelet/lipgloss/table"
2526
"github.com/charmbracelet/lipgloss/tree"
2627
"github.com/columnar-tech/dbc"
2728
"github.com/columnar-tech/dbc/config"
@@ -115,6 +116,8 @@ func viewDrivers(d []dbc.Driver, verbose bool) string {
115116
installedStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("241"))
116117

117118
l := list.New()
119+
t := table.New().Border(lipgloss.HiddenBorder()).
120+
BorderTop(false).BorderBottom(false).BorderLeft(false).BorderRight(false)
118121
for _, driver := range d {
119122
var installed []string
120123
installedVerbose := make(map[string][]string)
@@ -135,11 +138,11 @@ func viewDrivers(d []dbc.Driver, verbose bool) string {
135138
var regTag string
136139
if driver.Registry.Name != "" {
137140
regTag = registryStyle.Render(" [" + driver.Registry.Name + "]")
138-
suffix += regTag
139141
}
140142

141143
if !verbose {
142-
l.Item(nameStyle.Render(driver.Path) + " - " + descStyle.Render(driver.Desc) + suffix)
144+
t.Row(nameStyle.Render(driver.Path)+regTag,
145+
descStyle.Render(driver.Desc), suffix)
143146
continue
144147
}
145148

@@ -171,6 +174,9 @@ func viewDrivers(d []dbc.Driver, verbose bool) string {
171174
).Enumerator(emptyEnumerator))
172175
}
173176

177+
if !verbose {
178+
return t.String() + "\n"
179+
}
174180
return l.String() + "\n"
175181
}
176182

cmd/dbc/search_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ func (suite *SubcommandTestSuite) TestSearchCmd() {
2424
m := SearchCmd{}.GetModelCustom(
2525
baseModel{getDriverRegistry: getTestDriverRegistry,
2626
downloadPkg: downloadTestPkg})
27-
suite.validateOutput("\r ", "• test-driver-1 - This is a test driver\n"+
28-
"• test-driver-2 - This is another test driver\n"+
29-
"• test-driver-manifest-only - This is manifest-only driver\n"+
30-
"• test-driver-no-sig - Driver manifest missing Files.signature entry\n"+
31-
"• test-driver-invalid-manifest - This is test driver with an invalid manifest. See https://github.com/columnar-tech/dbc/issues/37.\n"+
32-
"• test-driver-docs-url - This is manifest-only with its docs_url key set\n", suite.runCmd(m))
27+
suite.validateOutput("\r ",
28+
"test-driver-1 This is a test driver \n"+
29+
"test-driver-2 This is another test driver \n"+
30+
"test-driver-manifest-only This is manifest-only driver \n"+
31+
"test-driver-no-sig Driver manifest missing Files.signature entry \n"+
32+
"test-driver-invalid-manifest This is test driver with an invalid manifest. See https://github.com/columnar-tech/dbc/issues/37. \n"+
33+
"test-driver-docs-url This is manifest-only with its docs_url key set \n", suite.runCmd(m))
3334
}
3435

3536
func (suite *SubcommandTestSuite) TestSearchCmdWithInstalled() {
@@ -40,12 +41,13 @@ func (suite *SubcommandTestSuite) TestSearchCmdWithInstalled() {
4041
m = SearchCmd{}.GetModelCustom(
4142
baseModel{getDriverRegistry: getTestDriverRegistry,
4243
downloadPkg: downloadTestPkg})
43-
suite.validateOutput("\r ", "• test-driver-1 - This is a test driver [installed: env=>1.1.0]\n"+
44-
"• test-driver-2 - This is another test driver\n"+
45-
"• test-driver-manifest-only - This is manifest-only driver\n"+
46-
"• test-driver-no-sig - Driver manifest missing Files.signature entry\n"+
47-
"• test-driver-invalid-manifest - This is test driver with an invalid manifest. See https://github.com/columnar-tech/dbc/issues/37.\n"+
48-
"• test-driver-docs-url - This is manifest-only with its docs_url key set\n", suite.runCmd(m))
44+
suite.validateOutput("\r ",
45+
"test-driver-1 This is a test driver [installed: env=>1.1.0]\n"+
46+
"test-driver-2 This is another test driver \n"+
47+
"test-driver-manifest-only This is manifest-only driver \n"+
48+
"test-driver-no-sig Driver manifest missing Files.signature entry \n"+
49+
"test-driver-invalid-manifest This is test driver with an invalid manifest. See https://github.com/columnar-tech/dbc/issues/37. \n"+
50+
"test-driver-docs-url This is manifest-only with its docs_url key set \n", suite.runCmd(m))
4951
}
5052

5153
func (suite *SubcommandTestSuite) TestSearchCmdVerbose() {

0 commit comments

Comments
 (0)