Skip to content
Open
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
25 changes: 20 additions & 5 deletions cmd/dbc/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ var dbcDocsUrl = "https://docs.columnar.tech/dbc/"

// Support drivers without a docs URL defined in the index
var fallbackDriverDocsUrl = map[string]string{
"bigquery": "https://docs.adbc-drivers.org/drivers/bigquery",
"duckdb": "https://duckdb.org/docs/stable/clients/adbc",
"flightsql": "https://arrow.apache.org/adbc/current/driver/flight_sql.html",
"mssql": "https://docs.adbc-drivers.org/drivers/mssql",
"mysql": "https://docs.adbc-drivers.org/drivers/mysql",
"postgresql": "https://arrow.apache.org/adbc/current/driver/postgresql.html",
"redshift": "https://docs.adbc-drivers.org/drivers/redshift",
"snowflake": "https://arrow.apache.org/adbc/current/driver/snowflake.html",
"sqlite": "https://arrow.apache.org/adbc/current/driver/sqlite.html",
"trino": "https://docs.adbc-drivers.org/drivers/trino",
}

var openBrowserFunc = browser.OpenURL
Expand Down Expand Up @@ -99,20 +104,30 @@ func (m docsModel) openBrowserCmd(url string) tea.Cmd {
}
}

func (m docsModel) getDocsUrlFor(driver *dbc.Driver) string {
if driver.DocsUrl != "" {
return driver.DocsUrl
}
fallbackUrl, keyExists := m.fallbackUrls[driver.Path]
if keyExists && fallbackUrl != "" {
return fallbackUrl
}

return ""
}

func (m docsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case dbc.Driver:
m.drv = &msg
// TODO: Add logic for finding driver docs from index. For now, we only use
// fallback URLs.
url, keyExists := m.fallbackUrls[msg.Path]
if !keyExists {
docsUrl := m.getDocsUrlFor(m.drv)
if docsUrl == "" {
return m, func() tea.Msg {
return fmt.Errorf("no documentation available for driver `%s`", msg.Path)
}
} else {
return m, func() tea.Msg {
return docsUrlFound(url)
return docsUrlFound(docsUrl)
}
}

Expand Down
13 changes: 12 additions & 1 deletion cmd/dbc/docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (suite *SubcommandTestSuite) TestDocsNoDriverArgNoOpen() {
suite.Equal("", lastOpenedURL, "browser should not be opened with --no-open")
}

func (suite *SubcommandTestSuite) TestDocsDriverFoundWithDocs() {
func (suite *SubcommandTestSuite) TestDocsDriverFoundWithFallbackDocs() {
openBrowserFunc = mockOpenBrowserSuccess
lastOpenedURL = ""
fallbackDriverDocsUrl = testFallbackUrls
Expand Down Expand Up @@ -143,3 +143,14 @@ func (suite *SubcommandTestSuite) TestDocsBrowserOpenError() {

suite.Contains(output, "failed to open browser: browser not available")
}

func (suite *SubcommandTestSuite) TestDocsDriverFoundWithDocs() {
openBrowserFunc = mockOpenBrowserSuccess
lastOpenedURL = ""
fallbackDriverDocsUrl = testFallbackUrls

m := DocsCmd{Driver: "test-driver-docs-url"}.GetModel()
suite.runCmd(m)

suite.Equal("http://example.com", lastOpenedURL)
}
15 changes: 13 additions & 2 deletions cmd/dbc/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func (suite *SubcommandTestSuite) TestSearchCmd() {
"• test-driver-2 - This is another test driver\r\n"+
"• test-driver-manifest-only - This is manifest-only driver\r\n"+
"• test-driver-no-sig - Driver manifest missing Files.signature entry\r\n"+
"• test-driver-invalid-manifest - This is test driver with an invalid manfiest. See https://github.com/columnar-tech/dbc/issues/37.\r\n\r ", "", suite.runCmd(m))
"• test-driver-invalid-manifest - This is test driver with an invalid manfiest. See https://github.com/columnar-tech/dbc/issues/37.\r\n"+
"• test-driver-docs-url - This is manifest-only with its docs_url key set\r\n\r ", "", suite.runCmd(m))
}

func (suite *SubcommandTestSuite) TestSearchCmdWithInstalled() {
Expand All @@ -42,7 +43,8 @@ func (suite *SubcommandTestSuite) TestSearchCmdWithInstalled() {
suite.validateOutput("• test-driver-1 - This is a test driver [installed: env=>1.1.0]\r\n"+
"• test-driver-2 - This is another test driver\r\n• test-driver-manifest-only - This is manifest-only driver\r\n"+
"• test-driver-no-sig - Driver manifest missing Files.signature entry\r\n"+
"• test-driver-invalid-manifest - This is test driver with an invalid manfiest. See https://github.com/columnar-tech/dbc/issues/37.\r\n\r ", "", suite.runCmd(m))
"• test-driver-invalid-manifest - This is test driver with an invalid manfiest. See https://github.com/columnar-tech/dbc/issues/37.\r\n"+
"• test-driver-docs-url - This is manifest-only with its docs_url key set\r\n\r ", "", suite.runCmd(m))
}

func (suite *SubcommandTestSuite) TestSearchCmdVerbose() {
Expand All @@ -63,6 +65,9 @@ func (suite *SubcommandTestSuite) TestSearchCmdVerbose() {
"Available Versions:\r\n ╰── 1.0.0\r\n"+
"• test-driver-invalid-manifest\r\n Title: Test Driver Invalid Manifest\r\n "+
"Description: This is test driver with an invalid manfiest. See https://github.com/columnar-tech/dbc/issues/37.\r\n License: Apache-2.0\r\n "+
"Available Versions:\r\n ╰── 1.0.0\r\n"+
"• test-driver-docs-url\r\n Title: Test Driver With Docs URL Set\r\n "+
"Description: This is manifest-only with its docs_url key set\r\n License: Apache-2.0\r\n "+
"Available Versions:\r\n ╰── 1.0.0\r\n\r ", "", suite.runCmd(m))
}

Expand Down Expand Up @@ -98,5 +103,11 @@ func (suite *SubcommandTestSuite) TestSearchCmdVerboseWithInstalled() {
" Description: This is test driver with an invalid manfiest. See https://github.com/columnar-tech/dbc/issues/37.\r\n"+
" License: Apache-2.0\r\n"+
" Available Versions:\r\n"+
" ╰── 1.0.0\r\n"+
"• test-driver-docs-url\r\n"+
" Title: Test Driver With Docs URL Set\r\n"+
" Description: This is manifest-only with its docs_url key set\r\n"+
" License: Apache-2.0\r\n"+
" Available Versions:\r\n"+
" ╰── 1.0.0\r\n\r ", "", suite.runCmd(m))
}
12 changes: 12 additions & 0 deletions cmd/dbc/testdata/test_index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,15 @@ drivers:
- platform: macos_arm64
- platform: windows_amd64
- platform: windows_arm64
- name: Test Driver With Docs URL Set
description: This is manifest-only with its docs_url key set
license: Apache-2.0
path: test-driver-docs-url
docs_url: http://example.com
pkginfo:
- version: v1.0.0
packages:
- platform: linux_amd64
- platform: macos_amd64
- platform: macos_arm64
- platform: windows_amd64
1 change: 1 addition & 0 deletions drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ type Driver struct {
License string `yaml:"license"`
Path string `yaml:"path"`
URLs []string `yaml:"urls"`
DocsUrl string `yaml:"docs_url"`
PkgInfo []pkginfo `yaml:"pkginfo"`
}

Expand Down
Loading