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
2 changes: 1 addition & 1 deletion cmd/workspace/alerts/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
)

func listOverride(listCmd *cobra.Command, listReq *sql.ListAlertsRequest) {
func listOverride(listCmd *cobra.Command, _ *sql.ListAlertsRequest) {
listCmd.Annotations["template"] = cmdio.Heredoc(`
{{range .}}{{green "%s" .Id}} {{.DisplayName}} {{.State}}
{{end}}`)
Expand Down
4 changes: 2 additions & 2 deletions cmd/workspace/apps/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

func listOverride(listCmd *cobra.Command, listReq *apps.ListAppsRequest) {
func listOverride(listCmd *cobra.Command, _ *apps.ListAppsRequest) {
listCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "Name"}} {{header "Url"}} {{header "ComputeStatus"}} {{header "DeploymentStatus"}}`)
listCmd.Annotations["template"] = cmdio.Heredoc(`
Expand Down Expand Up @@ -41,7 +41,7 @@ func listOverride(listCmd *cobra.Command, listReq *apps.ListAppsRequest) {
tableview.RegisterConfig(listCmd, tableview.TableConfig{Columns: columns})
}

func listDeploymentsOverride(listDeploymentsCmd *cobra.Command, listDeploymentsReq *apps.ListAppDeploymentsRequest) {
func listDeploymentsOverride(listDeploymentsCmd *cobra.Command, _ *apps.ListAppDeploymentsRequest) {
listDeploymentsCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "DeploymentId"}} {{header "State"}} {{header "CreatedAt"}}`)
listDeploymentsCmd.Annotations["template"] = cmdio.Heredoc(`
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace/catalogs/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
)

func listOverride(listCmd *cobra.Command, listReq *catalog.ListCatalogsRequest) {
func listOverride(listCmd *cobra.Command, _ *catalog.ListCatalogsRequest) {
listCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "Name"}} {{header "Type"}} {{header "Comment"}}`)
listCmd.Annotations["template"] = cmdio.Heredoc(`
Expand Down
18 changes: 18 additions & 0 deletions cmd/workspace/cluster-policies/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cluster_policies

import (
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/tableview"
"github.com/databricks/databricks-sdk-go/service/compute"
"github.com/spf13/cobra"
)
Expand All @@ -10,6 +11,23 @@ func listOverride(listCmd *cobra.Command, _ *compute.ListClusterPoliciesRequest)
listCmd.Annotations["template"] = cmdio.Heredoc(`
{{range .}}{{.PolicyId | green}} {{.Name}}
{{end}}`)

columns := []tableview.ColumnDef{
{Header: "Policy ID", Extract: func(v any) string {
return v.(compute.Policy).PolicyId
}},
{Header: "Name", Extract: func(v any) string {
return v.(compute.Policy).Name
}},
{Header: "Default", Extract: func(v any) string {
if v.(compute.Policy).IsDefault {
return "yes"
}
return ""
}},
}

tableview.RegisterConfig(listCmd, tableview.TableConfig{Columns: columns})
}

func getOverride(getCmd *cobra.Command, _ *compute.GetClusterPolicyRequest) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace/external-locations/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
)

func listOverride(listCmd *cobra.Command, listReq *catalog.ListExternalLocationsRequest) {
func listOverride(listCmd *cobra.Command, _ *catalog.ListExternalLocationsRequest) {
listCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "Name"}} {{header "Credential"}} {{header "URL"}}`)
listCmd.Annotations["template"] = cmdio.Heredoc(`
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace/jobs/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func listOverride(listCmd *cobra.Command, listReq *jobs.ListJobsRequest) {
})
}

func listRunsOverride(listRunsCmd *cobra.Command, listRunsReq *jobs.ListRunsRequest) {
func listRunsOverride(listRunsCmd *cobra.Command, _ *jobs.ListRunsRequest) {
listRunsCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "Job ID"}} {{header "Run ID"}} {{header "Result State"}} URL`)
listRunsCmd.Annotations["template"] = cmdio.Heredoc(`
Expand Down
25 changes: 25 additions & 0 deletions cmd/workspace/lakeview/overrides.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
package lakeview

import (
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/tableview"
"github.com/databricks/databricks-sdk-go/service/dashboards"
"github.com/spf13/cobra"
)

func listOverride(listCmd *cobra.Command, _ *dashboards.ListDashboardsRequest) {
listCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "Dashboard ID"}} {{header "Name"}} {{header "State"}}`)
listCmd.Annotations["template"] = cmdio.Heredoc(`
{{range .}}{{green "%s" .DashboardId}} {{.DisplayName}} {{blue "%s" .LifecycleState}}
{{end}}`)

columns := []tableview.ColumnDef{
{Header: "Dashboard ID", Extract: func(v any) string {
return v.(dashboards.Dashboard).DashboardId
}},
{Header: "Name", Extract: func(v any) string {
return v.(dashboards.Dashboard).DisplayName
}},
{Header: "State", Extract: func(v any) string {
return string(v.(dashboards.Dashboard).LifecycleState)
}},
}

tableview.RegisterConfig(listCmd, tableview.TableConfig{Columns: columns})
}

func publishOverride(cmd *cobra.Command, req *dashboards.PublishRequest) {
originalRunE := cmd.RunE
cmd.RunE = func(cmd *cobra.Command, args []string) error {
Expand All @@ -15,5 +39,6 @@ func publishOverride(cmd *cobra.Command, req *dashboards.PublishRequest) {
}

func init() {
listOverrides = append(listOverrides, listOverride)
publishOverrides = append(publishOverrides, publishOverride)
}
26 changes: 26 additions & 0 deletions cmd/workspace/pipelines/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,34 @@ func listPipelinesOverride(listCmd *cobra.Command, listReq *pipelines.ListPipeli
})
}

func listPipelineEventsOverride(listCmd *cobra.Command, _ *pipelines.ListPipelineEventsRequest) {
listCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "Timestamp"}} {{header "Level"}} {{header "Event Type"}} {{header "Message"}}`)
listCmd.Annotations["template"] = cmdio.Heredoc(`
{{range .}}{{.Timestamp}} {{.Level}} {{.EventType}} {{.Message}}
{{end}}`)

columns := []tableview.ColumnDef{
{Header: "Timestamp", Extract: func(v any) string {
return v.(pipelines.PipelineEvent).Timestamp
}},
{Header: "Level", Extract: func(v any) string {
return string(v.(pipelines.PipelineEvent).Level)
}},
{Header: "Event Type", Extract: func(v any) string {
return v.(pipelines.PipelineEvent).EventType
}},
{Header: "Message", MaxWidth: 60, Extract: func(v any) string {
return v.(pipelines.PipelineEvent).Message
}},
}

tableview.RegisterConfig(listCmd, tableview.TableConfig{Columns: columns})
}

func init() {
listPipelinesOverrides = append(listPipelinesOverrides, listPipelinesOverride)
listPipelineEventsOverrides = append(listPipelineEventsOverrides, listPipelineEventsOverride)

cmdOverrides = append(cmdOverrides, func(cli *cobra.Command) {
// all auto-generated commands apart from nonManagementCommands go into 'management' group
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace/repos/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/spf13/cobra"
)

func listOverride(listCmd *cobra.Command, listReq *workspace.ListReposRequest) {
func listOverride(listCmd *cobra.Command, _ *workspace.ListReposRequest) {
listCmd.Annotations["template"] = cmdio.Heredoc(`
{{range .}}{{green "%d" .Id}} {{.Path}} {{.Branch|blue}} {{.Url|cyan}}
{{end}}`)
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace/schemas/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
)

func listOverride(listCmd *cobra.Command, listReq *catalog.ListSchemasRequest) {
func listOverride(listCmd *cobra.Command, _ *catalog.ListSchemasRequest) {
listCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "Full Name"}} {{header "Owner"}} {{header "Comment"}}`)
listCmd.Annotations["template"] = cmdio.Heredoc(`
Expand Down
29 changes: 29 additions & 0 deletions cmd/workspace/secrets/overrides.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package secrets

import (
"time"

"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/tableview"
"github.com/databricks/databricks-sdk-go/service/workspace"
"github.com/spf13/cobra"
)
Expand All @@ -16,6 +19,17 @@ func listScopesOverride(listScopesCmd *cobra.Command) {
listScopesCmd.Annotations["template"] = cmdio.Heredoc(`
{{range .}}{{.Name|green}} {{.BackendType}}
{{end}}`)

columns := []tableview.ColumnDef{
{Header: "Scope", Extract: func(v any) string {
return v.(workspace.SecretScope).Name
}},
{Header: "Backend Type", Extract: func(v any) string {
return string(v.(workspace.SecretScope).BackendType)
}},
}

tableview.RegisterConfig(listScopesCmd, tableview.TableConfig{Columns: columns})
}

func listSecretsOverride(listSecretsCommand *cobra.Command, _ *workspace.ListSecretsRequest) {
Expand All @@ -24,6 +38,21 @@ func listSecretsOverride(listSecretsCommand *cobra.Command, _ *workspace.ListSec
listSecretsCommand.Annotations["template"] = cmdio.Heredoc(`
{{range .}}{{.Key|green}} {{.LastUpdatedTimestamp}}
{{end}}`)

columns := []tableview.ColumnDef{
{Header: "Key", Extract: func(v any) string {
return v.(workspace.SecretMetadata).Key
}},
{Header: "Last Updated", Extract: func(v any) string {
ts := v.(workspace.SecretMetadata).LastUpdatedTimestamp
if ts == 0 {
return ""
}
return time.UnixMilli(ts).UTC().Format("2006-01-02 15:04:05")
}},
}

tableview.RegisterConfig(listSecretsCommand, tableview.TableConfig{Columns: columns})
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace/tables/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
)

func listOverride(listCmd *cobra.Command, listReq *catalog.ListTablesRequest) {
func listOverride(listCmd *cobra.Command, _ *catalog.ListTablesRequest) {
listCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "Full Name"}} {{header "Table Type"}}`)
listCmd.Annotations["template"] = cmdio.Heredoc(`
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace/volumes/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
)

func listOverride(listCmd *cobra.Command, listReq *catalog.ListVolumesRequest) {
func listOverride(listCmd *cobra.Command, _ *catalog.ListVolumesRequest) {
listCmd.Annotations["template"] = cmdio.Heredoc(`
{{range .}}{{green "%s" .Name}} {{.VolumeType}} {{.FullName}}
{{end}}`)
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace/warehouses/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
)

func listOverride(listCmd *cobra.Command, listReq *sql.ListWarehousesRequest) {
func listOverride(listCmd *cobra.Command, _ *sql.ListWarehousesRequest) {
listCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "ID"}} {{header "Name"}} {{header "Size"}} {{header "State"}}`)
listCmd.Annotations["template"] = cmdio.Heredoc(`
Expand Down
7 changes: 5 additions & 2 deletions libs/tableview/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import "context"

// ColumnDef defines a column in the TUI table.
type ColumnDef struct {
Header string // Display name in header row.
MaxWidth int // Max cell width; 0 = default (50).
Header string // Display name in header row.
// MaxWidth caps cell display width; 0 = default (50). Values exceeding
// this limit are destructively truncated with "..." in the rendered
// output. Horizontal scrolling does not recover the hidden portion.
MaxWidth int
Extract func(v any) string // Extracts cell value from typed SDK struct.
}

Expand Down
28 changes: 25 additions & 3 deletions libs/tableview/paginated.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
seq int
}

// PaginatedModel is the exported alias used by callers (e.g. RenderIterator)
// to inspect the final model returned by tea.Program.Run().
type PaginatedModel = paginatedModel

type paginatedModel struct {
cfg *TableConfig
headers []string
Expand Down Expand Up @@ -77,6 +81,11 @@
limitReached bool
}

// Err returns the error recorded during data fetching, if any.
func (m paginatedModel) Err() error {
return m.err
}

// newFetchCmdFunc returns a closure that creates fetch commands, capturing ctx.
func newFetchCmdFunc(ctx context.Context) func(paginatedModel) tea.Cmd {
return func(m paginatedModel) tea.Cmd {
Expand Down Expand Up @@ -151,12 +160,20 @@
// RunPaginated launches the paginated TUI table.
func RunPaginated(ctx context.Context, w io.Writer, cfg *TableConfig, iter RowIterator, maxItems int) error {
p := NewPaginatedProgram(ctx, w, cfg, iter, maxItems)
_, err := p.Run()
return err
finalModel, err := p.Run()
if err != nil {
return err
}
if m, ok := finalModel.(PaginatedModel); ok {
if fetchErr := m.Err(); fetchErr != nil {
return fetchErr
}
}
return nil
}

// Err returns any error that occurred during data fetching.
func (m paginatedModel) Err() error {

Check failure on line 176 in libs/tableview/paginated.go

View workflow job for this annotation

GitHub Actions / lint

method paginatedModel.Err already declared at libs/tableview/paginated.go:85:25 (typecheck)

Check failure on line 176 in libs/tableview/paginated.go

View workflow job for this annotation

GitHub Actions / validate-generated-is-up-to-date

method paginatedModel.Err already declared at libs/tableview/paginated.go:85:25

Check failure on line 176 in libs/tableview/paginated.go

View workflow job for this annotation

GitHub Actions / make test (linux, terraform)

method paginatedModel.Err already declared at libs/tableview/paginated.go:85:25

Check failure on line 176 in libs/tableview/paginated.go

View workflow job for this annotation

GitHub Actions / make test (linux, direct)

method paginatedModel.Err already declared at libs/tableview/paginated.go:85:25

Check failure on line 176 in libs/tableview/paginated.go

View workflow job for this annotation

GitHub Actions / make test (windows, direct)

method paginatedModel.Err already declared at libs\tableview\paginated.go:85:25

Check failure on line 176 in libs/tableview/paginated.go

View workflow job for this annotation

GitHub Actions / make test (windows, terraform)

method paginatedModel.Err already declared at libs\tableview\paginated.go:85:25

Check failure on line 176 in libs/tableview/paginated.go

View workflow job for this annotation

GitHub Actions / make test (macos, terraform)

method paginatedModel.Err already declared at libs/tableview/paginated.go:85:25

Check failure on line 176 in libs/tableview/paginated.go

View workflow job for this annotation

GitHub Actions / make test (macos, direct)

method paginatedModel.Err already declared at libs/tableview/paginated.go:85:25
return m.err
}

Expand Down Expand Up @@ -263,7 +280,12 @@
}
fmt.Fprintln(tw, strings.Join(seps, "\t"))

// Data rows
// Data rows.
// NOTE: MaxWidth truncation here is destructive, not display wrapping.
// Values exceeding MaxWidth are cut and suffixed with "..." in the
// rendered output. Horizontal scrolling cannot recover the hidden tail.
// A future improvement could store full values and only truncate the
// visible slice, but that requires per-cell width tracking.
for _, row := range m.rows {
vals := make([]string, len(m.headers))
for i := range m.headers {
Expand Down
8 changes: 8 additions & 0 deletions libs/tableview/paginated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ func TestPaginatedFetchError(t *testing.T) {
assert.Equal(t, "network error", pm.err.Error())
}

func TestPaginatedErrAccessor(t *testing.T) {
m := newTestModel(t, nil, 0)
assert.NoError(t, m.Err())

m.err = errors.New("api timeout")
assert.EqualError(t, m.Err(), "api timeout")
}

func TestPaginatedCursorMovement(t *testing.T) {
m := newTestModel(t, nil, 0)
m.ready = true
Expand Down
Loading