2023-07-25 18:19:07 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-09-11 08:18:43 +00:00
|
|
|
"context"
|
2023-09-05 09:58:45 +00:00
|
|
|
"strings"
|
|
|
|
|
2023-07-25 18:19:07 +00:00
|
|
|
"github.com/databricks/cli/cmd/account"
|
2023-07-27 10:03:08 +00:00
|
|
|
"github.com/databricks/cli/cmd/api"
|
|
|
|
"github.com/databricks/cli/cmd/auth"
|
|
|
|
"github.com/databricks/cli/cmd/bundle"
|
|
|
|
"github.com/databricks/cli/cmd/configure"
|
|
|
|
"github.com/databricks/cli/cmd/fs"
|
2023-11-17 12:47:37 +00:00
|
|
|
"github.com/databricks/cli/cmd/labs"
|
2023-07-25 18:19:07 +00:00
|
|
|
"github.com/databricks/cli/cmd/root"
|
2023-07-27 10:03:08 +00:00
|
|
|
"github.com/databricks/cli/cmd/sync"
|
|
|
|
"github.com/databricks/cli/cmd/version"
|
2023-07-25 18:19:07 +00:00
|
|
|
"github.com/databricks/cli/cmd/workspace"
|
2024-08-15 13:23:07 +00:00
|
|
|
"github.com/databricks/cli/cmd/workspace/apps"
|
2023-07-25 18:19:07 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2023-09-05 09:58:45 +00:00
|
|
|
const (
|
|
|
|
mainGroup = "main"
|
|
|
|
permissionsGroup = "permissions"
|
|
|
|
)
|
|
|
|
|
2023-09-11 08:18:43 +00:00
|
|
|
func New(ctx context.Context) *cobra.Command {
|
|
|
|
cli := root.New(ctx)
|
2023-07-27 10:03:08 +00:00
|
|
|
|
|
|
|
// Add account subcommand.
|
|
|
|
cli.AddCommand(account.New())
|
|
|
|
|
|
|
|
// Add workspace subcommands.
|
|
|
|
for _, cmd := range workspace.All() {
|
2023-09-05 09:58:45 +00:00
|
|
|
// Built-in groups for the workspace commands.
|
|
|
|
groups := []cobra.Group{
|
|
|
|
{
|
|
|
|
ID: mainGroup,
|
|
|
|
Title: "Available Commands",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: permissionsGroup,
|
|
|
|
Title: "Permission Commands",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for i := range groups {
|
|
|
|
cmd.AddGroup(&groups[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
// Order the permissions subcommands after the main commands.
|
|
|
|
for _, sub := range cmd.Commands() {
|
|
|
|
switch {
|
|
|
|
case strings.HasSuffix(sub.Name(), "-permissions"), strings.HasSuffix(sub.Name(), "-permission-levels"):
|
|
|
|
sub.GroupID = permissionsGroup
|
|
|
|
default:
|
|
|
|
sub.GroupID = mainGroup
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
cli.AddCommand(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add workspace command groups.
|
|
|
|
groups := workspace.Groups()
|
|
|
|
for i := range groups {
|
|
|
|
cli.AddGroup(&groups[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add other subcommands.
|
|
|
|
cli.AddCommand(api.New())
|
2024-08-15 13:23:07 +00:00
|
|
|
cli.AddCommand(apps.New())
|
2023-07-27 10:03:08 +00:00
|
|
|
cli.AddCommand(auth.New())
|
|
|
|
cli.AddCommand(bundle.New())
|
|
|
|
cli.AddCommand(configure.New())
|
|
|
|
cli.AddCommand(fs.New())
|
2023-11-17 12:47:37 +00:00
|
|
|
cli.AddCommand(labs.New(ctx))
|
2023-07-27 10:03:08 +00:00
|
|
|
cli.AddCommand(sync.New())
|
|
|
|
cli.AddCommand(version.New())
|
|
|
|
|
|
|
|
return cli
|
2023-07-25 18:19:07 +00:00
|
|
|
}
|