-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathcmd.go
More file actions
120 lines (104 loc) · 3.1 KB
/
cmd.go
File metadata and controls
120 lines (104 loc) · 3.1 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package cmd
import (
"context"
"strings"
"github.com/databricks/cli/cmd/psql"
aitoolscmd "github.com/databricks/cli/experimental/aitools/cmd"
ssh "github.com/databricks/cli/experimental/ssh/cmd"
"github.com/databricks/cli/cmd/account"
"github.com/databricks/cli/cmd/api"
"github.com/databricks/cli/cmd/auth"
"github.com/databricks/cli/cmd/bundle"
"github.com/databricks/cli/cmd/cache"
"github.com/databricks/cli/cmd/completion"
"github.com/databricks/cli/cmd/configure"
"github.com/databricks/cli/cmd/experimental"
"github.com/databricks/cli/cmd/fs"
"github.com/databricks/cli/cmd/labs"
"github.com/databricks/cli/cmd/pipelines"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/cmd/selftest"
"github.com/databricks/cli/cmd/sync"
"github.com/databricks/cli/cmd/version"
"github.com/databricks/cli/cmd/workspace"
"github.com/databricks/cli/libs/cmdgroup"
"github.com/spf13/cobra"
)
const (
mainGroup = "main"
permissionsGroup = "permissions"
)
// configureGroups adds groups to the command, only if a group
// has at least one available command.
func configureGroups(cmd *cobra.Command, groups []cobra.Group) {
filteredGroups := cmdgroup.FilterGroups(groups, cmd.Commands())
for i := range filteredGroups {
cmd.AddGroup(&filteredGroups[i])
}
}
func accountCommand() *cobra.Command {
cmd := account.New()
configureGroups(cmd, account.Groups())
return cmd
}
func New(ctx context.Context) *cobra.Command {
cli := root.New(ctx)
// Add account subcommand.
cli.AddCommand(accountCommand())
// Add workspace subcommands.
workspaceCommands := workspace.All()
for _, cmd := range workspaceCommands {
// Order the permissions subcommands after the main commands.
for _, sub := range cmd.Commands() {
// some commands override groups in overrides.go, leave them as-is
if sub.GroupID != "" {
continue
}
switch {
case strings.HasSuffix(sub.Name(), "-permissions"), strings.HasSuffix(sub.Name(), "-permission-levels"):
sub.GroupID = permissionsGroup
default:
sub.GroupID = mainGroup
}
}
cli.AddCommand(cmd)
// Built-in groups for the workspace commands.
groups := []cobra.Group{
{
ID: mainGroup,
Title: "Available Commands",
},
{
ID: pipelines.ManagementGroupID,
Title: "Management Commands",
},
{
ID: permissionsGroup,
Title: "Permission Commands",
},
}
configureGroups(cmd, groups)
}
// Add other subcommands.
cli.AddCommand(aitoolscmd.NewAitoolsCmd())
cli.AddCommand(api.New())
cli.AddCommand(auth.New())
cli.AddCommand(completion.New())
cli.AddCommand(bundle.New())
cli.AddCommand(cache.New())
cli.AddCommand(experimental.New())
cli.AddCommand(psql.New())
cli.AddCommand(configure.New())
cli.AddCommand(fs.New())
cli.AddCommand(labs.New(ctx))
cli.AddCommand(sync.New())
cli.AddCommand(version.New())
cli.AddCommand(selftest.New())
cli.AddCommand(ssh.New())
// Add workspace command groups, filtering out empty groups or groups with only hidden commands.
configureGroups(cli, append(workspace.Groups(), cobra.Group{
ID: "development",
Title: "Developer Tools",
}))
return cli
}