-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathoverrides.go
More file actions
56 lines (49 loc) · 1.71 KB
/
overrides.go
File metadata and controls
56 lines (49 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package jobs
import (
"context"
"strconv"
"github.com/databricks/cli/libs/cmdctx"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/tableview"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/spf13/cobra"
)
func listOverride(listCmd *cobra.Command, listReq *jobs.ListJobsRequest) {
listCmd.Annotations["template"] = cmdio.Heredoc(`
{{range .}}{{green "%d" .JobId}} {{.Settings.Name}}
{{end}}`)
columns := []tableview.ColumnDef{
{Header: "Job ID", Extract: func(v any) string {
return strconv.FormatInt(v.(jobs.BaseJob).JobId, 10)
}},
{Header: "Name", Extract: func(v any) string {
if v.(jobs.BaseJob).Settings != nil {
return v.(jobs.BaseJob).Settings.Name
}
return ""
}},
}
tableview.RegisterConfig(listCmd, tableview.TableConfig{
Columns: columns,
Search: &tableview.SearchConfig{
Placeholder: "Search by exact name...",
NewIterator: func(ctx context.Context, query string) tableview.RowIterator {
req := *listReq
req.Name = query
w := cmdctx.WorkspaceClient(ctx)
return tableview.WrapIterator(w.Jobs.List(ctx, req), columns)
},
},
})
}
func listRunsOverride(listRunsCmd *cobra.Command, listRunsReq *jobs.ListRunsRequest) {
listRunsCmd.Annotations["headerTemplate"] = cmdio.Heredoc(`
{{header "Job ID"}} {{header "Run ID"}} {{header "Result State"}} URL`)
listRunsCmd.Annotations["template"] = cmdio.Heredoc(`
{{range .}}{{green "%d" .JobId}} {{cyan "%d" .RunId}} {{if eq .State.ResultState "SUCCESS"}}{{"SUCCESS"|green}}{{else}}{{red "%s" .State.ResultState}}{{end}} {{.RunPageUrl}}
{{end}}`)
}
func init() {
listOverrides = append(listOverrides, listOverride)
listRunsOverrides = append(listRunsOverrides, listRunsOverride)
}