Skip to content
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

Associate generated commands with command groups #475

Merged
merged 3 commits into from
Jun 15, 2023
Merged
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
11 changes: 9 additions & 2 deletions .codegen/cmds-account.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ var accountCmd = &cobra.Command{

func init() {
root.RootCmd.AddCommand(accountCmd)
{{range .Services}}{{if .IsAccounts}}{{if not (in $excludes .KebabName) }}
accountCmd.AddCommand({{.SnakeName}}.Cmd){{end}}{{end}}{{end}}

{{range .Services}}{{if .IsAccounts}}{{if not (in $excludes .KebabName) -}}
accountCmd.AddCommand({{.SnakeName}}.Cmd)
{{end}}{{end}}{{end}}

// Register commands with groups
{{range .Services}}{{if .IsAccounts}}{{if not (in $excludes .KebabName) -}}
{{.SnakeName}}.Cmd.GroupID = "{{ .Package.Name }}"
{{end}}{{end}}{{end}}
}
12 changes: 9 additions & 3 deletions .codegen/cmds-workspace.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.

package cmd
package workspace

{{$excludes := list "command-execution" "statement-execution" "dbfs" "dbsql-permissions"}}

Expand All @@ -11,6 +11,12 @@ import (
)

func init() {
{{range .Services}}{{if not .IsAccounts}}{{if not (in $excludes .KebabName) }}
root.RootCmd.AddCommand({{.SnakeName}}.Cmd){{end}}{{end}}{{end}}
{{range .Services}}{{if not .IsAccounts}}{{if not (in $excludes .KebabName) -}}
root.RootCmd.AddCommand({{.SnakeName}}.Cmd)
{{end}}{{end}}{{end}}

// Register commands with groups
{{range .Services}}{{if not .IsAccounts}}{{if not (in $excludes .KebabName) -}}
{{.SnakeName}}.Cmd.GroupID = "{{ .Package.Name }}"
{{end}}{{end}}{{end}}
}
27 changes: 27 additions & 0 deletions cmd/account/cmd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions cmd/account/groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package account

import "github.com/spf13/cobra"

// Groups returns an ordered list of command groups.
// The order matches the order used in the Databricks API explorer.
func Groups() []cobra.Group {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you propagate it from x-databricks-groups from spec? otherwise, it'll get out of sync. Please also pull in descriptions from there:

...
  "x-databricks-groups" : [ {
    "x-databricks-package" : "workspace",
    "name" : "Databricks Workspace",
    "description" : "Manage workspace-level entities that include notebooks, Git checkouts, and secrets",
    "tags" : [ "Git Credentials", "Repos", "Secret", "Workspace" ]
  }, {
    "x-databricks-package" : "compute",
    "name" : "Compute",
    "description" : "Use and configure compute for Databricks",
    "tags" : [ "Cluster Policies", "Clusters", "Command Execution", "Global Init Scripts", "Instance Pools", "Instance Profiles", "ManagedLibraries", "Policy Families" ]
  }, {
...

you'll have to add it to codegen and expose from there https://github.com/databricks/databricks-sdk-go/blob/main/openapi/model.go#L41-L46

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in person. This list of packages is incomplete so we need to hardcode it here. Once it is complete and we expose it in the OpenAPI code in the SDK then we can autogenerate these as well.

return []cobra.Group{
{
ID: "iam",
Title: "Identity and Access Management",
},
{
ID: "catalog",
Title: "Unity Catalog",
},
{
ID: "settings",
Title: "Settings",
},
{
ID: "provisioning",
Title: "Provisioning",
},
{
ID: "billing",
Title: "Billing",
},
{
ID: "oauth2",
Title: "OAuth",
},
}
}

func init() {
// Register groups with parent command
groups := Groups()
for i := range groups {
accountCmd.AddGroup(&groups[i])
}
}
54 changes: 52 additions & 2 deletions cmd/workspace/cmd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions cmd/workspace/groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package workspace

import (
"github.com/databricks/cli/cmd/root"
"github.com/spf13/cobra"
)

// Groups returns an ordered list of command groups.
// The order matches the order used in the Databricks API explorer.
func Groups() []cobra.Group {
return []cobra.Group{
{
ID: "workspace",
Title: "Databricks Workspace",
},
{
ID: "compute",
Title: "Compute",
},
{
ID: "jobs",
Title: "Jobs",
},
{
ID: "pipelines",
Title: "Delta Live Tables",
},
{
ID: "ml",
Title: "Machine Learning",
},
{
ID: "serving",
Title: "Real-time Serving",
},
{
ID: "iam",
Title: "Identity and Access Management",
},
{
ID: "sql",
Title: "Databricks SQL",
},
{
ID: "catalog",
Title: "Unity Catalog",
},
{
ID: "sharing",
Title: "Delta Sharing",
},
{
ID: "settings",
Title: "Settings",
},
}
}

func init() {
// Register groups with parent command
groups := Groups()
for i := range groups {
root.RootCmd.AddGroup(&groups[i])
}
}