-
Notifications
You must be signed in to change notification settings - Fork 163
Add endless-scrolling TUI table for interactive list commands #4729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 32 commits
e672906
d7a7104
8b589d1
b7ca3d8
aa4cdb0
dbd2241
831b105
229baa9
78e6720
78b56b7
96e614a
3143a72
a548b79
43c526d
4281953
b3a6a53
7b4c0ee
aaf150e
5709b10
ed23efc
c7fb162
ffe9d6a
ed87880
8d63e1a
649f435
ff16f2b
f755a0e
be88c2e
673d24e
a9cc00e
d4fe4fb
c185c98
8e7674f
bcf339d
d967b28
046f656
da84d97
baaf1a8
4404611
5767ea3
c0f314e
a8b2626
56e3829
4981680
e269ea3
83662c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package alerts | ||
|
|
||
| import ( | ||
| "github.com/databricks/cli/libs/cmdio" | ||
| "github.com/databricks/cli/libs/tableview" | ||
| "github.com/databricks/databricks-sdk-go/service/sql" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func listOverride(listCmd *cobra.Command, _ *sql.ListAlertsRequest) { | ||
| listCmd.Annotations["template"] = cmdio.Heredoc(` | ||
| {{range .}}{{green "%s" .Id}} {{.DisplayName}} {{.State}} | ||
| {{end}}`) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need the template if we also use the tableview?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the template is the fallback for non-interactive output (piped, |
||
|
|
||
| columns := []tableview.ColumnDef{ | ||
| {Header: "ID", Extract: func(v any) string { | ||
| return v.(sql.ListAlertsResponseAlert).Id | ||
| }}, | ||
| {Header: "Name", Extract: func(v any) string { | ||
| return v.(sql.ListAlertsResponseAlert).DisplayName | ||
| }}, | ||
| {Header: "State", Extract: func(v any) string { | ||
| return string(v.(sql.ListAlertsResponseAlert).State) | ||
| }}, | ||
| } | ||
|
|
||
| tableview.RegisterConfig(listCmd, tableview.TableConfig{Columns: columns}) | ||
| } | ||
|
|
||
| func init() { | ||
| listOverrides = append(listOverrides, listOverride) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package apps | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/libs/tableview" | ||
| sdkapps "github.com/databricks/databricks-sdk-go/service/apps" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestListTableConfig(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why test here and not other commands?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apps has nested pointer dereferences ( |
||
| cmd := newList() | ||
|
|
||
| cfg := tableview.GetConfig(cmd) | ||
| require.NotNil(t, cfg) | ||
| require.Len(t, cfg.Columns, 4) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| app sdkapps.App | ||
| wantName string | ||
| wantURL string | ||
| wantCompute string | ||
| wantDeploy string | ||
| }{ | ||
| { | ||
| name: "with nested fields", | ||
| app: sdkapps.App{ | ||
| Name: "test-app", | ||
| Url: "https://example.com", | ||
| ComputeStatus: &sdkapps.ComputeStatus{ | ||
| State: sdkapps.ComputeStateActive, | ||
| }, | ||
| ActiveDeployment: &sdkapps.AppDeployment{ | ||
| Status: &sdkapps.AppDeploymentStatus{ | ||
| State: sdkapps.AppDeploymentStateSucceeded, | ||
| }, | ||
| }, | ||
| }, | ||
| wantName: "test-app", | ||
| wantURL: "https://example.com", | ||
| wantCompute: "ACTIVE", | ||
| wantDeploy: "SUCCEEDED", | ||
| }, | ||
| { | ||
| name: "nil nested fields", | ||
| app: sdkapps.App{ | ||
| Name: "test-app", | ||
| Url: "https://example.com", | ||
| ActiveDeployment: &sdkapps.AppDeployment{}, | ||
| }, | ||
| wantName: "test-app", | ||
| wantURL: "https://example.com", | ||
| wantCompute: "", | ||
| wantDeploy: "", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| assert.Equal(t, tt.wantName, cfg.Columns[0].Extract(tt.app)) | ||
| assert.Equal(t, tt.wantURL, cfg.Columns[1].Extract(tt.app)) | ||
| assert.Equal(t, tt.wantCompute, cfg.Columns[2].Extract(tt.app)) | ||
| assert.Equal(t, tt.wantDeploy, cfg.Columns[3].Extract(tt.app)) | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing mechanism to pass information from the autogen'd commands (or the overrides) into the command is via the annotations. This adds another mechanism.
I'm not biased to either but we should maintain a single system for associating static info with commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Removed
WithCommand/CommandFromContextand now thread*cobra.Commandas an explicit parameter toRenderIterator. The registry (RegisterConfig/GetConfig) is the only new mechanism, annotations still handle templates.