Skip to content
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
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, listReq *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 @@ -47,8 +47,34 @@ func listPipelinesOverride(listCmd *cobra.Command, listReq *pipelines.ListPipeli
})
}

func listPipelineEventsOverride(listCmd *cobra.Command, listReq *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
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 (
"strconv"

"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 strconv.FormatInt(ts, 10)
}},
}

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

func init() {
Expand Down
Loading