diff --git a/cmd/dbc/docs.go b/cmd/dbc/docs.go index 3e284246..4e752fdb 100644 --- a/cmd/dbc/docs.go +++ b/cmd/dbc/docs.go @@ -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 @@ -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) } } diff --git a/cmd/dbc/docs_test.go b/cmd/dbc/docs_test.go index 376fb169..54266c53 100644 --- a/cmd/dbc/docs_test.go +++ b/cmd/dbc/docs_test.go @@ -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 @@ -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) +} diff --git a/cmd/dbc/search_test.go b/cmd/dbc/search_test.go index 8aa5b3ef..f313d624 100644 --- a/cmd/dbc/search_test.go +++ b/cmd/dbc/search_test.go @@ -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() { @@ -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() { @@ -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)) } @@ -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)) } diff --git a/cmd/dbc/testdata/test_index.yaml b/cmd/dbc/testdata/test_index.yaml index 7f27abf9..b178d0f7 100644 --- a/cmd/dbc/testdata/test_index.yaml +++ b/cmd/dbc/testdata/test_index.yaml @@ -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 diff --git a/drivers.go b/drivers.go index 6c20ccb6..a4db4b6b 100644 --- a/drivers.go +++ b/drivers.go @@ -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"` }