From d16bf3a7b8a524949194d96d774bd989f6b83177 Mon Sep 17 00:00:00 2001 From: "pieter.noordhuis" Date: Wed, 11 Nov 2026 18:54:14 +0000 Subject: [PATCH] Build commands only when an invocation needs them Every invocation built the whole command tree (~1,750 commands and ~3,300 flags) before parsing its args, which took about 4 ms per run. Top-level commands are now declared as root.CommandSpec values. A root.Tree holds a placeholder built from each spec's fields, which are all its parent shows in help, completion, and suggestions, and Tree.Execute builds the commands that the args resolve to before running cobra. The tree owns the root command, and the functions that create and run a bare root command are now unexported, so commands can only be added as specs and the CLI can only run through Tree.Execute. root.NewCommand panics if building a command changes the fields its spec declares. Co-authored-by: Isaac --- cmd/account/access-control/access-control.go | 31 +- cmd/account/billable-usage/billable-usage.go | 32 +- cmd/account/budget-policy/budget-policy.go | 31 +- cmd/account/budgets/budgets.go | 31 +- cmd/account/cmd.go | 95 +++--- cmd/account/credentials/credentials.go | 31 +- .../csp-enablement-account.go | 29 +- .../custom-app-integration.go | 31 +- .../disable-legacy-features.go | 29 +- .../disaster-recovery/disaster-recovery.go | 29 +- .../enable-ip-access-lists.go | 33 ++- .../encryption-keys/encryption-keys.go | 31 +- cmd/account/endpoints/endpoints.go | 29 +- .../esm-enablement-account.go | 29 +- .../federation-policy/federation-policy.go | 31 +- cmd/account/groups-v2/groups-v2.go | 31 +- cmd/account/groups/groups.go | 30 +- cmd/account/iam-v2/iam-v2.go | 31 +- .../ip-access-lists/ip-access-lists.go | 31 +- .../llm-proxy-partner-powered-account.go | 31 +- .../llm-proxy-partner-powered-enforce.go | 33 ++- cmd/account/log-delivery/log-delivery.go | 31 +- .../metastore-assignments.go | 29 +- cmd/account/metastores/metastores.go | 31 +- .../network-connectivity.go | 31 +- .../network-policies/network-policies.go | 31 +- cmd/account/networks/networks.go | 32 +- .../o-auth-published-apps.go | 31 +- .../personal-compute/personal-compute.go | 33 ++- cmd/account/private-access/private-access.go | 30 +- .../private-network-gateways.go | 37 +-- .../published-app-integration.go | 31 +- .../service-principal-federation-policy.go | 31 +- .../service-principal-secrets.go | 31 +- .../service-principals-v2.go | 31 +- .../service-principals/service-principals.go | 30 +- cmd/account/settings-v2/settings-v2.go | 29 +- cmd/account/settings/settings.go | 44 +-- .../storage-credentials.go | 29 +- cmd/account/storage/storage.go | 31 +- .../usage-dashboards/usage-dashboards.go | 32 +- cmd/account/users-v2/users-v2.go | 31 +- cmd/account/users/users.go | 30 +- cmd/account/vpc-endpoints/vpc-endpoints.go | 30 +- .../workspace-assignment.go | 31 +- .../workspace-network-configuration.go | 31 +- cmd/account/workspaces/workspaces.go | 31 +- cmd/air/air.go | 24 +- cmd/air/air_test.go | 9 +- cmd/air/pools_test.go | 2 +- cmd/aitools/aitools.go | 22 +- cmd/aitools/install_test.go | 6 +- cmd/api/api.go | 14 +- cmd/auth/auth.go | 20 +- cmd/auth/auth_test.go | 32 +- cmd/auth/switch_test.go | 12 +- cmd/bundle/bundle.go | 24 +- cmd/cache/cache.go | 19 +- cmd/cmd.go | 140 ++++----- cmd/cmd_test.go | 18 -- cmd/completion/completion.go | 30 +- cmd/configure/configure.go | 26 +- cmd/configure/configure_test.go | 15 +- cmd/experimental/experimental.go | 24 +- cmd/fs/fs.go | 22 +- cmd/labs/labs.go | 19 +- cmd/psql/psql.go | 21 +- cmd/quickstart/quickstart.go | 25 +- cmd/root/auth_test.go | 36 +-- cmd/root/bundle_test.go | 6 +- cmd/root/cli_test.go | 50 ++++ cmd/root/command_spec.go | 68 +++++ cmd/root/command_spec_test.go | 46 +++ cmd/root/export_test.go | 13 + cmd/{ => root}/fuzz_panic_test.go | 5 +- cmd/root/root.go | 7 +- cmd/root/root_test.go | 10 +- cmd/root/tree.go | 132 +++++++++ cmd/root/tree_test.go | 111 +++++++ cmd/sandbox/sandbox.go | 25 +- cmd/selftest/selftest.go | 18 +- cmd/sync/sync.go | 19 +- cmd/sync/sync_test.go | 3 +- cmd/version/version.go | 21 +- .../access-control/access-control.go | 33 ++- cmd/workspace/agent-bricks/agent-bricks.go | 37 +-- cmd/workspace/agent-kit/agent-kit.go | 31 +- cmd/workspace/ai-functions/ai-functions.go | 29 +- cmd/workspace/ai-gateway/ai-gateway.go | 31 +- cmd/workspace/ai-search/ai-search.go | 31 +- .../aibi-dashboard-embedding-access-policy.go | 29 +- ...bi-dashboard-embedding-approved-domains.go | 29 +- cmd/workspace/alerts-legacy/alerts-legacy.go | 31 +- cmd/workspace/alerts-v2/alerts-v2.go | 29 +- cmd/workspace/alerts/alerts.go | 31 +- cmd/workspace/apps-settings/apps-settings.go | 37 +-- cmd/workspace/apps/apps.go | 31 +- .../artifact-allowlists.go | 31 +- .../automatic-cluster-update.go | 29 +- .../bundle-deployments/bundle-deployments.go | 33 ++- cmd/workspace/catalogs/catalogs.go | 31 +- .../clean-room-asset-revisions.go | 31 +- .../clean-room-assets/clean-room-assets.go | 31 +- .../clean-room-auto-approval-rules.go | 31 +- .../clean-room-task-runs.go | 31 +- cmd/workspace/clean-rooms/clean-rooms.go | 31 +- .../cluster-policies/cluster-policies.go | 31 +- cmd/workspace/clusters/clusters.go | 31 +- cmd/workspace/cmd.go | 279 +++++++++--------- .../compliance-security-profile.go | 29 +- .../compute-migrations/compute-migrations.go | 33 ++- cmd/workspace/connections/connections.go | 31 +- .../consumer-fulfillments.go | 29 +- .../consumer-installations.go | 31 +- .../consumer-listings/consumer-listings.go | 31 +- .../consumer-personalization-requests.go | 31 +- .../consumer-providers/consumer-providers.go | 29 +- .../credentials-manager.go | 37 +-- cmd/workspace/credentials/credentials.go | 31 +- cmd/workspace/current-user/current-user.go | 32 +- .../dashboard-email-subscriptions.go | 29 +- .../dashboard-widgets/dashboard-widgets.go | 35 ++- cmd/workspace/dashboards/dashboards.go | 31 +- .../data-classification.go | 31 +- cmd/workspace/data-quality/data-quality.go | 31 +- cmd/workspace/data-sources/data-sources.go | 32 +- cmd/workspace/database/database.go | 31 +- .../default-namespace/default-namespace.go | 29 +- .../default-warehouse-id.go | 33 ++- .../disable-legacy-access.go | 29 +- .../disable-legacy-dbfs.go | 29 +- cmd/workspace/domains/domains.go | 31 +- .../enable-export-notebook.go | 29 +- .../enable-notebook-table-clipboard.go | 29 +- .../enable-results-downloading.go | 29 +- .../enhanced-security-monitoring.go | 29 +- .../entity-tag-assignments.go | 31 +- cmd/workspace/environments/environments.go | 31 +- cmd/workspace/experiments/experiments.go | 31 +- .../external-lineage/external-lineage.go | 31 +- .../external-locations/external-locations.go | 31 +- .../external-metadata/external-metadata.go | 31 +- .../feature-engineering.go | 31 +- cmd/workspace/feature-store/feature-store.go | 35 ++- cmd/workspace/forecasting/forecasting.go | 37 +-- cmd/workspace/functions/functions.go | 31 +- cmd/workspace/genie-agents/genie-agents.go | 35 ++- cmd/workspace/genie/genie.go | 31 +- .../git-credentials/git-credentials.go | 31 +- .../global-init-scripts.go | 31 +- cmd/workspace/grants/grants.go | 31 +- cmd/workspace/groups-v2/groups-v2.go | 31 +- cmd/workspace/groups/groups.go | 30 +- .../instance-pools/instance-pools.go | 31 +- .../instance-profiles/instance-profiles.go | 31 +- .../ip-access-lists/ip-access-lists.go | 31 +- cmd/workspace/jobs/jobs.go | 31 +- .../knowledge-assistants.go | 31 +- .../lakeview-embedded/lakeview-embedded.go | 30 +- cmd/workspace/lakeview/lakeview.go | 31 +- cmd/workspace/lakewatch/lakewatch.go | 31 +- cmd/workspace/libraries/libraries.go | 31 +- .../llm-proxy-partner-powered-workspace.go | 33 ++- .../materialized-features.go | 37 +-- cmd/workspace/metastores/metastores.go | 31 +- .../model-registry/model-registry.go | 31 +- .../model-versions/model-versions.go | 31 +- .../notification-destinations.go | 31 +- cmd/workspace/online-tables/online-tables.go | 31 +- .../permission-migration.go | 37 +-- cmd/workspace/permissions/permissions.go | 32 +- cmd/workspace/pipelines/pipelines.go | 31 +- cmd/workspace/policies/policies.go | 31 +- .../policy-compliance-for-clusters.go | 31 +- .../policy-compliance-for-jobs.go | 31 +- .../policy-families/policy-families.go | 31 +- cmd/workspace/postgres/postgres.go | 31 +- .../provider-exchange-filters.go | 29 +- .../provider-exchanges/provider-exchanges.go | 31 +- .../provider-files/provider-files.go | 31 +- .../provider-listings/provider-listings.go | 31 +- .../provider-personalization-requests.go | 31 +- .../provider-provider-analytics-dashboards.go | 30 +- .../provider-providers/provider-providers.go | 29 +- cmd/workspace/providers/providers.go | 31 +- .../quality-monitor-v2/quality-monitor-v2.go | 31 +- .../quality-monitors/quality-monitors.go | 31 +- .../queries-legacy/queries-legacy.go | 31 +- cmd/workspace/queries/queries.go | 31 +- cmd/workspace/query-history/query-history.go | 32 +- .../query-visualizations-legacy.go | 35 ++- .../query-visualizations.go | 35 ++- .../recipient-activation.go | 32 +- .../recipient-federation-policies.go | 31 +- cmd/workspace/recipients/recipients.go | 31 +- cmd/workspace/redash-config/redash-config.go | 34 ++- .../registered-models/registered-models.go | 31 +- cmd/workspace/repos/repos.go | 31 +- .../resource-quotas/resource-quotas.go | 31 +- .../restrict-workspace-admins.go | 29 +- cmd/workspace/rfa/rfa.go | 31 +- cmd/workspace/sandbox/sandbox.go | 31 +- cmd/workspace/schemas/schemas.go | 31 +- cmd/workspace/secrets-uc/secrets-uc.go | 31 +- cmd/workspace/secrets/secrets.go | 31 +- .../serverless-compute-service.go | 33 ++- .../service-principal-secrets-proxy.go | 31 +- .../service-principals-v2.go | 31 +- .../service-principals/service-principals.go | 30 +- .../serving-endpoints/serving-endpoints.go | 31 +- cmd/workspace/settings/settings.go | 62 ++-- cmd/workspace/shares/shares.go | 31 +- .../software-artifacts/software-artifacts.go | 31 +- .../sql-results-download.go | 29 +- .../storage-credentials.go | 31 +- .../supervisor-agents/supervisor-agents.go | 31 +- .../system-schemas/system-schemas.go | 31 +- .../table-constraints/table-constraints.go | 31 +- cmd/workspace/tables/tables.go | 31 +- cmd/workspace/tag-policies/tag-policies.go | 31 +- .../temporary-path-credentials.go | 31 +- .../temporary-table-credentials.go | 32 +- .../temporary-volume-credentials.go | 32 +- .../token-management/token-management.go | 31 +- cmd/workspace/tokens/tokens.go | 31 +- cmd/workspace/users-v2/users-v2.go | 31 +- cmd/workspace/users/users.go | 30 +- .../vector-search-endpoints.go | 29 +- .../vector-search-indexes.go | 31 +- cmd/workspace/volumes/volumes.go | 31 +- cmd/workspace/warehouses/warehouses.go | 31 +- .../workspace-bindings/workspace-bindings.go | 31 +- .../workspace-conf/workspace-conf.go | 29 +- .../workspace-entity-tag-assignments.go | 29 +- .../workspace-iam-v2/workspace-iam-v2.go | 31 +- .../workspace-settings-v2.go | 29 +- cmd/workspace/workspace/workspace.go | 31 +- experimental/ssh/cmd/ssh.go | 24 +- .../cligen/templates/cmds-account.go.tmpl | 25 +- .../cligen/templates/cmds-workspace.go.tmpl | 15 +- internal/cligen/templates/service.go.tmpl | 59 ++-- internal/testcli/runner.go | 5 +- libs/cmdgroup/command.go | 17 ++ main.go | 3 +- main_test.go | 17 -- 245 files changed, 4432 insertions(+), 3402 deletions(-) delete mode 100644 cmd/cmd_test.go create mode 100644 cmd/root/cli_test.go create mode 100644 cmd/root/command_spec.go create mode 100644 cmd/root/command_spec_test.go create mode 100644 cmd/root/export_test.go rename cmd/{ => root}/fuzz_panic_test.go (98%) create mode 100644 cmd/root/tree.go create mode 100644 cmd/root/tree_test.go diff --git a/cmd/account/access-control/access-control.go b/cmd/account/access-control/access-control.go index 3be9b6579cb..7aa6814a0c3 100644 --- a/cmd/account/access-control/access-control.go +++ b/cmd/account/access-control/access-control.go @@ -3,6 +3,7 @@ package access_control import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,22 +18,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "access-control", - Short: `*Public Preview* These APIs manage access rules on resources in an account.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "access-control", + Short: `*Public Preview* These APIs manage access rules on resources in an account.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. These APIs manage access rules on resources in an account. Currently, only grant rules are supported. A grant rule specifies a role assigned to a set of - principals. A list of rules attached to a resource is called a rule set.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } + principals. A list of rules attached to a resource is called a rule set.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newGetAssignableRolesForResource()) @@ -43,8 +48,6 @@ These APIs manage access rules on resources in an account. Currently, only for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-assignable-roles-for-resource command diff --git a/cmd/account/billable-usage/billable-usage.go b/cmd/account/billable-usage/billable-usage.go index b7d0365fb63..2a454940498 100644 --- a/cmd/account/billable-usage/billable-usage.go +++ b/cmd/account/billable-usage/billable-usage.go @@ -3,6 +3,8 @@ package billable_usage import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -14,19 +16,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "billable-usage", - Short: `This API allows you to download billable usage logs for the specified account and date range.`, - Long: `This API allows you to download billable usage logs for the specified account - and date range. This feature works with all account types.`, - GroupID: "billing", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "billable-usage", + Short: `This API allows you to download billable usage logs for the specified account and date range.`, + GroupID: "billing", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This API allows you to download billable usage logs for the specified account + and date range. This feature works with all account types.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newDownload()) @@ -35,8 +41,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start download command diff --git a/cmd/account/budget-policy/budget-policy.go b/cmd/account/budget-policy/budget-policy.go index 917f23548dc..f445489d3ca 100644 --- a/cmd/account/budget-policy/budget-policy.go +++ b/cmd/account/budget-policy/budget-policy.go @@ -3,6 +3,7 @@ package budget_policy import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,20 +18,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "budget-policy", - Short: `*Public Preview* A service serves REST API about Budget policies.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "budget-policy", + Short: `*Public Preview* A service serves REST API about Budget policies.`, + GroupID: "billing", + Build: buildCommand, +} -A service serves REST API about Budget policies`, - GroupID: "billing", - RunE: root.ReportUnknownSubcommand, - } +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" +A service serves REST API about Budget policies` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreate()) @@ -43,8 +48,6 @@ A service serves REST API about Budget policies`, for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/budgets/budgets.go b/cmd/account/budgets/budgets.go index bd9231ad755..b2886bf8170 100644 --- a/cmd/account/budgets/budgets.go +++ b/cmd/account/budgets/budgets.go @@ -3,6 +3,7 @@ package budgets import ( + "context" "errors" "fmt" @@ -18,21 +19,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "budgets", - Short: `These APIs manage budget configurations for this account.`, - Long: `These APIs manage budget configurations for this account. Budgets enable you +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "budgets", + Short: `These APIs manage budget configurations for this account.`, + GroupID: "billing", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage budget configurations for this account. Budgets enable you to monitor usage across your account. You can set up budgets to either track account-wide spending, or apply filters to track the spending of specific - teams, projects, or workspaces.`, - GroupID: "billing", - RunE: root.ReportUnknownSubcommand, - } + teams, projects, or workspaces.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -47,8 +52,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/cmd.go b/cmd/account/cmd.go index 74709c06020..b06e376c3bd 100644 --- a/cmd/account/cmd.go +++ b/cmd/account/cmd.go @@ -3,6 +3,9 @@ package account import ( + "context" + + "github.com/databricks/cli/cmd/root" "github.com/spf13/cobra" account_access_control "github.com/databricks/cli/cmd/account/access-control" @@ -47,52 +50,52 @@ import ( account_users "github.com/databricks/cli/cmd/account/users" ) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "account", - Short: `Databricks Account Commands`, - } - - cmd.AddCommand(account_access_control.New()) - cmd.AddCommand(billable_usage.New()) - cmd.AddCommand(budget_policy.New()) - cmd.AddCommand(budgets.New()) - cmd.AddCommand(credentials.New()) - cmd.AddCommand(custom_app_integration.New()) - cmd.AddCommand(disaster_recovery.New()) - cmd.AddCommand(encryption_keys.New()) - cmd.AddCommand(endpoints.New()) - cmd.AddCommand(account_federation_policy.New()) - cmd.AddCommand(account_groups_v2.New()) - cmd.AddCommand(account_iam_v2.New()) - cmd.AddCommand(account_ip_access_lists.New()) - cmd.AddCommand(log_delivery.New()) - cmd.AddCommand(account_metastore_assignments.New()) - cmd.AddCommand(account_metastores.New()) - cmd.AddCommand(network_connectivity.New()) - cmd.AddCommand(network_policies.New()) - cmd.AddCommand(networks.New()) - cmd.AddCommand(o_auth_published_apps.New()) - cmd.AddCommand(private_access.New()) - cmd.AddCommand(private_network_gateways.New()) - cmd.AddCommand(published_app_integration.New()) - cmd.AddCommand(service_principal_federation_policy.New()) - cmd.AddCommand(service_principal_secrets.New()) - cmd.AddCommand(account_service_principals_v2.New()) - cmd.AddCommand(account_settings.New()) - cmd.AddCommand(account_settings_v2.New()) - cmd.AddCommand(storage.New()) - cmd.AddCommand(account_storage_credentials.New()) - cmd.AddCommand(usage_dashboards.New()) - cmd.AddCommand(account_users_v2.New()) - cmd.AddCommand(vpc_endpoints.New()) - cmd.AddCommand(workspace_assignment.New()) - cmd.AddCommand(workspace_network_configuration.New()) - cmd.AddCommand(workspaces.New()) +// Spec declares the account command. +var Spec = root.CommandSpec{ + Use: "account", + Short: `Databricks Account Commands`, + Build: buildCommand, +} - cmd.AddCommand(account_groups.New()) - cmd.AddCommand(account_service_principals.New()) - cmd.AddCommand(account_users.New()) +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.AddCommand(root.NewCommand(ctx, account_access_control.Spec)) + cmd.AddCommand(root.NewCommand(ctx, billable_usage.Spec)) + cmd.AddCommand(root.NewCommand(ctx, budget_policy.Spec)) + cmd.AddCommand(root.NewCommand(ctx, budgets.Spec)) + cmd.AddCommand(root.NewCommand(ctx, credentials.Spec)) + cmd.AddCommand(root.NewCommand(ctx, custom_app_integration.Spec)) + cmd.AddCommand(root.NewCommand(ctx, disaster_recovery.Spec)) + cmd.AddCommand(root.NewCommand(ctx, encryption_keys.Spec)) + cmd.AddCommand(root.NewCommand(ctx, endpoints.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_federation_policy.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_groups_v2.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_iam_v2.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_ip_access_lists.Spec)) + cmd.AddCommand(root.NewCommand(ctx, log_delivery.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_metastore_assignments.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_metastores.Spec)) + cmd.AddCommand(root.NewCommand(ctx, network_connectivity.Spec)) + cmd.AddCommand(root.NewCommand(ctx, network_policies.Spec)) + cmd.AddCommand(root.NewCommand(ctx, networks.Spec)) + cmd.AddCommand(root.NewCommand(ctx, o_auth_published_apps.Spec)) + cmd.AddCommand(root.NewCommand(ctx, private_access.Spec)) + cmd.AddCommand(root.NewCommand(ctx, private_network_gateways.Spec)) + cmd.AddCommand(root.NewCommand(ctx, published_app_integration.Spec)) + cmd.AddCommand(root.NewCommand(ctx, service_principal_federation_policy.Spec)) + cmd.AddCommand(root.NewCommand(ctx, service_principal_secrets.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_service_principals_v2.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_settings.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_settings_v2.Spec)) + cmd.AddCommand(root.NewCommand(ctx, storage.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_storage_credentials.Spec)) + cmd.AddCommand(root.NewCommand(ctx, usage_dashboards.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_users_v2.Spec)) + cmd.AddCommand(root.NewCommand(ctx, vpc_endpoints.Spec)) + cmd.AddCommand(root.NewCommand(ctx, workspace_assignment.Spec)) + cmd.AddCommand(root.NewCommand(ctx, workspace_network_configuration.Spec)) + cmd.AddCommand(root.NewCommand(ctx, workspaces.Spec)) - return cmd + cmd.AddCommand(root.NewCommand(ctx, account_groups.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_service_principals.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_users.Spec)) } diff --git a/cmd/account/credentials/credentials.go b/cmd/account/credentials/credentials.go index 580a650e889..5fda14df640 100644 --- a/cmd/account/credentials/credentials.go +++ b/cmd/account/credentials/credentials.go @@ -3,6 +3,7 @@ package credentials import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,22 +18,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "credentials", - Short: `These APIs manage credential configurations for this workspace.`, - Long: `These APIs manage credential configurations for this workspace. Databricks +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "credentials", + Short: `These APIs manage credential configurations for this workspace.`, + GroupID: "provisioning", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage credential configurations for this workspace. Databricks needs access to a cross-account service IAM role in your AWS account so that Databricks can deploy clusters in the appropriate VPC for the new workspace. A credential configuration encapsulates this role information, and its ID is - used when creating a new workspace.`, - GroupID: "provisioning", - RunE: root.ReportUnknownSubcommand, - } + used when creating a new workspace.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -44,8 +49,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/csp-enablement-account/csp-enablement-account.go b/cmd/account/csp-enablement-account/csp-enablement-account.go index 6e90bdae435..b50ea09e11d 100644 --- a/cmd/account/csp-enablement-account/csp-enablement-account.go +++ b/cmd/account/csp-enablement-account/csp-enablement-account.go @@ -3,6 +3,7 @@ package csp_enablement_account import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,15 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "csp-enablement-account", - Short: `*Public Preview* The compliance security profile settings at the account level control whether to enable it for new workspaces.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "csp-enablement-account", + Short: `*Public Preview* The compliance security profile settings at the account level control whether to enable it for new workspaces.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. The compliance security profile settings at the account level control whether to enable it for new workspaces. By default, this account-level setting is @@ -29,13 +34,13 @@ The compliance security profile settings at the account level control whether enable the compliance security profile individually for each workspace. This settings can be disabled so that new workspaces do not have compliance - security profile enabled by default.`, - RunE: root.ReportUnknownSubcommand, - } + security profile enabled by default.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newGet()) @@ -45,8 +50,6 @@ The compliance security profile settings at the account level control whether for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/account/custom-app-integration/custom-app-integration.go b/cmd/account/custom-app-integration/custom-app-integration.go index 16882132e51..f8b10819825 100644 --- a/cmd/account/custom-app-integration/custom-app-integration.go +++ b/cmd/account/custom-app-integration/custom-app-integration.go @@ -3,6 +3,7 @@ package custom_app_integration import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,20 +18,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "custom-app-integration", - Short: `These APIs enable administrators to manage custom OAuth app integrations, which is required for adding/using Custom OAuth App Integration like Tableau Cloud for Databricks in AWS cloud.`, - Long: `These APIs enable administrators to manage custom OAuth app integrations, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "custom-app-integration", + Short: `These APIs enable administrators to manage custom OAuth app integrations, which is required for adding/using Custom OAuth App Integration like Tableau Cloud for Databricks in AWS cloud.`, + GroupID: "oauth2", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs enable administrators to manage custom OAuth app integrations, which is required for adding/using Custom OAuth App Integration like Tableau - Cloud for Databricks in AWS cloud.`, - GroupID: "oauth2", - RunE: root.ReportUnknownSubcommand, - } + Cloud for Databricks in AWS cloud.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -43,8 +48,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/disable-legacy-features/disable-legacy-features.go b/cmd/account/disable-legacy-features/disable-legacy-features.go index 7ded95ff0a3..9c7fbde06c1 100644 --- a/cmd/account/disable-legacy-features/disable-legacy-features.go +++ b/cmd/account/disable-legacy-features/disable-legacy-features.go @@ -3,6 +3,7 @@ package disable_legacy_features import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,21 +18,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "disable-legacy-features", - Short: `Disable legacy features for new Databricks workspaces.`, - Long: `Disable legacy features for new Databricks workspaces. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "disable-legacy-features", + Short: `Disable legacy features for new Databricks workspaces.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Disable legacy features for new Databricks workspaces. For newly created workspaces: 1. Disables the use of DBFS root and mounts. 2. Hive Metastore will not be provisioned. 3. Disables the use of ‘No-isolation - clusters’. 4. Disables Databricks Runtime versions prior to 13.3LTS.`, - RunE: root.ReportUnknownSubcommand, - } + clusters’. 4. Disables Databricks Runtime versions prior to 13.3LTS.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newDelete()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/account/disaster-recovery/disaster-recovery.go b/cmd/account/disaster-recovery/disaster-recovery.go index 5189b96118e..81a7a9d71a1 100644 --- a/cmd/account/disaster-recovery/disaster-recovery.go +++ b/cmd/account/disaster-recovery/disaster-recovery.go @@ -3,6 +3,7 @@ package disaster_recovery import ( + "context" "errors" "fmt" "strings" @@ -20,18 +21,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "disaster-recovery", - Short: `Manage disaster recovery configurations and execute failover operations.`, - Long: `Manage disaster recovery configurations and execute failover operations.`, - GroupID: "disasterrecovery", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "disaster-recovery", + Short: `Manage disaster recovery configurations and execute failover operations.`, + GroupID: "disasterrecovery", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Manage disaster recovery configurations and execute failover operations.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateFailoverGroup()) @@ -49,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-failover-group command diff --git a/cmd/account/enable-ip-access-lists/enable-ip-access-lists.go b/cmd/account/enable-ip-access-lists/enable-ip-access-lists.go index e417dc92144..a04d0ce8c98 100644 --- a/cmd/account/enable-ip-access-lists/enable-ip-access-lists.go +++ b/cmd/account/enable-ip-access-lists/enable-ip-access-lists.go @@ -3,6 +3,7 @@ package enable_ip_access_lists import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,21 +18,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "enable-ip-access-lists", - Short: `Controls the enforcement of IP access lists for accessing the account console.`, - Long: `Controls the enforcement of IP access lists for accessing the account console. - Allowing you to enable or disable restricted access based on IP addresses.`, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "enable-ip-access-lists", + Short: `Controls the enforcement of IP access lists for accessing the account console.`, - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Controls the enforcement of IP access lists for accessing the account console. + Allowing you to enable or disable restricted access based on IP addresses.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newDelete()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/account/encryption-keys/encryption-keys.go b/cmd/account/encryption-keys/encryption-keys.go index 941fe953d43..73c19c71c40 100644 --- a/cmd/account/encryption-keys/encryption-keys.go +++ b/cmd/account/encryption-keys/encryption-keys.go @@ -3,6 +3,7 @@ package encryption_keys import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "encryption-keys", - Short: `These APIs manage encryption key configurations for this workspace (optional).`, - Long: `These APIs manage encryption key configurations for this workspace (optional). +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "encryption-keys", + Short: `These APIs manage encryption key configurations for this workspace (optional).`, + GroupID: "provisioning", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage encryption key configurations for this workspace (optional). A key configuration encapsulates the AWS KMS key information and some information about how the key configuration can be used. There are two possible uses for key configurations: @@ -36,14 +42,13 @@ func New() *cobra.Command { version of the platform. Updating a running workspace with workspace storage encryption requires that the workspace is on the E2 version of the platform. If you have an older workspace, it might not be on the E2 version of the - platform. If you are not sure, contact your Databricks representative.`, - GroupID: "provisioning", - RunE: root.ReportUnknownSubcommand, - } + platform. If you are not sure, contact your Databricks representative.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -55,8 +60,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/endpoints/endpoints.go b/cmd/account/endpoints/endpoints.go index 8cdb1b5c73f..01011d3a6ee 100644 --- a/cmd/account/endpoints/endpoints.go +++ b/cmd/account/endpoints/endpoints.go @@ -3,6 +3,7 @@ package endpoints import ( + "context" "errors" "fmt" @@ -18,18 +19,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "endpoints", - Short: `These APIs manage endpoint configurations for this account.`, - Long: `These APIs manage endpoint configurations for this account.`, - GroupID: "provisioning", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "endpoints", + Short: `These APIs manage endpoint configurations for this account.`, + GroupID: "provisioning", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage endpoint configurations for this account.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateEndpoint()) @@ -41,8 +46,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-endpoint command diff --git a/cmd/account/esm-enablement-account/esm-enablement-account.go b/cmd/account/esm-enablement-account/esm-enablement-account.go index 75af94183a2..19371d44864 100644 --- a/cmd/account/esm-enablement-account/esm-enablement-account.go +++ b/cmd/account/esm-enablement-account/esm-enablement-account.go @@ -3,6 +3,7 @@ package esm_enablement_account import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,23 +18,27 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "esm-enablement-account", - Short: `*Public Preview* The enhanced security monitoring setting at the account level controls whether to enable the feature on new workspaces.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "esm-enablement-account", + Short: `*Public Preview* The enhanced security monitoring setting at the account level controls whether to enable the feature on new workspaces.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. The enhanced security monitoring setting at the account level controls whether to enable the feature on new workspaces. By default, this account-level setting is disabled for new workspaces. After workspace creation, account admins can enable enhanced security monitoring individually for each - workspace.`, - RunE: root.ReportUnknownSubcommand, - } + workspace.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newGet()) @@ -43,8 +48,6 @@ The enhanced security monitoring setting at the account level controls whether for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/account/federation-policy/federation-policy.go b/cmd/account/federation-policy/federation-policy.go index f9ccb47c442..9f595268dfc 100644 --- a/cmd/account/federation-policy/federation-policy.go +++ b/cmd/account/federation-policy/federation-policy.go @@ -3,6 +3,7 @@ package federation_policy import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "federation-policy", - Short: `These APIs manage account federation policies.`, - Long: `These APIs manage account federation policies. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "federation-policy", + Short: `These APIs manage account federation policies.`, + GroupID: "oauth2", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage account federation policies. Account federation policies allow users and service principals in your Databricks account to securely access Databricks APIs using tokens from your @@ -69,14 +75,13 @@ func New() *cobra.Command { You do not need to configure an OAuth application in Databricks to use token federation. - [SCIM]: https://docs.databricks.com/admin/users-groups/scim/index.html`, - GroupID: "oauth2", - RunE: root.ReportUnknownSubcommand, - } + [SCIM]: https://docs.databricks.com/admin/users-groups/scim/index.html` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -89,8 +94,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/groups-v2/groups-v2.go b/cmd/account/groups-v2/groups-v2.go index 63c47c53ee8..1dd7db79e7c 100644 --- a/cmd/account/groups-v2/groups-v2.go +++ b/cmd/account/groups-v2/groups-v2.go @@ -3,6 +3,7 @@ package groups_v2 import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,24 +18,28 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "groups-v2", - Short: `Groups simplify identity management, making it easier to assign access to Databricks account, data, and other securable objects.`, - Long: `Groups simplify identity management, making it easier to assign access to +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "groups-v2", + Short: `Groups simplify identity management, making it easier to assign access to Databricks account, data, and other securable objects.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Groups simplify identity management, making it easier to assign access to Databricks account, data, and other securable objects. It is best practice to assign access to workspaces and access-control policies in Unity Catalog to groups, instead of to users individually. All Databricks account identities can be assigned as members of groups, and members inherit - permissions that are assigned to their group.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } + permissions that are assigned to their group.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -48,8 +53,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/groups/groups.go b/cmd/account/groups/groups.go index 9f2a4e89dfd..697900c8b7b 100755 --- a/cmd/account/groups/groups.go +++ b/cmd/account/groups/groups.go @@ -6,6 +6,7 @@ package groups import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -20,23 +21,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "groups", - Short: `Groups simplify identity management, making it easier to assign access to Databricks account, data, and other securable objects.`, - Long: `Groups simplify identity management, making it easier to assign access to +// Spec declares the groups command. +var Spec = root.CommandSpec{ + Use: "groups", + Short: `Groups simplify identity management, making it easier to assign access to Databricks account, data, and other securable objects.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Annotations = map[string]string{ + "package": "iam", + } + cmd.Long = `Groups simplify identity management, making it easier to assign access to Databricks account, data, and other securable objects. It is best practice to assign access to workspaces and access-control policies in Unity Catalog to groups, instead of to users individually. All Databricks account identities can be assigned as members of groups, and members inherit - permissions that are assigned to their group.`, - GroupID: "iam", - Annotations: map[string]string{ - "package": "iam", - }, - RunE: root.ReportUnknownSubcommand, - } + permissions that are assigned to their group.` + cmd.RunE = root.ReportUnknownSubcommand // Add methods cmd.AddCommand(newCreate()) @@ -50,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/iam-v2/iam-v2.go b/cmd/account/iam-v2/iam-v2.go index 4151a1ae44f..e8bc3fa116b 100644 --- a/cmd/account/iam-v2/iam-v2.go +++ b/cmd/account/iam-v2/iam-v2.go @@ -3,6 +3,7 @@ package iam_v2 import ( + "context" "errors" "fmt" "strings" @@ -20,19 +21,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "iam-v2", - Short: `These APIs are used to manage identities and the workspace access of these identities in Databricks.`, - Long: `These APIs are used to manage identities and the workspace access of these - identities in Databricks.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "iam-v2", + Short: `These APIs are used to manage identities and the workspace access of these identities in Databricks.`, + GroupID: "iam", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs are used to manage identities and the workspace access of these + identities in Databricks.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateDirectGroupMember()) @@ -81,8 +86,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-direct-group-member command diff --git a/cmd/account/ip-access-lists/ip-access-lists.go b/cmd/account/ip-access-lists/ip-access-lists.go index 7e9dab8b09b..d0caffa0b9b 100644 --- a/cmd/account/ip-access-lists/ip-access-lists.go +++ b/cmd/account/ip-access-lists/ip-access-lists.go @@ -3,6 +3,7 @@ package ip_access_lists import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "ip-access-lists", - Short: `The Accounts IP Access List API enables account admins to configure IP access lists for access to the account console.`, - Long: `The Accounts IP Access List API enables account admins to configure IP access +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "ip-access-lists", + Short: `The Accounts IP Access List API enables account admins to configure IP access lists for access to the account console.`, + GroupID: "settings", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Accounts IP Access List API enables account admins to configure IP access lists for access to the account console. Account IP Access Lists affect web application access and REST API access to @@ -43,14 +49,13 @@ func New() *cobra.Command { of 1000 IP/CIDR values, where one CIDR counts as a single value. After changes to the account-level IP access lists, it can take a few minutes - for changes to take effect.`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } + for changes to take effect.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -64,8 +69,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/llm-proxy-partner-powered-account/llm-proxy-partner-powered-account.go b/cmd/account/llm-proxy-partner-powered-account/llm-proxy-partner-powered-account.go index c81d65af84c..46faaca5862 100644 --- a/cmd/account/llm-proxy-partner-powered-account/llm-proxy-partner-powered-account.go +++ b/cmd/account/llm-proxy-partner-powered-account/llm-proxy-partner-powered-account.go @@ -3,6 +3,7 @@ package llm_proxy_partner_powered_account import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,20 +18,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "llm-proxy-partner-powered-account", - Short: `Determines if partner powered models are enabled or not for a specific account.`, - Long: `Determines if partner powered models are enabled or not for a specific account`, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "llm-proxy-partner-powered-account", + Short: `Determines if partner powered models are enabled or not for a specific account.`, - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Determines if partner powered models are enabled or not for a specific account` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newGet()) @@ -40,8 +45,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/account/llm-proxy-partner-powered-enforce/llm-proxy-partner-powered-enforce.go b/cmd/account/llm-proxy-partner-powered-enforce/llm-proxy-partner-powered-enforce.go index 035b0a0accf..440672814ef 100644 --- a/cmd/account/llm-proxy-partner-powered-enforce/llm-proxy-partner-powered-enforce.go +++ b/cmd/account/llm-proxy-partner-powered-enforce/llm-proxy-partner-powered-enforce.go @@ -3,6 +3,7 @@ package llm_proxy_partner_powered_enforce import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,21 +18,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "llm-proxy-partner-powered-enforce", - Short: `Determines if the account-level partner-powered setting value is enforced upon the workspace-level partner-powered setting.`, - Long: `Determines if the account-level partner-powered setting value is enforced upon - the workspace-level partner-powered setting`, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "llm-proxy-partner-powered-enforce", + Short: `Determines if the account-level partner-powered setting value is enforced upon the workspace-level partner-powered setting.`, - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Determines if the account-level partner-powered setting value is enforced upon + the workspace-level partner-powered setting` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newGet()) @@ -41,8 +46,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/account/log-delivery/log-delivery.go b/cmd/account/log-delivery/log-delivery.go index 93310e7aad5..f8412d5e5ba 100644 --- a/cmd/account/log-delivery/log-delivery.go +++ b/cmd/account/log-delivery/log-delivery.go @@ -3,6 +3,7 @@ package log_delivery import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "log-delivery", - Short: `These APIs manage log delivery configurations for this account.`, - Long: `These APIs manage log delivery configurations for this account. The two +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "log-delivery", + Short: `These APIs manage log delivery configurations for this account.`, + GroupID: "billing", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage log delivery configurations for this account. The two supported log types for this API are _billable usage logs_ (AWS only) and _audit logs_ (AWS and GCP). This feature is in Public Preview. This feature works with all account ID types. @@ -87,14 +93,13 @@ func New() *cobra.Command { [Billable usage log delivery]: https://docs.databricks.com/administration-guide/account-settings/billable-usage-delivery.html [GCP]: https://docs.databricks.com/gcp/en/admin/account-settings/audit-logs [Usage page]: https://docs.databricks.com/administration-guide/account-settings/usage.html - [create a new AWS S3 bucket]: https://docs.databricks.com/administration-guide/account-api/aws-storage.html`, - GroupID: "billing", - RunE: root.ReportUnknownSubcommand, - } + [create a new AWS S3 bucket]: https://docs.databricks.com/administration-guide/account-api/aws-storage.html` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -106,8 +111,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/metastore-assignments/metastore-assignments.go b/cmd/account/metastore-assignments/metastore-assignments.go index 622b56f75dd..ba93e406fc9 100644 --- a/cmd/account/metastore-assignments/metastore-assignments.go +++ b/cmd/account/metastore-assignments/metastore-assignments.go @@ -3,6 +3,7 @@ package metastore_assignments import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,18 +18,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "metastore-assignments", - Short: `These APIs manage metastore assignments to a workspace.`, - Long: `These APIs manage metastore assignments to a workspace.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "metastore-assignments", + Short: `These APIs manage metastore assignments to a workspace.`, + GroupID: "catalog", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage metastore assignments to a workspace.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -41,8 +46,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/metastores/metastores.go b/cmd/account/metastores/metastores.go index 7967101987f..337b89e6fcf 100644 --- a/cmd/account/metastores/metastores.go +++ b/cmd/account/metastores/metastores.go @@ -3,6 +3,7 @@ package metastores import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,19 +18,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "metastores", - Short: `These APIs manage Unity Catalog metastores for an account.`, - Long: `These APIs manage Unity Catalog metastores for an account. A metastore - contains catalogs that can be associated with workspaces`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "metastores", + Short: `These APIs manage Unity Catalog metastores for an account.`, + GroupID: "catalog", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage Unity Catalog metastores for an account. A metastore + contains catalogs that can be associated with workspaces` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/network-connectivity/network-connectivity.go b/cmd/account/network-connectivity/network-connectivity.go index ce09c01ebf5..98ac9400ff1 100644 --- a/cmd/account/network-connectivity/network-connectivity.go +++ b/cmd/account/network-connectivity/network-connectivity.go @@ -3,6 +3,7 @@ package network_connectivity import ( + "context" "errors" "fmt" "strings" @@ -20,11 +21,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "network-connectivity", - Short: `These APIs provide configurations for the network connectivity of your workspaces for serverless compute resources.`, - Long: `These APIs provide configurations for the network connectivity of your +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "network-connectivity", + Short: `These APIs provide configurations for the network connectivity of your workspaces for serverless compute resources.`, + GroupID: "settings", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs provide configurations for the network connectivity of your workspaces for serverless compute resources. This API provides stable subnets for your workspace so that you can configure your firewalls on your Azure Storage accounts to allow access from Databricks. You can also use the API to @@ -32,14 +38,13 @@ func New() *cobra.Command { compute resources to your Azure resources using Azure Private Link. See [configure serverless secure connectivity]. - [configure serverless secure connectivity]: https://learn.microsoft.com/azure/databricks/security/network/serverless-network-security`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } + [configure serverless secure connectivity]: https://learn.microsoft.com/azure/databricks/security/network/serverless-network-security` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateNetworkConnectivityConfiguration()) @@ -57,8 +62,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-network-connectivity-configuration command diff --git a/cmd/account/network-policies/network-policies.go b/cmd/account/network-policies/network-policies.go index 15cc31d5fa0..c7dde6e512e 100644 --- a/cmd/account/network-policies/network-policies.go +++ b/cmd/account/network-policies/network-policies.go @@ -3,6 +3,7 @@ package network_policies import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,24 +18,28 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "network-policies", - Short: `These APIs manage network policies for this account.`, - Long: `These APIs manage network policies for this account. Network policies control +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "network-policies", + Short: `These APIs manage network policies for this account.`, + GroupID: "settings", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage network policies for this account. Network policies control which network destinations can be accessed from the Databricks environment. Each Databricks account includes a default policy named 'default-policy'. 'default-policy' is associated with any workspace lacking an explicit network policy assignment, and is automatically associated with each newly created workspace. 'default-policy' is reserved and cannot be deleted, but it can be - updated to customize the default network access rules for your account.`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } + updated to customize the default network access rules for your account.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateNetworkPolicyRpc()) @@ -47,8 +52,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-network-policy-rpc command diff --git a/cmd/account/networks/networks.go b/cmd/account/networks/networks.go index ae7318e76b9..1d2dd7fd8a3 100644 --- a/cmd/account/networks/networks.go +++ b/cmd/account/networks/networks.go @@ -3,6 +3,8 @@ package networks import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -15,19 +17,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "networks", - Short: `These APIs manage network configurations for customer-managed VPCs (optional).`, - Long: `These APIs manage network configurations for customer-managed VPCs (optional). - Its ID is used when creating a new workspace if you use customer-managed VPCs.`, - GroupID: "provisioning", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "networks", + Short: `These APIs manage network configurations for customer-managed VPCs (optional).`, + GroupID: "provisioning", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage network configurations for customer-managed VPCs (optional). + Its ID is used when creating a new workspace if you use customer-managed VPCs.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -39,8 +45,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/o-auth-published-apps/o-auth-published-apps.go b/cmd/account/o-auth-published-apps/o-auth-published-apps.go index 89b96f0fadb..fe264a20f52 100644 --- a/cmd/account/o-auth-published-apps/o-auth-published-apps.go +++ b/cmd/account/o-auth-published-apps/o-auth-published-apps.go @@ -3,6 +3,7 @@ package o_auth_published_apps import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -16,21 +17,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "o-auth-published-apps", - Short: `These APIs enable administrators to view all the available published OAuth applications in Databricks.`, - Long: `These APIs enable administrators to view all the available published OAuth +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "o-auth-published-apps", + Short: `These APIs enable administrators to view all the available published OAuth applications in Databricks.`, + GroupID: "oauth2", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs enable administrators to view all the available published OAuth applications in Databricks. Administrators can add the published OAuth applications to their account through the OAuth Published App Integration - APIs.`, - GroupID: "oauth2", - RunE: root.ReportUnknownSubcommand, - } + APIs.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newList()) @@ -39,8 +44,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start list command diff --git a/cmd/account/personal-compute/personal-compute.go b/cmd/account/personal-compute/personal-compute.go index 1e6c3569975..bb31fde7b07 100644 --- a/cmd/account/personal-compute/personal-compute.go +++ b/cmd/account/personal-compute/personal-compute.go @@ -3,6 +3,7 @@ package personal_compute import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,18 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "personal-compute", - Short: `The Personal Compute enablement setting lets you control which users can use the Personal Compute default policy to create compute resources.`, - Long: `The Personal Compute enablement setting lets you control which users can use +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "personal-compute", + Short: `The Personal Compute enablement setting lets you control which users can use the Personal Compute default policy to create compute resources.`, + + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Personal Compute enablement setting lets you control which users can use the Personal Compute default policy to create compute resources. By default all users in all workspaces have access (ON), but you can change the setting to instead let individual workspaces configure access control (DELEGATE). @@ -29,17 +37,14 @@ func New() *cobra.Command { There is only one instance of this setting per account. Since this setting has a default value, this setting is present on all accounts even though it's never set on a given account. Deletion reverts the value of the setting back - to the default value.`, + to the default value.` + cmd.RunE = root.ReportUnknownSubcommand - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", } - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" - // Add methods cmd.AddCommand(newDelete()) cmd.AddCommand(newGet()) @@ -49,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/account/private-access/private-access.go b/cmd/account/private-access/private-access.go index 779cad0cff7..384a20755de 100644 --- a/cmd/account/private-access/private-access.go +++ b/cmd/account/private-access/private-access.go @@ -3,6 +3,8 @@ package private_access import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -15,18 +17,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "private-access", - Short: `These APIs manage private access settings for this account.`, - Long: `These APIs manage private access settings for this account.`, - GroupID: "provisioning", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "private-access", + Short: `These APIs manage private access settings for this account.`, + GroupID: "provisioning", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage private access settings for this account.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -39,8 +45,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/private-network-gateways/private-network-gateways.go b/cmd/account/private-network-gateways/private-network-gateways.go index aae82a8b651..69e1bfb44fc 100644 --- a/cmd/account/private-network-gateways/private-network-gateways.go +++ b/cmd/account/private-network-gateways/private-network-gateways.go @@ -3,6 +3,7 @@ package private_network_gateways import ( + "context" "errors" "fmt" "strings" @@ -22,22 +23,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "private-network-gateways", - Short: `These APIs manage private network gateways under network connectivity configurations.`, - Long: `These APIs manage private network gateways under network connectivity - configurations.`, - GroupID: "provisioning", - - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "private-network-gateways", + Short: `These APIs manage private network gateways under network connectivity configurations.`, + GroupID: "provisioning", - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage private network gateways under network connectivity + configurations.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newCreatePrivateNetworkGateway()) @@ -51,8 +56,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-private-network-gateway command diff --git a/cmd/account/published-app-integration/published-app-integration.go b/cmd/account/published-app-integration/published-app-integration.go index d49f9013eac..1577af4eb90 100644 --- a/cmd/account/published-app-integration/published-app-integration.go +++ b/cmd/account/published-app-integration/published-app-integration.go @@ -3,6 +3,7 @@ package published_app_integration import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,20 +18,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "published-app-integration", - Short: `These APIs enable administrators to manage published OAuth app integrations, which is required for adding/using Published OAuth App Integration like Tableau Desktop for Databricks in AWS cloud.`, - Long: `These APIs enable administrators to manage published OAuth app integrations, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "published-app-integration", + Short: `These APIs enable administrators to manage published OAuth app integrations, which is required for adding/using Published OAuth App Integration like Tableau Desktop for Databricks in AWS cloud.`, + GroupID: "oauth2", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs enable administrators to manage published OAuth app integrations, which is required for adding/using Published OAuth App Integration like - Tableau Desktop for Databricks in AWS cloud.`, - GroupID: "oauth2", - RunE: root.ReportUnknownSubcommand, - } + Tableau Desktop for Databricks in AWS cloud.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -43,8 +48,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/service-principal-federation-policy/service-principal-federation-policy.go b/cmd/account/service-principal-federation-policy/service-principal-federation-policy.go index 7a148865891..779bea8b595 100644 --- a/cmd/account/service-principal-federation-policy/service-principal-federation-policy.go +++ b/cmd/account/service-principal-federation-policy/service-principal-federation-policy.go @@ -3,6 +3,7 @@ package service_principal_federation_policy import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "service-principal-federation-policy", - Short: `These APIs manage service principal federation policies.`, - Long: `These APIs manage service principal federation policies. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "service-principal-federation-policy", + Short: `These APIs manage service principal federation policies.`, + GroupID: "oauth2", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage service principal federation policies. Service principal federation, also known as Workload Identity Federation, allows your automated workloads running outside of Databricks to securely @@ -74,14 +80,13 @@ func New() *cobra.Command { your workloads. You do not need to configure an OAuth application in Databricks to use token - federation.`, - GroupID: "oauth2", - RunE: root.ReportUnknownSubcommand, - } + federation.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -94,8 +99,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/service-principal-secrets/service-principal-secrets.go b/cmd/account/service-principal-secrets/service-principal-secrets.go index 5616726b1c7..37e35a6fb7e 100644 --- a/cmd/account/service-principal-secrets/service-principal-secrets.go +++ b/cmd/account/service-principal-secrets/service-principal-secrets.go @@ -3,6 +3,7 @@ package service_principal_secrets import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "service-principal-secrets", - Short: `These APIs enable administrators to manage service principal secrets.`, - Long: `These APIs enable administrators to manage service principal secrets. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "service-principal-secrets", + Short: `These APIs enable administrators to manage service principal secrets.`, + GroupID: "oauth2", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs enable administrators to manage service principal secrets. You can use the generated secrets to obtain OAuth access tokens for a service principal, which can then be used to access Databricks Accounts and Workspace @@ -33,14 +39,13 @@ func New() *cobra.Command { information, see [Databricks Terraform Provider]. [Authentication using OAuth tokens for service principals]: https://docs.databricks.com/dev-tools/authentication-oauth.html - [Databricks Terraform Provider]: https://github.com/databricks/terraform-provider-databricks/blob/master/docs/index.md#authenticating-with-service-principal`, - GroupID: "oauth2", - RunE: root.ReportUnknownSubcommand, - } + [Databricks Terraform Provider]: https://github.com/databricks/terraform-provider-databricks/blob/master/docs/index.md#authenticating-with-service-principal` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -51,8 +56,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/service-principals-v2/service-principals-v2.go b/cmd/account/service-principals-v2/service-principals-v2.go index ba6aadb6cb6..660420f429f 100644 --- a/cmd/account/service-principals-v2/service-principals-v2.go +++ b/cmd/account/service-principals-v2/service-principals-v2.go @@ -3,6 +3,7 @@ package service_principals_v2 import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,23 +18,27 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "service-principals-v2", - Short: `Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms.`, - Long: `Identities for use with jobs, automated tools, and systems such as scripts, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "service-principals-v2", + Short: `Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms. Databricks recommends creating service principals to run production jobs or modify production data. If all processes that act on production data run with service principals, interactive users do not need any write, delete, or modify privileges in production. This eliminates the risk of - a user overwriting production data by accident.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } + a user overwriting production data by accident.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -47,8 +52,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/service-principals/service-principals.go b/cmd/account/service-principals/service-principals.go index 06d410fc33d..689527a59a0 100755 --- a/cmd/account/service-principals/service-principals.go +++ b/cmd/account/service-principals/service-principals.go @@ -6,6 +6,7 @@ package service_principals import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -20,22 +21,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "service-principals", - Short: `Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms.`, - Long: `Identities for use with jobs, automated tools, and systems such as scripts, +// Spec declares the service-principals command. +var Spec = root.CommandSpec{ + Use: "service-principals", + Short: `Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Annotations = map[string]string{ + "package": "iam", + } + cmd.Long = `Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms. Databricks recommends creating service principals to run production jobs or modify production data. If all processes that act on production data run with service principals, interactive users do not need any write, delete, or modify privileges in production. This eliminates the risk of - a user overwriting production data by accident.`, - GroupID: "iam", - Annotations: map[string]string{ - "package": "iam", - }, - RunE: root.ReportUnknownSubcommand, - } + a user overwriting production data by accident.` + cmd.RunE = root.ReportUnknownSubcommand // Add methods cmd.AddCommand(newCreate()) @@ -49,8 +53,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/settings-v2/settings-v2.go b/cmd/account/settings-v2/settings-v2.go index f96bdc9c93b..7106b9d20db 100644 --- a/cmd/account/settings-v2/settings-v2.go +++ b/cmd/account/settings-v2/settings-v2.go @@ -3,6 +3,7 @@ package settings_v2 import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,18 +18,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "settings-v2", - Short: `APIs to manage account level settings.`, - Long: `APIs to manage account level settings`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "settings-v2", + Short: `APIs to manage account level settings.`, + GroupID: "settings", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `APIs to manage account level settings` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGetPublicAccountSetting()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-public-account-setting command diff --git a/cmd/account/settings/settings.go b/cmd/account/settings/settings.go index 752e80d0660..b27b7563bd1 100644 --- a/cmd/account/settings/settings.go +++ b/cmd/account/settings/settings.go @@ -3,6 +3,8 @@ package settings import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/spf13/cobra" @@ -19,34 +21,36 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "settings", - Short: `Accounts Settings API allows users to manage settings at the account level.`, - Long: `Accounts Settings API allows users to manage settings at the account level.`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "settings", + Short: `Accounts Settings API allows users to manage settings at the account level.`, + GroupID: "settings", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Accounts Settings API allows users to manage settings at the account level.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add subservices - cmd.AddCommand(csp_enablement_account.New()) - cmd.AddCommand(disable_legacy_features.New()) - cmd.AddCommand(enable_ip_access_lists.New()) - cmd.AddCommand(esm_enablement_account.New()) - cmd.AddCommand(llm_proxy_partner_powered_account.New()) - cmd.AddCommand(llm_proxy_partner_powered_enforce.New()) - cmd.AddCommand(personal_compute.New()) + cmd.AddCommand(root.NewCommand(ctx, csp_enablement_account.Spec)) + cmd.AddCommand(root.NewCommand(ctx, disable_legacy_features.Spec)) + cmd.AddCommand(root.NewCommand(ctx, enable_ip_access_lists.Spec)) + cmd.AddCommand(root.NewCommand(ctx, esm_enablement_account.Spec)) + cmd.AddCommand(root.NewCommand(ctx, llm_proxy_partner_powered_account.Spec)) + cmd.AddCommand(root.NewCommand(ctx, llm_proxy_partner_powered_enforce.Spec)) + cmd.AddCommand(root.NewCommand(ctx, personal_compute.Spec)) // Apply optional overrides to this command. for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // end service AccountSettings diff --git a/cmd/account/storage-credentials/storage-credentials.go b/cmd/account/storage-credentials/storage-credentials.go index ba3f3ded1b6..34ef8b4f02c 100644 --- a/cmd/account/storage-credentials/storage-credentials.go +++ b/cmd/account/storage-credentials/storage-credentials.go @@ -3,6 +3,7 @@ package storage_credentials import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,18 +18,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "storage-credentials", - Short: `These APIs manage storage credentials for a particular metastore.`, - Long: `These APIs manage storage credentials for a particular metastore.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "storage-credentials", + Short: `These APIs manage storage credentials for a particular metastore.`, + GroupID: "catalog", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage storage credentials for a particular metastore.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -41,8 +46,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/storage/storage.go b/cmd/account/storage/storage.go index 116b58fc2ca..595596d9f8b 100644 --- a/cmd/account/storage/storage.go +++ b/cmd/account/storage/storage.go @@ -3,6 +3,7 @@ package storage import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,23 +18,27 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "storage", - Short: `These APIs manage storage configurations for this workspace.`, - Long: `These APIs manage storage configurations for this workspace. A root storage S3 +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "storage", + Short: `These APIs manage storage configurations for this workspace.`, + GroupID: "provisioning", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage storage configurations for this workspace. A root storage S3 bucket in your account is required to store objects like cluster logs, notebook revisions, and job results. You can also use the root storage S3 bucket for storage of non-production DBFS data. A storage configuration encapsulates this bucket information, and its ID is used when creating a new - workspace.`, - GroupID: "provisioning", - RunE: root.ReportUnknownSubcommand, - } + workspace.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -45,8 +50,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/usage-dashboards/usage-dashboards.go b/cmd/account/usage-dashboards/usage-dashboards.go index 05d5d15177c..bf74f77dd1d 100644 --- a/cmd/account/usage-dashboards/usage-dashboards.go +++ b/cmd/account/usage-dashboards/usage-dashboards.go @@ -3,6 +3,8 @@ package usage_dashboards import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -15,20 +17,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "usage-dashboards", - Short: `These APIs manage usage dashboards for this account.`, - Long: `These APIs manage usage dashboards for this account. Usage dashboards enable +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "usage-dashboards", + Short: `These APIs manage usage dashboards for this account.`, + GroupID: "billing", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage usage dashboards for this account. Usage dashboards enable you to gain insights into your usage with pre-built dashboards: visualize - breakdowns, analyze tag attributions, and identify cost drivers.`, - GroupID: "billing", - RunE: root.ReportUnknownSubcommand, - } + breakdowns, analyze tag attributions, and identify cost drivers.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -38,8 +44,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/users-v2/users-v2.go b/cmd/account/users-v2/users-v2.go index 5fff739b461..9445cce1b2d 100644 --- a/cmd/account/users-v2/users-v2.go +++ b/cmd/account/users-v2/users-v2.go @@ -3,6 +3,7 @@ package users_v2 import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "users-v2", - Short: `User identities recognized by Databricks and represented by email addresses.`, - Long: `User identities recognized by Databricks and represented by email addresses. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "users-v2", + Short: `User identities recognized by Databricks and represented by email addresses.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `User identities recognized by Databricks and represented by email addresses. Databricks recommends using SCIM provisioning to sync users and groups automatically from your identity provider to your Databricks account. SCIM @@ -31,14 +37,13 @@ func New() *cobra.Command { access to Databricks account, admins can terminate the user in your identity provider and that user’s account will also be removed from Databricks account. This ensures a consistent offboarding process and prevents - unauthorized users from accessing sensitive data.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } + unauthorized users from accessing sensitive data.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -52,8 +57,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/users/users.go b/cmd/account/users/users.go index 57218bafc65..1dd2950008f 100755 --- a/cmd/account/users/users.go +++ b/cmd/account/users/users.go @@ -6,6 +6,7 @@ package users import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -20,11 +21,19 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "users", - Short: `User identities recognized by Databricks and represented by email addresses.`, - Long: `User identities recognized by Databricks and represented by email addresses. +// Spec declares the users command. +var Spec = root.CommandSpec{ + Use: "users", + Short: `User identities recognized by Databricks and represented by email addresses.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Annotations = map[string]string{ + "package": "iam", + } + cmd.Long = `User identities recognized by Databricks and represented by email addresses. Databricks recommends using SCIM provisioning to sync users and groups automatically from your identity provider to your Databricks account. SCIM @@ -34,13 +43,8 @@ func New() *cobra.Command { access to Databricks account, admins can terminate the user in your identity provider and that user’s account will also be removed from Databricks account. This ensures a consistent offboarding process and prevents - unauthorized users from accessing sensitive data.`, - GroupID: "iam", - Annotations: map[string]string{ - "package": "iam", - }, - RunE: root.ReportUnknownSubcommand, - } + unauthorized users from accessing sensitive data.` + cmd.RunE = root.ReportUnknownSubcommand // Add methods cmd.AddCommand(newCreate()) @@ -54,8 +58,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/vpc-endpoints/vpc-endpoints.go b/cmd/account/vpc-endpoints/vpc-endpoints.go index d05ae2fc063..3c2b3e89c8a 100644 --- a/cmd/account/vpc-endpoints/vpc-endpoints.go +++ b/cmd/account/vpc-endpoints/vpc-endpoints.go @@ -3,6 +3,8 @@ package vpc_endpoints import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -15,18 +17,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "vpc-endpoints", - Short: `These APIs manage VPC endpoint configurations for this account.`, - Long: `These APIs manage VPC endpoint configurations for this account.`, - GroupID: "provisioning", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "vpc-endpoints", + Short: `These APIs manage VPC endpoint configurations for this account.`, + GroupID: "provisioning", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage VPC endpoint configurations for this account.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -38,8 +44,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/account/workspace-assignment/workspace-assignment.go b/cmd/account/workspace-assignment/workspace-assignment.go index 08895b11b96..f1669002d82 100644 --- a/cmd/account/workspace-assignment/workspace-assignment.go +++ b/cmd/account/workspace-assignment/workspace-assignment.go @@ -3,6 +3,7 @@ package workspace_assignment import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,19 +18,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "workspace-assignment", - Short: `The Workspace Permission Assignment API allows you to manage workspace permissions for principals in your account.`, - Long: `The Workspace Permission Assignment API allows you to manage workspace - permissions for principals in your account.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "workspace-assignment", + Short: `The Workspace Permission Assignment API allows you to manage workspace permissions for principals in your account.`, + GroupID: "iam", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Workspace Permission Assignment API allows you to manage workspace + permissions for principals in your account.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newDelete()) @@ -41,8 +46,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/account/workspace-network-configuration/workspace-network-configuration.go b/cmd/account/workspace-network-configuration/workspace-network-configuration.go index 58ef41e0119..ed9eae800f9 100644 --- a/cmd/account/workspace-network-configuration/workspace-network-configuration.go +++ b/cmd/account/workspace-network-configuration/workspace-network-configuration.go @@ -3,6 +3,7 @@ package workspace_network_configuration import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,24 +18,28 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "workspace-network-configuration", - Short: `These APIs allow configuration of network settings for Databricks workspaces by selecting which network policy to associate with the workspace.`, - Long: `These APIs allow configuration of network settings for Databricks workspaces +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "workspace-network-configuration", + Short: `These APIs allow configuration of network settings for Databricks workspaces by selecting which network policy to associate with the workspace.`, + GroupID: "settings", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs allow configuration of network settings for Databricks workspaces by selecting which network policy to associate with the workspace. Each workspace is always associated with exactly one network policy that controls which network destinations can be accessed from the Databricks environment. By default, workspaces are associated with the 'default-policy' network policy. You cannot create or delete a workspace's network option, only update it to - associate the workspace with a different policy`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } + associate the workspace with a different policy` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGetWorkspaceNetworkOptionRpc()) @@ -44,8 +49,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-workspace-network-option-rpc command diff --git a/cmd/account/workspaces/workspaces.go b/cmd/account/workspaces/workspaces.go index 1025f94e68b..c12939977c0 100644 --- a/cmd/account/workspaces/workspaces.go +++ b/cmd/account/workspaces/workspaces.go @@ -3,6 +3,7 @@ package workspaces import ( + "context" "fmt" "time" @@ -18,25 +19,29 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "workspaces", - Short: `These APIs manage workspaces for this account.`, - Long: `These APIs manage workspaces for this account. A Databricks workspace is an +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "workspaces", + Short: `These APIs manage workspaces for this account.`, + GroupID: "provisioning", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs manage workspaces for this account. A Databricks workspace is an environment for accessing all of your Databricks assets. The workspace organizes objects (notebooks, libraries, and experiments) into folders, and provides access to data and computational resources such as clusters and jobs. These endpoints are available if your account is on the E2 version of the platform or on a select custom plan that allows multiple workspaces per - account.`, - GroupID: "provisioning", - RunE: root.ReportUnknownSubcommand, - } + account.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -49,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/air/air.go b/cmd/air/air.go index 4154bab891c..07f4c9281a5 100644 --- a/cmd/air/air.go +++ b/cmd/air/air.go @@ -1,9 +1,11 @@ package aircmd import ( + "context" "fmt" "strings" + "github.com/databricks/cli/cmd/root" "github.com/spf13/cobra" ) @@ -23,18 +25,20 @@ Learn more: Coding agent skill databricks aitools install --skills-only --skills databricks-ai-runtime ` -// New returns the root command for the AI Runtime CLI. -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "air", - Short: "Run and manage AI Runtime workloads on serverless GPU compute", - GroupID: "development", - Long: `Run GPU workloads on Databricks serverless compute. +// Spec declares the air command. +var Spec = root.CommandSpec{ + Use: "air", + Short: "Run and manage AI Runtime workloads on serverless GPU compute", + GroupID: "development", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Run GPU workloads on Databricks serverless compute. Describe a workload in a YAML file and submit it with "databricks air run". Follow a run with "databricks air logs" and "databricks air get", or see your -active runs with "databricks air list".`, - } +active runs with "databricks air list".` cmd.AddGroup( &cobra.Group{ID: runGroupID, Title: "Run workloads:"}, @@ -58,8 +62,6 @@ active runs with "databricks air list".`, fmt.Fprint(c.OutOrStdout(), airHelpFooter) } }) - - return cmd } func addToGroup(parent *cobra.Command, groupID string, cmds ...*cobra.Command) { diff --git a/cmd/air/air_test.go b/cmd/air/air_test.go index 11e4546d21d..aa939bd421a 100644 --- a/cmd/air/air_test.go +++ b/cmd/air/air_test.go @@ -6,6 +6,7 @@ import ( "strings" "testing" + "github.com/databricks/cli/cmd/root" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" ) @@ -14,7 +15,7 @@ import ( // expected subcommand, so none is accidentally dropped from New. func TestNewRegistersAllSubcommands(t *testing.T) { registered := make(map[string]bool) - for _, c := range New().Commands() { + for _, c := range root.NewCommand(t.Context(), Spec).Commands() { registered[c.Name()] = true } @@ -26,7 +27,7 @@ func TestNewRegistersAllSubcommands(t *testing.T) { } func TestNewHelpMetadata(t *testing.T) { - cmd := New() + cmd := root.NewCommand(t.Context(), Spec) assert.Equal(t, "development", cmd.GroupID) assert.Equal(t, "Run and manage AI Runtime workloads on serverless GPU compute", cmd.Short) @@ -35,7 +36,7 @@ func TestNewHelpMetadata(t *testing.T) { // TestNewGroupsSubcommands asserts every subcommand is listed under a help // heading, so none falls into cobra's catch-all "Additional Commands". func TestNewGroupsSubcommands(t *testing.T) { - cmd := New() + cmd := root.NewCommand(t.Context(), Spec) groups := map[string]string{} for _, g := range cmd.Groups() { groups[g.ID] = g.Title @@ -48,7 +49,7 @@ func TestNewGroupsSubcommands(t *testing.T) { } func TestHelpFooterOnlyOnAirCommand(t *testing.T) { - cmd := New() + cmd := root.NewCommand(t.Context(), Spec) var airOut bytes.Buffer cmd.SetOut(&airOut) cmd.HelpFunc()(cmd, nil) diff --git a/cmd/air/pools_test.go b/cmd/air/pools_test.go index 0062c48f61a..6ec2fe2fc2d 100644 --- a/cmd/air/pools_test.go +++ b/cmd/air/pools_test.go @@ -36,7 +36,7 @@ func TestPoolsCommandShape(t *testing.T) { assert.NoError(t, get.Args(get, []string{})) // id optional: resolved when there's one pool assert.Error(t, get.Args(get, []string{"a", "b"})) - assert.True(t, hasSubcommand(New(), "pools")) + assert.True(t, hasSubcommand(root.NewCommand(t.Context(), Spec), "pools")) assert.False(t, hasSubcommand(newListCommand(), "pools")) assert.False(t, hasSubcommand(newGetCommand(), "pool")) } diff --git a/cmd/aitools/aitools.go b/cmd/aitools/aitools.go index 451e8cee523..503bfc634ec 100644 --- a/cmd/aitools/aitools.go +++ b/cmd/aitools/aitools.go @@ -1,30 +1,34 @@ package aitools import ( + "context" "strings" + "github.com/databricks/cli/cmd/root" + "github.com/databricks/cli/libs/aitools/agents" "github.com/spf13/cobra" ) -func NewAitoolsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "aitools", - Short: "Databricks skills and plugins for coding agents", - Long: `Install Databricks skills and plugins into your coding agent so it can work +// Spec declares the aitools command. +var Spec = root.CommandSpec{ + Use: "aitools", + Short: "Databricks skills and plugins for coding agents", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Install Databricks skills and plugins into your coding agent so it can work effectively with Databricks resources (bundles, jobs, SQL, and more). Supported agents: ` + strings.Join(agents.SupportedNames(), ", ") + `. Skills and plugins are sourced from -https://github.com/databricks/databricks-agent-skills`, - } +https://github.com/databricks/databricks-agent-skills` cmd.AddCommand(NewInstallCmd()) cmd.AddCommand(NewUpdateCmd()) cmd.AddCommand(NewUninstallCmd()) cmd.AddCommand(NewListCmd()) cmd.AddCommand(NewVersionCmd()) - - return cmd } diff --git a/cmd/aitools/install_test.go b/cmd/aitools/install_test.go index 0b80056009f..c24b8cc9b3c 100644 --- a/cmd/aitools/install_test.go +++ b/cmd/aitools/install_test.go @@ -1082,12 +1082,12 @@ func TestInstallOutputJSONThroughRoot(t *testing.T) { recordPluginInstallsFn = func(context.Context, string, map[string]installer.PluginRecord, string) error { return nil } ctx := telemetry.WithNewLogger(cmdio.MockDiscard(t.Context())) - cli := root.New(ctx) - cli.AddCommand(NewInstallCmd()) + cli := root.NewTree(ctx) + cli.Add(Spec) var out, errOut bytes.Buffer cli.SetOut(&out) cli.SetErr(&errOut) - err := root.Execute(ctx, cli, []string{"install", "--agents", "codex", "--scope", "global", "--output", "json"}) + err := cli.Execute(ctx, []string{"aitools", "install", "--agents", "codex", "--scope", "global", "--output", "json"}) require.ErrorIs(t, err, root.ErrAlreadyPrinted) assert.NotContains(t, errOut.String(), "Error:") diff --git a/cmd/api/api.go b/cmd/api/api.go index e6bd47b8ec2..2caf2ccb95d 100644 --- a/cmd/api/api.go +++ b/cmd/api/api.go @@ -44,12 +44,14 @@ const ( // also live under /accounts/. var accountSegmentRe = regexp.MustCompile(`(^|/)accounts/[^/]+`) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "api", - Short: "Perform Databricks API call", - } +// Spec declares the api command. +var Spec = root.CommandSpec{ + Use: "api", + Short: "Perform Databricks API call", + Build: buildCommand, +} +func buildCommand(ctx context.Context, cmd *cobra.Command) { cmd.AddCommand( makeCommand(http.MethodGet), makeCommand(http.MethodHead), @@ -58,8 +60,6 @@ func New() *cobra.Command { makeCommand(http.MethodPatch), makeCommand(http.MethodDelete), ) - - return cmd } func makeCommand(method string) *cobra.Command { diff --git a/cmd/auth/auth.go b/cmd/auth/auth.go index bfba43c7c76..2784e6e164f 100644 --- a/cmd/auth/auth.go +++ b/cmd/auth/auth.go @@ -6,6 +6,8 @@ import ( "fmt" "strings" + "github.com/databricks/cli/cmd/root" + "github.com/databricks/cli/libs/auth" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/databrickscfg/profile" @@ -13,18 +15,21 @@ import ( "github.com/spf13/cobra" ) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "auth", - Short: "Authentication related commands", - Long: `Authentication related commands. For more information regarding how +// Spec declares the auth command. +var Spec = root.CommandSpec{ + Use: "auth", + Short: "Authentication related commands", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Authentication related commands. For more information regarding how authentication for the Databricks CLI and SDKs work please refer to the documentation linked below. AWS: https://docs.databricks.com/dev-tools/auth/index.html Azure: https://learn.microsoft.com/azure/databricks/dev-tools/auth -GCP: https://docs.gcp.databricks.com/dev-tools/auth/index.html`, - } +GCP: https://docs.gcp.databricks.com/dev-tools/auth/index.html` var authArguments auth.AuthArguments cmd.PersistentFlags().StringVar(&authArguments.Host, "host", "", "Databricks Host") @@ -39,7 +44,6 @@ GCP: https://docs.gcp.databricks.com/dev-tools/auth/index.html`, cmd.AddCommand(newDockerCommand()) cmd.AddCommand(newDescribeCommand()) cmd.AddCommand(newSwitchCommand()) - return cmd } func promptForHost(ctx context.Context) (string, error) { diff --git a/cmd/auth/auth_test.go b/cmd/auth/auth_test.go index 10cb67409b9..e4bb631c35a 100644 --- a/cmd/auth/auth_test.go +++ b/cmd/auth/auth_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/databricks/cli/cmd/root" - "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio/cmdiotest/termtest" "github.com/databricks/cli/libs/databrickscfg/profile" "github.com/stretchr/testify/assert" @@ -77,18 +76,15 @@ func TestProfileHostConflictViaCobra(t *testing.T) { // Point at a config file that has "profile-1" with host https://www.host1.test. t.Setenv("DATABRICKS_CONFIG_FILE", "./testdata/.databrickscfg") - ctx := cmdctx.GenerateExecId(t.Context()) - cli := root.New(ctx) - cli.AddCommand(New()) + ctx := t.Context() + cli := root.NewTree(ctx) + cli.Add(Spec) - // Set args: auth login --profile profile-1 --host https://other.host.test - cli.SetArgs([]string{ + err := cli.Execute(ctx, []string{ "auth", "login", "--profile", "profile-1", "--host", "https://other.host.test", }) - - _, err := cli.ExecuteContextC(ctx) require.Error(t, err) assert.Contains(t, err.Error(), `--profile "profile-1" has host "https://www.host1.test", which conflicts with --host "https://other.host.test"`) assert.Contains(t, err.Error(), "Use --profile only to select a profile") @@ -98,17 +94,15 @@ func TestProfileHostConflictViaCobra(t *testing.T) { func TestProfileHostConflictTokenViaCobra(t *testing.T) { t.Setenv("DATABRICKS_CONFIG_FILE", "./testdata/.databrickscfg") - ctx := cmdctx.GenerateExecId(t.Context()) - cli := root.New(ctx) - cli.AddCommand(New()) + ctx := t.Context() + cli := root.NewTree(ctx) + cli.Add(Spec) - cli.SetArgs([]string{ + err := cli.Execute(ctx, []string{ "auth", "token", "--profile", "profile-1", "--host", "https://other.host.test", }) - - _, err := cli.ExecuteContextC(ctx) require.Error(t, err) assert.Contains(t, err.Error(), `--profile "profile-1" has host "https://www.host1.test", which conflicts with --host "https://other.host.test"`) } @@ -126,17 +120,15 @@ func TestProfileHostCompatibleViaCobra(t *testing.T) { require.NoError(t, os.WriteFile(configPath, fixture, 0o600)) t.Setenv("DATABRICKS_CONFIG_FILE", configPath) - ctx := cmdctx.GenerateExecId(t.Context()) - cli := root.New(ctx) - cli.AddCommand(New()) + ctx := t.Context() + cli := root.NewTree(ctx) + cli.Add(Spec) - cli.SetArgs([]string{ + err = cli.Execute(ctx, []string{ "auth", "login", "--profile", "profile-1", "--host", "https://www.host1.test", }) - - _, err = cli.ExecuteContextC(ctx) // The command may fail for other reasons (no browser, non-interactive, etc.) // but it should NOT fail with a conflict error. if err != nil { diff --git a/cmd/auth/switch_test.go b/cmd/auth/switch_test.go index 4ad6e112eec..d14477ab7fc 100644 --- a/cmd/auth/switch_test.go +++ b/cmd/auth/switch_test.go @@ -6,6 +6,8 @@ import ( "path/filepath" "testing" + "github.com/databricks/cli/cmd/root" + "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/databrickscfg" "github.com/databricks/databricks-sdk-go/config" @@ -30,7 +32,7 @@ func TestSwitchCommand_WithProfileFlag(t *testing.T) { ctx = cmdio.MockDiscard(ctx) - cmd := New() + cmd := root.NewCommand(t.Context(), Spec) cmd.PersistentFlags().StringP("profile", "p", "", "~/.databrickscfg profile") cmd.SetContext(ctx) cmd.SetArgs([]string{"switch", "--profile", "my-workspace"}) @@ -60,7 +62,7 @@ func TestSwitchCommand_ProfileNotFound(t *testing.T) { ctx = cmdio.MockDiscard(ctx) - cmd := New() + cmd := root.NewCommand(t.Context(), Spec) cmd.PersistentFlags().StringP("profile", "p", "", "~/.databrickscfg profile") cmd.SetContext(ctx) cmd.SetArgs([]string{"switch", "--profile", "nonexistent"}) @@ -86,7 +88,7 @@ func TestSwitchCommand_NonInteractiveNoProfile(t *testing.T) { ctx = cmdio.MockDiscard(ctx) - cmd := New() + cmd := root.NewCommand(t.Context(), Spec) cmd.PersistentFlags().StringP("profile", "p", "", "~/.databrickscfg profile") cmd.SetContext(ctx) cmd.SetArgs([]string{"switch"}) @@ -114,7 +116,7 @@ func TestSwitchCommand_WritesSettingsSection(t *testing.T) { ctx = cmdio.MockDiscard(ctx) - cmd := New() + cmd := root.NewCommand(t.Context(), Spec) cmd.PersistentFlags().StringP("profile", "p", "", "~/.databrickscfg profile") cmd.SetContext(ctx) cmd.SetArgs([]string{"switch", "--profile", "profile-a"}) @@ -129,7 +131,7 @@ func TestSwitchCommand_WritesSettingsSection(t *testing.T) { assert.Contains(t, string(contents), "default_profile = profile-a") // Switch to another profile. - cmd = New() + cmd = root.NewCommand(t.Context(), Spec) cmd.PersistentFlags().StringP("profile", "p", "", "~/.databrickscfg profile") cmd.SetContext(ctx) cmd.SetArgs([]string{"switch", "--profile", "profile-b"}) diff --git a/cmd/bundle/bundle.go b/cmd/bundle/bundle.go index d8334d38289..ad384c8d148 100644 --- a/cmd/bundle/bundle.go +++ b/cmd/bundle/bundle.go @@ -1,15 +1,23 @@ package bundle import ( + "context" + "github.com/databricks/cli/cmd/bundle/deployment" + "github.com/databricks/cli/cmd/root" "github.com/spf13/cobra" ) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "bundle", - Short: "Declarative Automation Bundles let you express data/AI/analytics projects as code.", - Long: `Declarative Automation Bundles let you express data/AI/analytics projects as code. +// Spec declares the bundle command. +var Spec = root.CommandSpec{ + Use: "bundle", + Short: "Declarative Automation Bundles let you express data/AI/analytics projects as code.", + GroupID: "development", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Declarative Automation Bundles let you express data/AI/analytics projects as code. Common workflows: databricks bundle init default-python # Initialize new project @@ -21,9 +29,7 @@ Import existing resources: databricks bundle generate job --existing-job-id 123 --key my_job # Generate job configuration databricks bundle deployment bind my_job 123 # Link to an existing job -Online documentation: https://docs.databricks.com/en/dev-tools/bundles/index.html`, - GroupID: "development", - } +Online documentation: https://docs.databricks.com/en/dev-tools/bundles/index.html` initVariableFlag(cmd) cmd.AddCommand(newDeployCommand()) @@ -40,6 +46,4 @@ Online documentation: https://docs.databricks.com/en/dev-tools/bundles/index.htm cmd.AddCommand(newOpenCommand()) cmd.AddCommand(newPlanCommand()) cmd.AddCommand(newConfigRemoteSyncCommand()) - - return cmd } diff --git a/cmd/cache/cache.go b/cmd/cache/cache.go index 88dec62acc6..a5333a192ab 100644 --- a/cmd/cache/cache.go +++ b/cmd/cache/cache.go @@ -1,19 +1,24 @@ package cache import ( + "context" + + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cache" "github.com/spf13/cobra" ) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "cache", - Short: "Local cache related commands", - Long: "Manage local cache used by the Databricks CLI for improved performance", - } +// Spec declares the cache command. +var Spec = root.CommandSpec{ + Use: "cache", + Short: "Local cache related commands", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = "Manage local cache used by the Databricks CLI for improved performance" cmd.AddCommand(newClearCommand()) - return cmd } func newClearCommand() *cobra.Command { diff --git a/cmd/cmd.go b/cmd/cmd.go index 9bc26de1785..1140d5bc322 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -36,50 +36,23 @@ const ( permissionsGroup = "permissions" ) -// configureGroups adds groups to the command, only if a group -// has at least one available command. When only one group survives -// filtering, the grouping is dropped so Cobra's default "Available -// Commands" heading is used — matching commands that don't define -// groups at all. -func configureGroups(cmd *cobra.Command, groups []cobra.Group) { - filteredGroups := cmdgroup.FilterGroups(groups, cmd.Commands()) - if len(filteredGroups) <= 1 { - for _, sub := range cmd.Commands() { - sub.GroupID = "" - } - return - } - for i := range filteredGroups { - cmd.AddGroup(&filteredGroups[i]) +// withGroups returns spec with a Build that also groups the command's +// subcommands into groups, keeping only groups that have available commands. +func withGroups(spec root.CommandSpec, groups []cobra.Group) root.CommandSpec { + build := spec.Build + spec.Build = func(ctx context.Context, cmd *cobra.Command) { + build(ctx, cmd) + cmdgroup.Configure(cmd, groups) } + return spec } -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()) - - // Hand-written commands that replace a generated workspace command of the - // same name. Cobra resolves duplicate names by position after an unstable - // sort, so the generated command must not be registered at all. - sandboxCmd := sandbox.New() - replacedWorkspaceCommands := map[string]bool{ - sandboxCmd.Name(): true, - } - - // Add workspace subcommands. - workspaceCommands := workspace.All() - for _, cmd := range workspaceCommands { - if replacedWorkspaceCommands[cmd.Name()] { - continue - } +// workspaceSpec returns spec with a Build that also groups the subcommands of +// a generated workspace command and orders its permissions subcommands last. +func workspaceSpec(spec root.CommandSpec) root.CommandSpec { + build := spec.Build + spec.Build = func(ctx context.Context, cmd *cobra.Command) { + build(ctx, cmd) // Order the permissions subcommands after the main commands. for _, sub := range cmd.Commands() { @@ -95,53 +68,58 @@ func New(ctx context.Context) *cobra.Command { sub.GroupID = mainGroup } } + } + return withGroups(spec, []cobra.Group{ + {ID: mainGroup, Title: "Main Commands"}, + {ID: pipelines.ManagementGroupID, Title: "Management Commands"}, + {ID: permissionsGroup, Title: "Permission Commands"}, + }) +} - cli.AddCommand(cmd) - - // Built-in groups for the workspace commands. - groups := []cobra.Group{ - { - ID: mainGroup, - Title: "Main Commands", - }, - { - ID: pipelines.ManagementGroupID, - Title: "Management Commands", - }, - { - ID: permissionsGroup, - Title: "Permission Commands", - }, +// New returns the CLI's command tree. +func New(ctx context.Context) *root.Tree { + cli := root.NewTree(ctx) + + specs := []root.CommandSpec{ + withGroups(account.Spec, account.Groups()), + aircmd.Spec, + aitoolscmd.Spec, + api.Spec, + auth.Spec, + completion.Spec, + bundle.Spec, + cache.Spec, + experimental.Spec, + psql.Spec, + configure.Spec, + fs.Spec, + labs.Spec, + sandbox.Spec, + sync.Spec, + version.Spec, + quickstart.Spec, + selftest.Spec, + ssh.Spec, + } + // Hand-written commands that replace a generated workspace command of the + // same name. Cobra resolves duplicate names by position after an unstable + // sort, so the generated command must not be added at all. + name := func(spec root.CommandSpec) string { return strings.Fields(spec.Use)[0] } + replaced := map[string]bool{ + name(sandbox.Spec): true, + } + for _, spec := range workspace.All() { + if !replaced[name(spec)] { + specs = append(specs, workspaceSpec(spec)) } - - configureGroups(cmd, groups) } - - // Add other subcommands. - cli.AddCommand(aircmd.New()) - 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(sandboxCmd) - cli.AddCommand(sync.New()) - cli.AddCommand(version.New()) - cli.AddCommand(quickstart.New()) - cli.AddCommand(selftest.New()) - cli.AddCommand(ssh.New()) + cli.Add(specs...) // Add workspace command groups, filtering out empty groups or groups with only hidden commands. - configureGroups(cli, append(workspace.Groups(), cobra.Group{ + cli.AddGroups(append(workspace.Groups(), cobra.Group{ ID: "development", Title: "Developer Tools", - })) + })...) return cli } diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go deleted file mode 100644 index 0ed19a1a2bb..00000000000 --- a/cmd/cmd_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package cmd_test - -import ( - "testing" - - "github.com/databricks/cli/cmd" - "github.com/stretchr/testify/assert" -) - -func TestRootCommandNamesAreUnique(t *testing.T) { - cli := cmd.New(t.Context()) - - seen := map[string]bool{} - for _, sub := range cli.Commands() { - assert.False(t, seen[sub.Name()], "duplicate top-level command %q", sub.Name()) - seen[sub.Name()] = true - } -} diff --git a/cmd/completion/completion.go b/cmd/completion/completion.go index e69c3eaa4d9..892d7e7a946 100644 --- a/cmd/completion/completion.go +++ b/cmd/completion/completion.go @@ -12,22 +12,20 @@ import ( "github.com/spf13/cobra" ) -// New returns the "completion" command with shell subcommands and -// install/uninstall/status subcommands. Providing a command named -// "completion" prevents Cobra's InitDefaultCompletionCmd from generating -// its default, so we replicate the shell subcommands here with runtime -// writer resolution to avoid the frozen-writer bug. -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "completion", - Short: "Generate the autocompletion script for the specified shell", - Long: `Generate the autocompletion script for databricks for the specified shell. +// Spec declares the completion command. +var Spec = root.CommandSpec{ + Use: "completion", + Short: "Generate the autocompletion script for the specified shell", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Generate the autocompletion script for databricks for the specified shell. See each sub-command's help for details on how to use the generated script. -`, - Args: cobra.NoArgs, - ValidArgsFunction: cobra.NoFileCompletions, - RunE: root.ReportUnknownSubcommand, - } +` + cmd.Args = cobra.NoArgs + cmd.ValidArgsFunction = cobra.NoFileCompletions + cmd.RunE = root.ReportUnknownSubcommand cmd.AddCommand( newBashCmd(), @@ -38,8 +36,6 @@ See each sub-command's help for details on how to use the generated script. newUninstallCmd(), newStatusCmd(), ) - - return cmd } func newBashCmd() *cobra.Command { diff --git a/cmd/configure/configure.go b/cmd/configure/configure.go index 35ffad26d83..2419a43b05f 100644 --- a/cmd/configure/configure.go +++ b/cmd/configure/configure.go @@ -1,9 +1,12 @@ package configure import ( + "context" "errors" "fmt" + "github.com/databricks/cli/cmd/root" + "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/databrickscfg" "github.com/databricks/cli/libs/databrickscfg/cfgpickers" @@ -93,19 +96,22 @@ func configureNonInteractive(cmd *cobra.Command, flags *configureFlags, cfg *con return nil } -func newConfigureCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "configure", - Short: "Configure authentication", - Long: `Configure authentication. +// Spec declares the configure command. +var Spec = root.CommandSpec{ + Use: "configure", + Short: "Configure authentication", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Configure authentication. This command adds a profile to your ~/.databrickscfg file. You can write to a different file by setting the DATABRICKS_CONFIG_FILE environment variable. If this command is invoked in non-interactive mode, it will read the token from stdin. The host must be specified with the --host flag or the DATABRICKS_HOST environment variable. - `, - } + ` var flags configureFlags flags.Register(cmd) @@ -181,10 +187,4 @@ The host must be specified with the --host flag or the DATABRICKS_HOST environme }, clearKeys...) return err } - - return cmd -} - -func New() *cobra.Command { - return newConfigureCommand() } diff --git a/cmd/configure/configure_test.go b/cmd/configure/configure_test.go index 44d75999522..8aa03ba7db8 100644 --- a/cmd/configure/configure_test.go +++ b/cmd/configure/configure_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/databricks/cli/cmd" - "github.com/databricks/cli/cmd/root" "github.com/stretchr/testify/assert" "gopkg.in/ini.v1" ) @@ -56,7 +55,7 @@ func TestDefaultConfigureNoInteractive(t *testing.T) { os.Stdin = inp cmd := cmd.New(ctx) - err := root.Execute(ctx, cmd, []string{"configure", "--token", "--host", "https://host"}) + err := cmd.Execute(ctx, []string{"configure", "--token", "--host", "https://host"}) assert.NoError(t, err) cfgPath := filepath.Join(tempHomeDir, ".databrickscfg") @@ -88,7 +87,7 @@ func TestConfigFileFromEnvNoInteractive(t *testing.T) { os.Stdin = inp cmd := cmd.New(ctx) - err := root.Execute(ctx, cmd, []string{"configure", "--token", "--host", "https://host"}) + err := cmd.Execute(ctx, []string{"configure", "--token", "--host", "https://host"}) assert.NoError(t, err) _, err = os.Stat(cfgPath) @@ -126,7 +125,7 @@ func TestEnvVarsConfigureNoInteractive(t *testing.T) { t.Setenv("DATABRICKS_METADATA_SERVICE_URL", "https://metadata") cmd := cmd.New(ctx) - err := root.Execute(ctx, cmd, []string{"configure", "--token"}) + err := cmd.Execute(ctx, []string{"configure", "--token"}) assert.NoError(t, err) _, err = os.Stat(cfgPath) @@ -157,7 +156,7 @@ func TestEnvVarsConfigureNoArgsNoInteractive(t *testing.T) { t.Setenv("DATABRICKS_TOKEN", "secret") cmd := cmd.New(ctx) - err := root.Execute(ctx, cmd, []string{"configure"}) + err := cmd.Execute(ctx, []string{"configure"}) assert.NoError(t, err) _, err = os.Stat(cfgPath) @@ -186,7 +185,7 @@ func TestEnvProfileConfigureNoInteractive(t *testing.T) { t.Setenv("DATABRICKS_CONFIG_PROFILE", "FROM-ENV") cmd := cmd.New(ctx) - err := root.Execute(ctx, cmd, []string{"configure", "--token", "--host", "https://host"}) + err := cmd.Execute(ctx, []string{"configure", "--token", "--host", "https://host"}) assert.NoError(t, err) cfg, err := ini.Load(cfgPath) @@ -212,7 +211,7 @@ func TestProfileShorthandOverridesEnvConfigureNoInteractive(t *testing.T) { t.Setenv("DATABRICKS_CONFIG_PROFILE", "FROM-ENV") cmd := cmd.New(ctx) - err := root.Execute(ctx, cmd, []string{"configure", "--token", "--host", "https://host", "-p", "FROM-FLAG"}) + err := cmd.Execute(ctx, []string{"configure", "--token", "--host", "https://host", "-p", "FROM-FLAG"}) assert.NoError(t, err) cfg, err := ini.Load(cfgPath) @@ -239,7 +238,7 @@ func TestCustomProfileConfigureNoInteractive(t *testing.T) { os.Stdin = inp cmd := cmd.New(ctx) - err := root.Execute(ctx, cmd, []string{"configure", "--token", "--host", "https://host", "--profile", "CUSTOM"}) + err := cmd.Execute(ctx, []string{"configure", "--token", "--host", "https://host", "--profile", "CUSTOM"}) assert.NoError(t, err) _, err = os.Stat(cfgPath) diff --git a/cmd/experimental/experimental.go b/cmd/experimental/experimental.go index 45349fcd29b..a8252324216 100644 --- a/cmd/experimental/experimental.go +++ b/cmd/experimental/experimental.go @@ -1,31 +1,35 @@ package experimental import ( + "context" + + "github.com/databricks/cli/cmd/root" aitoolscmd "github.com/databricks/cli/experimental/aitools/cmd" postgrescmd "github.com/databricks/cli/experimental/postgres/cmd" "github.com/spf13/cobra" ) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "experimental", - Short: "Experimental commands that may change in future versions", - Hidden: true, - Long: `Experimental commands that may change in future versions. +// Spec declares the experimental command. +var Spec = root.CommandSpec{ + Use: "experimental", + Short: "Experimental commands that may change in future versions", + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Experimental commands that may change in future versions. ╔══════════════════════════════════════════════════════════════════╗ ║ 🚧 EXPERIMENTAL: These commands may change in future versions ║ ╚══════════════════════════════════════════════════════════════════╝ These commands provide early access to new features that are still under -development. They may change or be removed in future versions without notice.`, - } +development. They may change or be removed in future versions without notice.` cmd.AddCommand(newAirCmd()) cmd.AddCommand(aitoolscmd.NewAitoolsCmd()) cmd.AddCommand(newGenieCmd()) cmd.AddCommand(postgrescmd.New()) cmd.AddCommand(newWorkspaceOpenCommand()) - - return cmd } diff --git a/cmd/fs/fs.go b/cmd/fs/fs.go index 074bd31a64c..5896eca74ba 100644 --- a/cmd/fs/fs.go +++ b/cmd/fs/fs.go @@ -1,16 +1,22 @@ package fs import ( + "context" + + "github.com/databricks/cli/cmd/root" "github.com/spf13/cobra" ) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "fs", - Short: "Filesystem related commands", - Long: `Commands to do file system operations on DBFS, UC Volumes and UC Skills.`, - GroupID: "workspace", - } +// Spec declares the fs command. +var Spec = root.CommandSpec{ + Use: "fs", + Short: "Filesystem related commands", + GroupID: "workspace", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Commands to do file system operations on DBFS, UC Volumes and UC Skills.` cmd.AddCommand( newCatCommand(), @@ -19,6 +25,4 @@ func New() *cobra.Command { newMkdirCommand(), newRmCommand(), ) - - return cmd } diff --git a/cmd/labs/labs.go b/cmd/labs/labs.go index c8c8546ae46..777e6133b8d 100644 --- a/cmd/labs/labs.go +++ b/cmd/labs/labs.go @@ -4,16 +4,20 @@ import ( "context" "github.com/databricks/cli/cmd/labs/project" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/log" "github.com/spf13/cobra" ) -func New(ctx context.Context) *cobra.Command { - cmd := &cobra.Command{ - Use: "labs", - Short: "Manage Databricks Labs installations", - Long: `Manage experimental Databricks Labs apps`, - } +// Spec declares the labs command. +var Spec = root.CommandSpec{ + Use: "labs", + Short: "Manage Databricks Labs installations", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Manage experimental Databricks Labs apps` cmd.AddGroup(&cobra.Group{ ID: "labs", @@ -32,10 +36,9 @@ func New(ctx context.Context) *cobra.Command { all, err := project.Installed(ctx) if err != nil { log.Errorf(ctx, "Cannot retrieve installed labs: %s", err) - return cmd + return } for _, v := range all { v.Register(cmd) } - return cmd } diff --git a/cmd/psql/psql.go b/cmd/psql/psql.go index b07f37f6c6c..217577f6243 100644 --- a/cmd/psql/psql.go +++ b/cmd/psql/psql.go @@ -18,16 +18,16 @@ import ( "github.com/spf13/cobra" ) -func New() *cobra.Command { - return newLakebaseConnectCommand() +// Spec declares the psql command. +var Spec = root.CommandSpec{ + Use: "psql [TARGET] [flags] [-- PSQL_ARGS...]", + Short: "Connect to a Lakebase Postgres database", + GroupID: "database", + Build: buildCommand, } -func newLakebaseConnectCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "psql [TARGET] [flags] [-- PSQL_ARGS...]", - Short: "Connect to a Lakebase Postgres database", - GroupID: "database", - Long: `Connect to a Lakebase Postgres database. +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Connect to a Lakebase Postgres database. Requires psql to be installed. @@ -51,8 +51,7 @@ Examples: databricks psql --project my-project -- -d mydb For more information, see: https://docs.databricks.com/aws/en/oltp/ -`, - } +` var maxRetries int var provisionedFlag, autoscalingFlag bool @@ -196,8 +195,6 @@ For more information, see: https://docs.databricks.com/aws/en/oltp/ return names, cobra.ShellCompDirectiveNoFileComp } - - return cmd } // parseResourcePath extracts project, branch, and endpoint IDs from a resource path. diff --git a/cmd/quickstart/quickstart.go b/cmd/quickstart/quickstart.go index 34ab996ba7a..7cfe4e88e4c 100644 --- a/cmd/quickstart/quickstart.go +++ b/cmd/quickstart/quickstart.go @@ -1,10 +1,12 @@ package quickstart import ( - _ "embed" + "context" "fmt" "strings" + _ "embed" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" "github.com/spf13/cobra" @@ -22,26 +24,27 @@ var humanQuickstart string //go:embed quickstart-agent.md var agentQuickstart string -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "quickstart", - Args: root.NoArgs, - Short: "Print an introduction to the Databricks CLI", - Long: `Print a short introduction to the Databricks CLI: authentication, profiles, +// Spec declares the quickstart command. +var Spec = root.CommandSpec{ + Use: "quickstart", + Short: "Print an introduction to the Databricks CLI", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Args = root.NoArgs + cmd.Long = `Print a short introduction to the Databricks CLI: authentication, profiles, building with Declarative Automation Bundles, and where to go next. Prints a human-friendly guide by default. When stdout is not an interactive terminal (for example, when a coding agent runs the command), it prints a -denser, agent-oriented version instead.`, - } +denser, agent-oriented version instead.` cmd.RunE = func(cmd *cobra.Command, args []string) error { content := quickstartFor(cmdio.IsPromptSupported(cmd.Context())) _, err := fmt.Fprintln(cmd.OutOrStdout(), content) return err } - - return cmd } // quickstartFor returns the quickstart text for the caller. Interactive diff --git a/cmd/root/auth_test.go b/cmd/root/auth_test.go index afc022efce1..98f0d431d8d 100644 --- a/cmd/root/auth_test.go +++ b/cmd/root/auth_test.go @@ -282,7 +282,7 @@ func TestMustWorkspaceClientRewritesInvalidRefreshTokenForPickedProfile(t *testi ctx, tt := cmdio.SetupTest(t.Context(), cmdio.TestOptions{PromptSupported: true}) t.Cleanup(tt.Done) - cmd := New(ctx) + cmd := newRootCommand(ctx) err := MustWorkspaceClient(cmd, []string{}) require.Error(t, err) @@ -306,7 +306,7 @@ func TestMustAccountClientWorksWithDatabricksCfg(t *testing.T) { 0o755) require.NoError(t, err) - cmd := New(t.Context()) + cmd := newRootCommand(t.Context()) t.Setenv("DATABRICKS_CONFIG_FILE", configFile) err = MustAccountClient(cmd, []string{}) @@ -318,7 +318,7 @@ func TestMustAccountClientWorksWithNoDatabricksCfgButEnvironmentVariables(t *tes ctx, tt := cmdio.SetupTest(t.Context(), cmdio.TestOptions{PromptSupported: true}) t.Cleanup(tt.Done) - cmd := New(ctx) + cmd := newRootCommand(ctx) t.Setenv("DATABRICKS_HOST", "https://accounts.azuredatabricks.net/") t.Setenv("DATABRICKS_TOKEN", "foobar") t.Setenv("DATABRICKS_ACCOUNT_ID", "1111") @@ -332,7 +332,7 @@ func TestMustAccountClientErrorsWithNoDatabricksCfg(t *testing.T) { ctx, tt := cmdio.SetupTest(t.Context(), cmdio.TestOptions{PromptSupported: true}) t.Cleanup(tt.Done) - cmd := New(ctx) + cmd := newRootCommand(ctx) err := MustAccountClient(cmd, []string{}) require.ErrorContains(t, err, "no configuration file found at") @@ -357,7 +357,7 @@ func TestMustAnyClientCanCreateWorkspaceClient(t *testing.T) { ctx, tt := cmdio.SetupTest(t.Context(), cmdio.TestOptions{PromptSupported: true}) t.Cleanup(tt.Done) - cmd := New(ctx) + cmd := newRootCommand(ctx) t.Setenv("DATABRICKS_CONFIG_FILE", configFile) isAccount, err := MustAnyClient(cmd, []string{}) @@ -388,7 +388,7 @@ func TestMustAnyClientCanCreateAccountClient(t *testing.T) { ctx, tt := cmdio.SetupTest(t.Context(), cmdio.TestOptions{PromptSupported: true}) t.Cleanup(tt.Done) - cmd := New(ctx) + cmd := newRootCommand(ctx) t.Setenv("DATABRICKS_CONFIG_FILE", configFile) isAccount, err := MustAnyClient(cmd, []string{}) @@ -414,7 +414,7 @@ func TestMustAnyClientWithEmptyDatabricksCfg(t *testing.T) { ctx, tt := cmdio.SetupTest(t.Context(), cmdio.TestOptions{PromptSupported: true}) t.Cleanup(tt.Done) - cmd := New(ctx) + cmd := newRootCommand(ctx) t.Setenv("DATABRICKS_CONFIG_FILE", configFile) @@ -485,7 +485,7 @@ token = flag-token ctx := cmdio.MockDiscard(t.Context()) ctx = SkipLoadBundle(ctx) - cmd := New(ctx) + cmd := newRootCommand(ctx) if tc.profileFlag != "" { err := cmd.Flag("profile").Value.Set(tc.profileFlag) @@ -521,7 +521,7 @@ token = tst-token ctx := cmdio.MockDiscard(t.Context()) ctx = SkipLoadBundle(ctx) - cmd := New(ctx) + cmd := newRootCommand(ctx) err = cmd.Flag("profile").Value.Set("tst-svc") require.NoError(t, err) @@ -554,7 +554,7 @@ host = https://tst.cloud.databricks.test ctx := cmdio.MockDiscard(t.Context()) ctx = SkipLoadBundle(ctx) - cmd := New(ctx) + cmd := newRootCommand(ctx) err = cmd.Flag("profile").Value.Set("host-only") require.NoError(t, err) @@ -590,7 +590,7 @@ token = tst-token ctx := cmdio.MockDiscard(t.Context()) ctx = SkipLoadBundle(ctx) - cmd := New(ctx) + cmd := newRootCommand(ctx) err = MustWorkspaceClient(cmd, []string{}) require.NoError(t, err) @@ -621,7 +621,7 @@ token = tst-token t.Setenv("DATABRICKS_HOST", "https://accounts.dev.databricks.test") t.Setenv("DATABRICKS_TOKEN", "dev-token") - cmd := New(t.Context()) + cmd := newRootCommand(t.Context()) err = cmd.Flag("profile").Value.Set("acc-tst") require.NoError(t, err) @@ -880,7 +880,7 @@ workspace_id = none ctx, tt := cmdio.SetupTest(t.Context(), cmdio.TestOptions{PromptSupported: true}) t.Cleanup(tt.Done) - cmd := New(ctx) + cmd := newRootCommand(ctx) require.NoError(t, cmd.PersistentFlags().Set("profile", "skipws")) // Workspace path returns ErrAccountOnlyProfile. MustAnyClient must @@ -945,7 +945,7 @@ token = named-token ctx := cmdio.MockDiscard(t.Context()) ctx = SkipLoadBundle(ctx) - cmd := New(ctx) + cmd := newRootCommand(ctx) err = MustWorkspaceClient(cmd, []string{}) require.NoError(t, err) @@ -982,7 +982,7 @@ password = pass ctx := cmdio.MockDiscard(t.Context()) ctx = SkipLoadBundle(ctx) - cmd := New(ctx) + cmd := newRootCommand(ctx) err = MustWorkspaceClient(cmd, []string{}) require.NoError(t, err) @@ -1048,7 +1048,7 @@ func TestMustClientResolvesHostMetadataWithCommandLogger(t *testing.T) { logger := slog.New(slog.DiscardHandler) ctx, cancel := context.WithCancel(log.NewContext(cmdio.MockDiscard(t.Context()), logger)) cancel() - cmd := New(SkipLoadBundle(ctx)) + cmd := newRootCommand(SkipLoadBundle(ctx)) require.NoError(t, tc.mustAny(cmd, nil)) require.NotEmpty(t, *seen) for _, r := range *seen { @@ -1073,7 +1073,7 @@ func TestBindHostMetadataLoggerDefersFactoryCall(t *testing.T) { return nil } - cmd := New(SkipLoadBundle(cmdio.MockDiscard(t.Context()))) + cmd := newRootCommand(SkipLoadBundle(cmdio.MockDiscard(t.Context()))) require.Error(t, MustWorkspaceClient(cmd, nil)) assert.Zero(t, factoryCalls) } @@ -1100,7 +1100,7 @@ func TestBindHostMetadataLoggerFallsBackToSDKFetch(t *testing.T) { return nil } - cmd := New(SkipLoadBundle(cmdio.MockDiscard(t.Context()))) + cmd := newRootCommand(SkipLoadBundle(cmdio.MockDiscard(t.Context()))) require.NoError(t, MustWorkspaceClient(cmd, nil)) assert.Equal(t, 1, fetches) } diff --git a/cmd/root/bundle_test.go b/cmd/root/bundle_test.go index ae98df4b028..5c65b43d04f 100644 --- a/cmd/root/bundle_test.go +++ b/cmd/root/bundle_test.go @@ -389,7 +389,7 @@ func TestTargetFlagFull(t *testing.T) { initTargetFlag(cmd) ctx := t.Context() - err := Execute(ctx, cmd, []string{"version", "--target", "development"}) + err := execute(ctx, cmd, []string{"version", "--target", "development"}) assert.NoError(t, err) assert.Equal(t, "development", getTarget(cmd)) @@ -400,7 +400,7 @@ func TestTargetFlagShort(t *testing.T) { initTargetFlag(cmd) ctx := t.Context() - err := Execute(ctx, cmd, []string{"version", "-t", "production"}) + err := execute(ctx, cmd, []string{"version", "-t", "production"}) assert.NoError(t, err) assert.Equal(t, "production", getTarget(cmd)) @@ -413,7 +413,7 @@ func TestTargetEnvironmentFlag(t *testing.T) { initEnvironmentFlag(cmd) ctx := t.Context() - err := Execute(ctx, cmd, []string{"version", "--environment", "development"}) + err := execute(ctx, cmd, []string{"version", "--environment", "development"}) assert.NoError(t, err) assert.Equal(t, "development", getTarget(cmd)) diff --git a/cmd/root/cli_test.go b/cmd/root/cli_test.go new file mode 100644 index 00000000000..28d1ebe139e --- /dev/null +++ b/cmd/root/cli_test.go @@ -0,0 +1,50 @@ +package root_test + +import ( + "bytes" + "testing" + + "github.com/databricks/cli/cmd" + "github.com/databricks/cli/cmd/root" + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestRootCommandNamesAreUnique(t *testing.T) { + cli := root.BuildAll(t.Context(), cmd.New(t.Context())) + + seen := map[string]bool{} + for _, sub := range cli.Commands() { + assert.False(t, seen[sub.Name()], "duplicate top-level command %q", sub.Name()) + seen[sub.Name()] = true + } +} + +// Root help only shows what placeholders show, so it must not depend on +// whether commands are built. +func TestRootHelpIsTheSameBeforeAndAfterBuilding(t *testing.T) { + help := func(buildAll bool) string { + ctx := t.Context() + var out bytes.Buffer + cli := cmd.New(ctx) + if buildAll { + root.BuildAll(ctx, cli) + } + cli.SetOut(&out) + cli.SetErr(&bytes.Buffer{}) + require.NoError(t, cli.Execute(ctx, []string{"--help"})) + return out.String() + } + assert.Equal(t, help(true), help(false)) +} + +// Logs use underscores to separate the names of commands. +func TestCommandNamesDontUseUnderscores(t *testing.T) { + queue := []*cobra.Command{root.BuildAll(t.Context(), cmd.New(t.Context()))} + for len(queue) > 0 { + cmd := queue[0] + assert.NotContains(t, cmd.Name(), "_") + queue = append(queue[1:], cmd.Commands()...) + } +} diff --git a/cmd/root/command_spec.go b/cmd/root/command_spec.go new file mode 100644 index 00000000000..18edf59993f --- /dev/null +++ b/cmd/root/command_spec.go @@ -0,0 +1,68 @@ +package root + +import ( + "context" + "fmt" + "reflect" + "slices" + + "github.com/spf13/cobra" +) + +// CommandSpec declares a command. Top-level commands are added to a [Tree] as +// specs, so that each is only built when an invocation needs it. Until then, +// the tree holds a placeholder with the spec's fields, which are what the root +// shows about the command in help, completion, and suggestions. Build +// completes a command that already has these fields, for example with its +// flags, run function, and subcommands. [NewCommand] panics if Build changes +// them. +type CommandSpec struct { + Use string + Short string + GroupID string + Aliases []string + SuggestFor []string + Hidden bool + Deprecated string + + Build func(ctx context.Context, cmd *cobra.Command) +} + +// command returns a command with the spec's fields. +func (s CommandSpec) command() *cobra.Command { + return &cobra.Command{ + Use: s.Use, + Short: s.Short, + GroupID: s.GroupID, + Aliases: slices.Clone(s.Aliases), + SuggestFor: slices.Clone(s.SuggestFor), + Hidden: s.Hidden, + Deprecated: s.Deprecated, + } +} + +// specFields returns the spec fields of cmd, without Build. +func specFields(cmd *cobra.Command) CommandSpec { + return CommandSpec{ + Use: cmd.Use, + Short: cmd.Short, + GroupID: cmd.GroupID, + Aliases: cmd.Aliases, + SuggestFor: cmd.SuggestFor, + Hidden: cmd.Hidden, + Deprecated: cmd.Deprecated, + } +} + +// NewCommand builds the command that spec declares. Use it to add commands +// below the top level, which are built together with their parent. Their +// parent's help shows the spec's fields too, so Build must not change them. +func NewCommand(ctx context.Context, spec CommandSpec) *cobra.Command { + cmd := spec.command() + spec.Build(ctx, cmd) + // Placeholders show the spec's fields, so the command must show the same. + if !reflect.DeepEqual(specFields(cmd), specFields(spec.command())) { + panic(fmt.Sprintf("root: building %q changed fields that its spec declares; set them in the spec instead", spec.Use)) + } + return cmd +} diff --git a/cmd/root/command_spec_test.go b/cmd/root/command_spec_test.go new file mode 100644 index 00000000000..c145354b094 --- /dev/null +++ b/cmd/root/command_spec_test.go @@ -0,0 +1,46 @@ +package root_test + +import ( + "context" + "reflect" + "testing" + + "github.com/databricks/cli/cmd/root" + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" +) + +// Every spec field must reach the command, and changing it while building +// must panic. This fails if a field is added to Spec but not handled. +func TestSpecFields(t *testing.T) { + specType := reflect.TypeFor[root.CommandSpec]() + for i := range specType.NumField() { + field := specType.Field(i) + if field.Name == "Build" { + continue + } + t.Run(field.Name, func(t *testing.T) { + spec := root.CommandSpec{Use: "cmd"} + set := func(v reflect.Value) { + switch v.Kind() { + case reflect.String: + v.SetString(v.String() + "x") + case reflect.Bool: + v.SetBool(!v.Bool()) + case reflect.Slice: + v.Set(reflect.Append(v, reflect.ValueOf("x"))) + default: + t.Fatalf("unhandled kind %s", v.Kind()) + } + } + set(reflect.ValueOf(&spec).Elem().Field(i)) + + spec.Build = func(context.Context, *cobra.Command) {} + cmd := root.NewCommand(t.Context(), spec) + assert.Equal(t, reflect.ValueOf(spec).Field(i).Interface(), reflect.ValueOf(cmd).Elem().FieldByName(field.Name).Interface()) + + spec.Build = func(_ context.Context, cmd *cobra.Command) { set(reflect.ValueOf(cmd).Elem().FieldByName(field.Name)) } + assert.Panics(t, func() { root.NewCommand(t.Context(), spec) }) + }) + } +} diff --git a/cmd/root/export_test.go b/cmd/root/export_test.go new file mode 100644 index 00000000000..c5142696dde --- /dev/null +++ b/cmd/root/export_test.go @@ -0,0 +1,13 @@ +package root + +import ( + "context" + + "github.com/spf13/cobra" +) + +// BuildAll builds every command in t and returns the root command, for tests +// that walk the whole tree. +func BuildAll(ctx context.Context, t *Tree) *cobra.Command { + return t.buildAll(ctx) +} diff --git a/cmd/fuzz_panic_test.go b/cmd/root/fuzz_panic_test.go similarity index 98% rename from cmd/fuzz_panic_test.go rename to cmd/root/fuzz_panic_test.go index 970ca17f0a8..1fc8fd9c17d 100644 --- a/cmd/fuzz_panic_test.go +++ b/cmd/root/fuzz_panic_test.go @@ -1,4 +1,4 @@ -package cmd_test +package root_test import ( "bytes" @@ -12,6 +12,7 @@ import ( "time" "github.com/databricks/cli/cmd" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/logdiag" @@ -90,7 +91,7 @@ func newFuzzHarness(t *testing.T) *fuzzHarness { baseCtx = cmdctx.SetAccountClient(baseCtx, ac) baseCtx = cmdio.MockDiscard(baseCtx) - cli := cmd.New(baseCtx) + cli := root.BuildAll(baseCtx, cmd.New(baseCtx)) // Replace the real PersistentPreRunE (IO/logger/telemetry/user-agent init) // with a no-op so it doesn't clobber the context we just set up. diff --git a/cmd/root/root.go b/cmd/root/root.go index 52e14eae0e7..d684688c870 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -24,7 +24,7 @@ import ( "github.com/spf13/cobra" ) -func New(ctx context.Context) *cobra.Command { +func newRootCommand(ctx context.Context) *cobra.Command { cmd := &cobra.Command{ Use: "databricks", Short: "Databricks CLI", @@ -114,11 +114,10 @@ func flagErrorFunc(c *cobra.Command, err error) error { return fmt.Errorf("%w\n\n%s", err, c.UsageString()) } -// Execute runs cmd with args, which select the subcommand to run. It is called -// by main.main() with the arguments after the program name. Unlike +// execute runs cmd with args, which select the subcommand to run. Unlike // [cobra.Command.SetArgs], nil args mean no arguments rather than the process // arguments. -func Execute(ctx context.Context, cmd *cobra.Command, args []string) (err error) { +func execute(ctx context.Context, cmd *cobra.Command, args []string) (err error) { defer func() { r := recover() diff --git a/cmd/root/root_test.go b/cmd/root/root_test.go index c52e7b99dfa..18ea18d23c6 100644 --- a/cmd/root/root_test.go +++ b/cmd/root/root_test.go @@ -46,7 +46,7 @@ func TestExecuteEnrichesAuthErrors(t *testing.T) { return nil } - err := Execute(ctx, cmd, nil) + err := execute(ctx, cmd, nil) require.Error(t, err) output := stderr.String() @@ -72,7 +72,7 @@ func TestExecuteNoEnrichmentWithoutConfigUsed(t *testing.T) { } cmd.SetErr(stderr) - err := Execute(ctx, cmd, nil) + err := execute(ctx, cmd, nil) require.Error(t, err) output := stderr.String() @@ -145,7 +145,7 @@ func TestExecuteAppendsAccountHostHint(t *testing.T) { return nil } - err := Execute(t.Context(), cmd, nil) + err := execute(t.Context(), cmd, nil) require.Error(t, err) output := stderr.String() @@ -174,7 +174,7 @@ func TestExecuteErrAlreadyPrintedNotEnriched(t *testing.T) { } cmd.SetErr(stderr) - err := Execute(ctx, cmd, nil) + err := execute(ctx, cmd, nil) require.Error(t, err) assert.Empty(t, stderr.String()) } @@ -192,6 +192,6 @@ func TestExecuteWithNilArgsRunsWithoutArgs(t *testing.T) { return nil }, } - require.NoError(t, Execute(t.Context(), cmd, nil)) + require.NoError(t, execute(t.Context(), cmd, nil)) assert.Empty(t, got) } diff --git a/cmd/root/tree.go b/cmd/root/tree.go new file mode 100644 index 00000000000..a1e3324b7e8 --- /dev/null +++ b/cmd/root/tree.go @@ -0,0 +1,132 @@ +package root + +import ( + "context" + "fmt" + "io" + "maps" + "slices" + + "github.com/databricks/cli/libs/cmdgroup" + "github.com/spf13/cobra" +) + +// Tree is the CLI's command tree. It owns the root command, so commands can +// only be added as specs and the tree can only run through [Tree.Execute], +// which builds the commands that the args resolve to before running them. +type Tree struct { + cmd *cobra.Command + pending map[*cobra.Command]CommandSpec +} + +// NewTree returns a tree with the CLI's root command and no subcommands. +func NewTree(ctx context.Context) *Tree { + return &Tree{cmd: newRootCommand(ctx), pending: map[*cobra.Command]CommandSpec{}} +} + +// Add adds top-level commands. Each is built when an invocation needs it. +func (t *Tree) Add(specs ...CommandSpec) { + for _, spec := range specs { + // Copy the fields so that the caller changing them later can't make + // the placeholder and the built command differ. + build := spec.Build + spec = specFields(spec.command()) + spec.Build = build + placeholder := spec.command() + // Cobra only lists a command in help and completion if it is + // runnable or has subcommands; a placeholder has no subcommands. + placeholder.RunE = func(cmd *cobra.Command, args []string) error { + return fmt.Errorf("internal error: %s was not built before running", cmd.CommandPath()) + } + t.cmd.AddCommand(placeholder) + t.pending[placeholder] = spec + } +} + +// AddGroups adds the groups that have at least one available top-level +// command, so call it after [Tree.Add]. If at most one group remains, it +// ungroups the top-level commands instead; see [cmdgroup.Configure]. +func (t *Tree) AddGroups(groups ...cobra.Group) { + cmdgroup.Configure(t.cmd, groups) +} + +// SetOut sets the destination for the commands' output. +func (t *Tree) SetOut(w io.Writer) { t.cmd.SetOut(w) } + +// SetErr sets the destination for the commands' error output. +func (t *Tree) SetErr(w io.Writer) { t.cmd.SetErr(w) } + +// SetIn sets the source for the commands' input. +func (t *Tree) SetIn(in io.Reader) { t.cmd.SetIn(in) } + +// Execute builds the commands that args resolve to and runs the command. +func (t *Tree) Execute(ctx context.Context, args []string) error { + t.buildForArgs(ctx, args) + return execute(ctx, t.cmd, args) +} + +// buildAll builds every command and returns the root command. +func (t *Tree) buildAll(ctx context.Context) *cobra.Command { + placeholders := slices.Collect(maps.Keys(t.pending)) + cmds := make([]*cobra.Command, len(placeholders)) + for i, placeholder := range placeholders { + cmds[i] = t.buildPending(ctx, placeholder) + } + // Cobra recomputes the commands' layout on every removal, so remove and + // add them all at once. + t.cmd.RemoveCommand(placeholders...) + t.cmd.AddCommand(cmds...) + return t.cmd +} + +// replace replaces placeholder with the command its spec builds. +func (t *Tree) replace(ctx context.Context, placeholder *cobra.Command) { + cmd := t.buildPending(ctx, placeholder) + t.cmd.RemoveCommand(placeholder) + t.cmd.AddCommand(cmd) +} + +// buildPending builds the command that placeholder stands in for. +func (t *Tree) buildPending(ctx context.Context, placeholder *cobra.Command) *cobra.Command { + spec := t.pending[placeholder] + delete(t.pending, placeholder) + cmd := NewCommand(ctx, spec) + // The root may have ungrouped the placeholder, for example because its + // group has no visible commands. + cmd.GroupID = placeholder.GroupID + return cmd +} + +// buildForArgs builds the command that args resolve to. Cobra picks the +// command to run from args before running any hook, so if it isn't built +// first, cobra runs its placeholder. +func (t *Tree) buildForArgs(ctx context.Context, args []string) { + // Cobra adds its help and completion commands when executing. Add them now + // so that args naming them resolve to them. + t.cmd.InitDefaultHelpCmd() + complete := &cobra.Command{ + Use: cobra.ShellCompRequestCmd, + Aliases: []string{cobra.ShellCompNoDescRequestCmd}, + Hidden: true, + } + t.cmd.AddCommand(complete) + defer t.cmd.RemoveCommand(complete) + + cmd, _, err := t.cmd.Find(args) + if err != nil { + return + } + _, pending := t.pending[cmd] + switch { + case cmd.Parent() == t.cmd && (cmd.Name() == "help" || isCompletionRequest(cmd)): + // Help and completion resolve commands from their own arguments, the + // way cobra parses them. Building everything avoids parsing them here. + t.buildAll(ctx) + case pending: + t.replace(ctx, cmd) + } +} + +func isCompletionRequest(cmd *cobra.Command) bool { + return cmd.Name() == cobra.ShellCompRequestCmd +} diff --git a/cmd/root/tree_test.go b/cmd/root/tree_test.go new file mode 100644 index 00000000000..f3042b59ffc --- /dev/null +++ b/cmd/root/tree_test.go @@ -0,0 +1,111 @@ +package root_test + +import ( + "bytes" + "context" + "io" + "testing" + + "github.com/databricks/cli/cmd/root" + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func newTestRoot(t *testing.T, built *[]string) *root.Tree { + r := root.NewTree(t.Context()) + r.SetOut(io.Discard) + r.SetErr(io.Discard) + spec := func(name string) root.CommandSpec { + return root.CommandSpec{ + Use: name, + Short: name + " commands", + Aliases: []string{name + "-alias"}, + Build: func(ctx context.Context, cmd *cobra.Command) { + *built = append(*built, name) + cmd.AddCommand(&cobra.Command{Use: "child", Run: func(*cobra.Command, []string) {}}) + }, + } + } + r.Add(spec("one"), spec("two")) + return r +} + +func TestExecuteBuildsOnlyWhatArgsResolveTo(t *testing.T) { + for _, tc := range []struct { + name string + args []string + want []string + }{ + {"no args", nil, nil}, + {"unknown command", []string{"unknown"}, nil}, + {"command", []string{"one"}, []string{"one"}}, + {"alias", []string{"one-alias", "child"}, []string{"one"}}, + {"subcommand", []string{"one", "child"}, []string{"one"}}, + {"flag with value before command", []string{"--profile", "two", "two", "child"}, []string{"two"}}, + {"help flag", []string{"two", "--help"}, []string{"two"}}, + {"help", []string{"help", "one"}, []string{"one", "two"}}, + {"help with flag value that looks like a terminator", []string{"help", "--profile", "--", "one"}, []string{"one", "two"}}, + {"completion", []string{cobra.ShellCompRequestCmd, "one", ""}, []string{"one", "two"}}, + {"completion after flag", []string{"--profile", "x", cobra.ShellCompNoDescRequestCmd, "o"}, []string{"one", "two"}}, + } { + t.Run(tc.name, func(t *testing.T) { + var built []string + r := newTestRoot(t, &built) + _ = r.Execute(t.Context(), tc.args) + assert.ElementsMatch(t, tc.want, built) + }) + } +} + +// Cobra keeps the completion command it adds, so later completions must +// still build commands. +func TestRepeatedCompletion(t *testing.T) { + var built []string + r := newTestRoot(t, &built) + _ = r.Execute(t.Context(), []string{cobra.ShellCompRequestCmd, "one", ""}) + built = nil + r.Add(root.CommandSpec{Use: "three", Build: func(context.Context, *cobra.Command) { built = append(built, "three") }}) + _ = r.Execute(t.Context(), []string{cobra.ShellCompRequestCmd, "three", ""}) + assert.Equal(t, []string{"three"}, built) +} + +func TestPlaceholdersAreListed(t *testing.T) { + var built []string + r := newTestRoot(t, &built) + cmd, _, err := root.BuildAll(t.Context(), r).Find([]string{"one", "child"}) + require.NoError(t, err) + assert.Equal(t, "databricks one child", cmd.CommandPath()) + + var unbuilt []string + var out bytes.Buffer + r = newTestRoot(t, &unbuilt) + r.SetOut(&out) + require.NoError(t, r.Execute(t.Context(), []string{"--help"})) + assert.Contains(t, out.String(), "one commands") + assert.Contains(t, out.String(), "two commands") + assert.Empty(t, unbuilt) +} + +// A command keeps the group the root assigned to its placeholder, for example +// when the root ungrouped it because its group has no visible commands. +func TestHiddenCommandInDroppedGroupRuns(t *testing.T) { + r := root.NewTree(t.Context()) + r.SetOut(io.Discard) + r.SetErr(io.Discard) + r.Add( + root.CommandSpec{Use: "visible", GroupID: "a", Build: func(context.Context, *cobra.Command) {}}, + root.CommandSpec{Use: "hidden", GroupID: "b", Hidden: true, Build: func(context.Context, *cobra.Command) {}}, + ) + r.AddGroups(cobra.Group{ID: "a", Title: "A"}, cobra.Group{ID: "b", Title: "B"}) + require.NoError(t, r.Execute(t.Context(), []string{"hidden", "--help"})) +} + +func TestAddCopiesSpecFields(t *testing.T) { + aliases := []string{"old"} + r := root.NewTree(t.Context()) + r.SetOut(io.Discard) + r.Add(root.CommandSpec{Use: "cmd", Aliases: aliases, Build: func(context.Context, *cobra.Command) {}}) + aliases[0] = "new" + require.NoError(t, r.Execute(t.Context(), []string{"old", "--help"})) +} diff --git a/cmd/sandbox/sandbox.go b/cmd/sandbox/sandbox.go index 9b40c16d370..46fd6f9acf0 100644 --- a/cmd/sandbox/sandbox.go +++ b/cmd/sandbox/sandbox.go @@ -1,16 +1,22 @@ package sandbox import ( + "context" + + "github.com/databricks/cli/cmd/root" "github.com/spf13/cobra" ) -// New returns the root command for the sandbox subcommand. -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "sandbox", - Short: "*Beta* Manage Databricks Sandbox environments", - GroupID: "development", - Long: `Manage Databricks Sandbox environments. +// Spec declares the sandbox command. +var Spec = root.CommandSpec{ + Use: "sandbox", + Short: "*Beta* Manage Databricks Sandbox environments", + GroupID: "development", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Manage Databricks Sandbox environments. Sandbox provides SSH-accessible development environments backed by microVM isolation. Each sandbox is a personal sandbox with pre-installed @@ -29,8 +35,7 @@ Common workflows: databricks sandbox create # create a new sandbox databricks sandbox delete my-project # delete a sandbox databricks sandbox status my-project # show sandbox status -`, - } +` cmd.AddCommand(newRegisterCommand()) cmd.AddCommand(newSSHKeyCommand()) @@ -43,6 +48,4 @@ Common workflows: cmd.AddCommand(newStartCommand()) cmd.AddCommand(newStatusCommand()) cmd.AddCommand(newConfigCommand()) - - return cmd } diff --git a/cmd/selftest/selftest.go b/cmd/selftest/selftest.go index b5d25a7e7fb..beaa75a0dc9 100644 --- a/cmd/selftest/selftest.go +++ b/cmd/selftest/selftest.go @@ -1,20 +1,24 @@ package selftest import ( + "context" + + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/cmd/selftest/tui" "github.com/spf13/cobra" ) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "selftest", - Short: "Non functional CLI commands that are useful for testing", - Hidden: true, - } +// Spec declares the selftest command. +var Spec = root.CommandSpec{ + Use: "selftest", + Short: "Non functional CLI commands that are useful for testing", + Hidden: true, + Build: buildCommand, +} +func buildCommand(ctx context.Context, cmd *cobra.Command) { cmd.AddCommand(newSendTelemetry()) cmd.AddCommand(newPanic()) cmd.AddCommand(newPatchWhl()) cmd.AddCommand(tui.New()) - return cmd } diff --git a/cmd/sync/sync.go b/cmd/sync/sync.go index dd56ead34e0..735bc292a06 100644 --- a/cmd/sync/sync.go +++ b/cmd/sync/sync.go @@ -167,13 +167,16 @@ func (f *syncFlags) syncOptionsFromArgs(ctx context.Context, output flags.Output return &opts, nil } -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "sync [flags] SRC DST", - Short: "Synchronize a local directory to a workspace directory", - Args: root.MaximumNArgs(2), - GroupID: "development", - } +// Spec declares the sync command. +var Spec = root.CommandSpec{ + Use: "sync [flags] SRC DST", + Short: "Synchronize a local directory to a workspace directory", + GroupID: "development", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Args = root.MaximumNArgs(2) var f syncFlags cmd.Flags().DurationVar(&f.interval, "interval", 1*time.Second, "file system polling interval (for --watch)") @@ -245,6 +248,4 @@ func New() *cobra.Command { return nil, cobra.ShellCompDirectiveNoFileComp } } - - return cmd } diff --git a/cmd/sync/sync_test.go b/cmd/sync/sync_test.go index e4cb0f183ff..05d30902301 100644 --- a/cmd/sync/sync_test.go +++ b/cmd/sync/sync_test.go @@ -9,6 +9,7 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/vfs" @@ -64,7 +65,7 @@ func TestSyncOptionsFromArgsRequiresSrcAndDst(t *testing.T) { // Flags that sync defines with the names or shorthands of the root's // --output and --profile flags would shadow them. func TestSyncDoesNotShadowRootFlags(t *testing.T) { - cmd := New() + cmd := root.NewCommand(t.Context(), Spec) for _, name := range []string{"output", "profile"} { assert.Nil(t, cmd.LocalFlags().Lookup(name), name) } diff --git a/cmd/version/version.go b/cmd/version/version.go index d0456cac9d5..7ad6a547059 100644 --- a/cmd/version/version.go +++ b/cmd/version/version.go @@ -49,14 +49,17 @@ func renderUpdateCheck(ctx context.Context, result *versioncheck.Result, output return nil } -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "version", - Args: root.NoArgs, - Short: "Retrieve information about the current version of this CLI", - Annotations: map[string]string{ - "template": "Databricks CLI v{{.Version}}\n", - }, +// Spec declares the version command. +var Spec = root.CommandSpec{ + Use: "version", + Short: "Retrieve information about the current version of this CLI", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Args = root.NoArgs + cmd.Annotations = map[string]string{ + "template": "Databricks CLI v{{.Version}}\n", } var check bool @@ -69,6 +72,4 @@ func New() *cobra.Command { } return cmdio.Render(ctx, build.GetInfo()) } - - return cmd } diff --git a/cmd/workspace/access-control/access-control.go b/cmd/workspace/access-control/access-control.go index f3571d21c3f..a77bc0af21a 100644 --- a/cmd/workspace/access-control/access-control.go +++ b/cmd/workspace/access-control/access-control.go @@ -3,6 +3,7 @@ package access_control import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,21 +18,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "access-control", - Short: `Rule based Access Control for Databricks Resources.`, - Long: `Rule based Access Control for Databricks Resources.`, - GroupID: "iam", +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "access-control", + Short: `Rule based Access Control for Databricks Resources.`, + GroupID: "iam", - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Rule based Access Control for Databricks Resources.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newCheckPolicy()) @@ -40,8 +45,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start check-policy command diff --git a/cmd/workspace/agent-bricks/agent-bricks.go b/cmd/workspace/agent-bricks/agent-bricks.go index 145b4198dee..fa735437aee 100644 --- a/cmd/workspace/agent-bricks/agent-bricks.go +++ b/cmd/workspace/agent-bricks/agent-bricks.go @@ -3,6 +3,7 @@ package agent_bricks import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,22 +18,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "agent-bricks", - Short: `The Custom LLMs service manages state and powers the UI for the Custom LLM product.`, - Long: `The Custom LLMs service manages state and powers the UI for the Custom LLM - product.`, - GroupID: "agentbricks", - - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "agent-bricks", + Short: `The Custom LLMs service manages state and powers the UI for the Custom LLM product.`, + GroupID: "agentbricks", - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Custom LLMs service manages state and powers the UI for the Custom LLM + product.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newCancelOptimize()) @@ -46,8 +51,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start cancel-optimize command diff --git a/cmd/workspace/agent-kit/agent-kit.go b/cmd/workspace/agent-kit/agent-kit.go index 0946b7e546f..1e1b9c5e252 100644 --- a/cmd/workspace/agent-kit/agent-kit.go +++ b/cmd/workspace/agent-kit/agent-kit.go @@ -3,6 +3,7 @@ package agent_kit import ( + "context" "errors" "fmt" "strings" @@ -20,21 +21,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "agent-kit", - Short: `*Beta* APIs for managing agent memory and durable session state.`, - Long: `This command is in Beta and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "agent-kit", + Short: `*Beta* APIs for managing agent memory and durable session state.`, + GroupID: "agentbricks", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Beta and may change without notice. APIs for managing agent memory and durable session state. This interface is - under active development and may change.`, - GroupID: "agentbricks", - RunE: root.ReportUnknownSubcommand, - } + under active development and may change.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_BETA" - cmd.Annotations["launch_stage_display"] = "Beta" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_BETA", + "launch_stage_display": "Beta", + } // Add methods cmd.AddCommand(newAppendSessionItems()) @@ -77,8 +82,6 @@ APIs for managing agent memory and durable session state. This interface is for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start append-session-items command diff --git a/cmd/workspace/ai-functions/ai-functions.go b/cmd/workspace/ai-functions/ai-functions.go index 306dee5c4b1..de4e53b61ca 100644 --- a/cmd/workspace/ai-functions/ai-functions.go +++ b/cmd/workspace/ai-functions/ai-functions.go @@ -3,6 +3,7 @@ package ai_functions import ( + "context" "errors" "fmt" @@ -18,18 +19,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "ai-functions", - Short: `Transform and enrich data with AI on Databricks.`, - Long: `Transform and enrich data with AI on Databricks.`, - GroupID: "aifunctions", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "ai-functions", + Short: `Transform and enrich data with AI on Databricks.`, + GroupID: "aifunctions", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Transform and enrich data with AI on Databricks.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newAiClassify()) @@ -45,8 +50,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start ai-classify command diff --git a/cmd/workspace/ai-gateway/ai-gateway.go b/cmd/workspace/ai-gateway/ai-gateway.go index b2860368f0c..1bf8f868b7a 100644 --- a/cmd/workspace/ai-gateway/ai-gateway.go +++ b/cmd/workspace/ai-gateway/ai-gateway.go @@ -3,6 +3,7 @@ package ai_gateway import ( + "context" "fmt" "strings" @@ -19,22 +20,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "ai-gateway", - Short: `Govern AI workloads in Unity Catalog.`, - Long: `Govern AI workloads in Unity Catalog. This API manages the Unity Catalog +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "ai-gateway", + Short: `Govern AI workloads in Unity Catalog.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Govern AI workloads in Unity Catalog. This API manages the Unity Catalog securables that bring centralized access control, lineage, and auditing to AI-serving entities: model services (governed access to foundation models and external LLMs), model provider services (governed resources for external model - providers), and MCP services (governed Model Context Protocol servers).`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + providers), and MCP services (governed Model Context Protocol servers).` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateMcpService()) @@ -66,8 +71,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-mcp-service command diff --git a/cmd/workspace/ai-search/ai-search.go b/cmd/workspace/ai-search/ai-search.go index e96c157ff52..aa500318626 100644 --- a/cmd/workspace/ai-search/ai-search.go +++ b/cmd/workspace/ai-search/ai-search.go @@ -3,6 +3,7 @@ package ai_search import ( + "context" "errors" "fmt" "strings" @@ -20,22 +21,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "ai-search", - Short: `*Public Preview* **AI Search Endpoint**: Represents the compute resources to host AI Search indexes.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "ai-search", + Short: `*Public Preview* **AI Search Endpoint**: Represents the compute resources to host AI Search indexes.`, + GroupID: "aisearch", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. **AI Search Endpoint**: Represents the compute resources to host AI Search indexes. AIP-conformant replacement for the legacy VectorSearchEndpoints API; - functionally equivalent.`, - GroupID: "aisearch", - RunE: root.ReportUnknownSubcommand, - } + functionally equivalent.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreateEndpoint()) @@ -57,8 +62,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-endpoint command diff --git a/cmd/workspace/aibi-dashboard-embedding-access-policy/aibi-dashboard-embedding-access-policy.go b/cmd/workspace/aibi-dashboard-embedding-access-policy/aibi-dashboard-embedding-access-policy.go index 5341051cd12..05888b9d75c 100644 --- a/cmd/workspace/aibi-dashboard-embedding-access-policy/aibi-dashboard-embedding-access-policy.go +++ b/cmd/workspace/aibi-dashboard-embedding-access-policy/aibi-dashboard-embedding-access-policy.go @@ -3,6 +3,7 @@ package aibi_dashboard_embedding_access_policy import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,21 +18,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "aibi-dashboard-embedding-access-policy", - Short: `*Public Preview* Controls whether AI/BI published dashboard embedding is enabled, conditionally enabled, or disabled at the workspace level.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "aibi-dashboard-embedding-access-policy", + Short: `*Public Preview* Controls whether AI/BI published dashboard embedding is enabled, conditionally enabled, or disabled at the workspace level.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Controls whether AI/BI published dashboard embedding is enabled, conditionally enabled, or disabled at the workspace level. By default, this setting is - conditionally enabled (ALLOW_APPROVED_DOMAINS).`, - RunE: root.ReportUnknownSubcommand, - } + conditionally enabled (ALLOW_APPROVED_DOMAINS).` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newDelete()) @@ -42,8 +47,6 @@ Controls whether AI/BI published dashboard embedding is enabled, conditionally for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/aibi-dashboard-embedding-approved-domains/aibi-dashboard-embedding-approved-domains.go b/cmd/workspace/aibi-dashboard-embedding-approved-domains/aibi-dashboard-embedding-approved-domains.go index 3477f3a0971..282bae07c22 100644 --- a/cmd/workspace/aibi-dashboard-embedding-approved-domains/aibi-dashboard-embedding-approved-domains.go +++ b/cmd/workspace/aibi-dashboard-embedding-approved-domains/aibi-dashboard-embedding-approved-domains.go @@ -3,6 +3,7 @@ package aibi_dashboard_embedding_approved_domains import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,21 +18,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "aibi-dashboard-embedding-approved-domains", - Short: `*Public Preview* Controls the list of domains approved to host the embedded AI/BI dashboards.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "aibi-dashboard-embedding-approved-domains", + Short: `*Public Preview* Controls the list of domains approved to host the embedded AI/BI dashboards.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Controls the list of domains approved to host the embedded AI/BI dashboards. The approved domains list can't be mutated when the current access policy is - not set to ALLOW_APPROVED_DOMAINS.`, - RunE: root.ReportUnknownSubcommand, - } + not set to ALLOW_APPROVED_DOMAINS.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newDelete()) @@ -42,8 +47,6 @@ Controls the list of domains approved to host the embedded AI/BI dashboards. for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/alerts-legacy/alerts-legacy.go b/cmd/workspace/alerts-legacy/alerts-legacy.go index b381f027b2c..440947ad9e2 100644 --- a/cmd/workspace/alerts-legacy/alerts-legacy.go +++ b/cmd/workspace/alerts-legacy/alerts-legacy.go @@ -3,6 +3,7 @@ package alerts_legacy import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "alerts-legacy", - Short: `*Public Preview* The alerts API can be used to perform CRUD operations on alerts.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "alerts-legacy", + Short: `*Public Preview* The alerts API can be used to perform CRUD operations on alerts.`, + GroupID: "sql", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. The alerts API can be used to perform CRUD operations on alerts. An alert is a Databricks SQL object that periodically runs a query, evaluates a condition of @@ -32,14 +38,13 @@ The alerts API can be used to perform CRUD operations on alerts. An alert is a **Warning**: This API is deprecated. Please see the latest version of the Databricks SQL API. [Learn more] - [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html`, - GroupID: "sql", - RunE: root.ReportUnknownSubcommand, - } + [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreate()) @@ -52,8 +57,6 @@ The alerts API can be used to perform CRUD operations on alerts. An alert is a for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/alerts-v2/alerts-v2.go b/cmd/workspace/alerts-v2/alerts-v2.go index f7a31691341..626e3e30a73 100644 --- a/cmd/workspace/alerts-v2/alerts-v2.go +++ b/cmd/workspace/alerts-v2/alerts-v2.go @@ -3,6 +3,7 @@ package alerts_v2 import ( + "context" "errors" "fmt" @@ -18,18 +19,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "alerts-v2", - Short: `New version of SQL Alerts.`, - Long: `New version of SQL Alerts`, - GroupID: "sql", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "alerts-v2", + Short: `New version of SQL Alerts.`, + GroupID: "sql", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `New version of SQL Alerts` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateAlert()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-alert command diff --git a/cmd/workspace/alerts/alerts.go b/cmd/workspace/alerts/alerts.go index 3d7ea15c063..8d2a8fc06d9 100644 --- a/cmd/workspace/alerts/alerts.go +++ b/cmd/workspace/alerts/alerts.go @@ -3,6 +3,7 @@ package alerts import ( + "context" "errors" "fmt" @@ -18,22 +19,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "alerts", - Short: `The alerts API can be used to perform CRUD operations on alerts.`, - Long: `The alerts API can be used to perform CRUD operations on alerts. An alert is a +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "alerts", + Short: `The alerts API can be used to perform CRUD operations on alerts.`, + GroupID: "sql", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The alerts API can be used to perform CRUD operations on alerts. An alert is a Databricks SQL object that periodically runs a query, evaluates a condition of its result, and notifies one or more users and/or notification destinations if the condition was met. Alerts can be scheduled using the sql_task type of - the Jobs API, e.g. :method:jobs/create.`, - GroupID: "sql", - RunE: root.ReportUnknownSubcommand, - } + the Jobs API, e.g. :method:jobs/create.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -46,8 +51,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/apps-settings/apps-settings.go b/cmd/workspace/apps-settings/apps-settings.go index ce5e6d84a41..584af3058c2 100644 --- a/cmd/workspace/apps-settings/apps-settings.go +++ b/cmd/workspace/apps-settings/apps-settings.go @@ -3,6 +3,7 @@ package apps_settings import ( + "context" "errors" "fmt" @@ -18,22 +19,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "apps-settings", - Short: `Apps Settings manage the settings for the Apps service on a customer's Databricks instance.`, - Long: `Apps Settings manage the settings for the Apps service on a customer's - Databricks instance.`, - GroupID: "apps", - - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "apps-settings", + Short: `Apps Settings manage the settings for the Apps service on a customer's Databricks instance.`, + GroupID: "apps", - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Apps Settings manage the settings for the Apps service on a customer's + Databricks instance.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newCreateCustomTemplate()) @@ -46,8 +51,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-custom-template command diff --git a/cmd/workspace/apps/apps.go b/cmd/workspace/apps/apps.go index 4b756f47d23..ca46c2ff046 100644 --- a/cmd/workspace/apps/apps.go +++ b/cmd/workspace/apps/apps.go @@ -3,6 +3,7 @@ package apps import ( + "context" "errors" "fmt" "strings" @@ -22,20 +23,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "apps", - Short: `Apps run directly on a customer's Databricks instance, integrate with their data, use and extend Databricks services, and enable users to interact through single sign-on.`, - Long: `Apps run directly on a customer's Databricks instance, integrate with their +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "apps", + Short: `Apps run directly on a customer's Databricks instance, integrate with their data, use and extend Databricks services, and enable users to interact through single sign-on.`, + GroupID: "apps", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Apps run directly on a customer's Databricks instance, integrate with their data, use and extend Databricks services, and enable users to interact through - single sign-on.`, - GroupID: "apps", - RunE: root.ReportUnknownSubcommand, - } + single sign-on.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -67,8 +72,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/artifact-allowlists/artifact-allowlists.go b/cmd/workspace/artifact-allowlists/artifact-allowlists.go index d6fce44ebd1..84671e086c3 100644 --- a/cmd/workspace/artifact-allowlists/artifact-allowlists.go +++ b/cmd/workspace/artifact-allowlists/artifact-allowlists.go @@ -3,6 +3,7 @@ package artifact_allowlists import ( + "context" "errors" "fmt" @@ -18,20 +19,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "artifact-allowlists", - Short: `In Databricks Runtime 13.3 and above, you can add libraries and init scripts to the allowlist in UC so that users can use these artifacts on compute configured with shared access mode.`, - Long: `In Databricks Runtime 13.3 and above, you can add libraries and init scripts +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "artifact-allowlists", + Short: `In Databricks Runtime 13.3 and above, you can add libraries and init scripts to the allowlist in UC so that users can use these artifacts on compute configured with shared access mode.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `In Databricks Runtime 13.3 and above, you can add libraries and init scripts to the allowlist in UC so that users can use these artifacts on compute - configured with shared access mode.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + configured with shared access mode.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGet()) @@ -41,8 +46,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/workspace/automatic-cluster-update/automatic-cluster-update.go b/cmd/workspace/automatic-cluster-update/automatic-cluster-update.go index 2ee11c74d41..40b5b43b977 100644 --- a/cmd/workspace/automatic-cluster-update/automatic-cluster-update.go +++ b/cmd/workspace/automatic-cluster-update/automatic-cluster-update.go @@ -3,6 +3,7 @@ package automatic_cluster_update import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,20 +18,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "automatic-cluster-update", - Short: `*Public Preview* Controls whether automatic cluster update is enabled for the current workspace.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "automatic-cluster-update", + Short: `*Public Preview* Controls whether automatic cluster update is enabled for the current workspace.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Controls whether automatic cluster update is enabled for the current - workspace. By default, it is turned off.`, - RunE: root.ReportUnknownSubcommand, - } + workspace. By default, it is turned off.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newGet()) @@ -40,8 +45,6 @@ Controls whether automatic cluster update is enabled for the current for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/workspace/bundle-deployments/bundle-deployments.go b/cmd/workspace/bundle-deployments/bundle-deployments.go index 47c856736ef..9dc8673faaa 100644 --- a/cmd/workspace/bundle-deployments/bundle-deployments.go +++ b/cmd/workspace/bundle-deployments/bundle-deployments.go @@ -3,6 +3,7 @@ package bundle_deployments import ( + "context" "errors" "fmt" @@ -18,21 +19,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "bundle-deployments", - Short: `Service for managing bundle deployment metadata.`, - Long: `Service for managing bundle deployment metadata.`, - GroupID: "bundledeployments", +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "bundle-deployments", + Short: `Service for managing bundle deployment metadata.`, + GroupID: "bundledeployments", - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Service for managing bundle deployment metadata.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newCompleteVersion()) @@ -55,8 +60,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start complete-version command diff --git a/cmd/workspace/catalogs/catalogs.go b/cmd/workspace/catalogs/catalogs.go index 0bc03d53555..3959e15fdb6 100644 --- a/cmd/workspace/catalogs/catalogs.go +++ b/cmd/workspace/catalogs/catalogs.go @@ -3,6 +3,7 @@ package catalogs import ( + "context" "errors" "fmt" @@ -18,25 +19,29 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "catalogs", - Short: `A catalog is the first layer of Unity Catalog’s three-level namespace.`, - Long: `A catalog is the first layer of Unity Catalog’s three-level namespace. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "catalogs", + Short: `A catalog is the first layer of Unity Catalog’s three-level namespace.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A catalog is the first layer of Unity Catalog’s three-level namespace. It’s used to organize your data assets. Users can see all catalogs on which they have been assigned the USE_CATALOG data permission. In Unity Catalog, admins and data stewards manage users and their access to data centrally across all of the workspaces in a Databricks account. Users in different workspaces can share access to the same data, depending on - privileges granted centrally in Unity Catalog.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + privileges granted centrally in Unity Catalog.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -49,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/clean-room-asset-revisions/clean-room-asset-revisions.go b/cmd/workspace/clean-room-asset-revisions/clean-room-asset-revisions.go index 8379f87849f..1afd9ba2485 100644 --- a/cmd/workspace/clean-room-asset-revisions/clean-room-asset-revisions.go +++ b/cmd/workspace/clean-room-asset-revisions/clean-room-asset-revisions.go @@ -3,6 +3,7 @@ package clean_room_asset_revisions import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -16,21 +17,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "clean-room-asset-revisions", - Short: `*Beta* Clean Room Asset Revisions denote new versions of uploaded assets (e.g.`, - Long: `This command is in Beta and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "clean-room-asset-revisions", + Short: `*Beta* Clean Room Asset Revisions denote new versions of uploaded assets (e.g.`, + GroupID: "cleanrooms", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Beta and may change without notice. Clean Room Asset Revisions denote new versions of uploaded assets (e.g. - notebooks) in the clean room.`, - GroupID: "cleanrooms", - RunE: root.ReportUnknownSubcommand, - } + notebooks) in the clean room.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_BETA" - cmd.Annotations["launch_stage_display"] = "Beta" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_BETA", + "launch_stage_display": "Beta", + } // Add methods cmd.AddCommand(newGet()) @@ -40,8 +45,6 @@ Clean Room Asset Revisions denote new versions of uploaded assets (e.g. for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/workspace/clean-room-assets/clean-room-assets.go b/cmd/workspace/clean-room-assets/clean-room-assets.go index cc8c6f7f334..86dfeb3263f 100644 --- a/cmd/workspace/clean-room-assets/clean-room-assets.go +++ b/cmd/workspace/clean-room-assets/clean-room-assets.go @@ -3,6 +3,7 @@ package clean_room_assets import ( + "context" "errors" "fmt" @@ -18,19 +19,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "clean-room-assets", - Short: `Clean room assets are data and code objects — Tables, volumes, and notebooks that are shared with the clean room.`, - Long: `Clean room assets are data and code objects — Tables, volumes, and notebooks - that are shared with the clean room.`, - GroupID: "cleanrooms", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "clean-room-assets", + Short: `Clean room assets are data and code objects — Tables, volumes, and notebooks that are shared with the clean room.`, + GroupID: "cleanrooms", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Clean room assets are data and code objects — Tables, volumes, and notebooks + that are shared with the clean room.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -44,8 +49,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/clean-room-auto-approval-rules/clean-room-auto-approval-rules.go b/cmd/workspace/clean-room-auto-approval-rules/clean-room-auto-approval-rules.go index 6ffea68d40d..ea1739a015e 100644 --- a/cmd/workspace/clean-room-auto-approval-rules/clean-room-auto-approval-rules.go +++ b/cmd/workspace/clean-room-auto-approval-rules/clean-room-auto-approval-rules.go @@ -3,6 +3,7 @@ package clean_room_auto_approval_rules import ( + "context" "errors" "fmt" @@ -18,22 +19,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "clean-room-auto-approval-rules", - Short: `*Beta* Clean room auto-approval rules automatically create an approval on your behalf when an asset (e.g.`, - Long: `This command is in Beta and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "clean-room-auto-approval-rules", + Short: `*Beta* Clean room auto-approval rules automatically create an approval on your behalf when an asset (e.g.`, + GroupID: "cleanrooms", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Beta and may change without notice. Clean room auto-approval rules automatically create an approval on your behalf when an asset (e.g. notebook) meeting specific criteria is shared in a clean - room.`, - GroupID: "cleanrooms", - RunE: root.ReportUnknownSubcommand, - } + room.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_BETA" - cmd.Annotations["launch_stage_display"] = "Beta" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_BETA", + "launch_stage_display": "Beta", + } // Add methods cmd.AddCommand(newCreate()) @@ -46,8 +51,6 @@ Clean room auto-approval rules automatically create an approval on your behalf for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/clean-room-task-runs/clean-room-task-runs.go b/cmd/workspace/clean-room-task-runs/clean-room-task-runs.go index 1ab6b639bc6..37597514309 100644 --- a/cmd/workspace/clean-room-task-runs/clean-room-task-runs.go +++ b/cmd/workspace/clean-room-task-runs/clean-room-task-runs.go @@ -3,6 +3,7 @@ package clean_room_task_runs import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -16,19 +17,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "clean-room-task-runs", - Short: `Clean room task runs are the executions of notebooks and JAR analyses in a clean room.`, - Long: `Clean room task runs are the executions of notebooks and JAR analyses in a - clean room.`, - GroupID: "cleanrooms", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "clean-room-task-runs", + Short: `Clean room task runs are the executions of notebooks and JAR analyses in a clean room.`, + GroupID: "cleanrooms", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Clean room task runs are the executions of notebooks and JAR analyses in a + clean room.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newList()) @@ -38,8 +43,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start list command diff --git a/cmd/workspace/clean-rooms/clean-rooms.go b/cmd/workspace/clean-rooms/clean-rooms.go index aa904968b58..76f8e0628ce 100644 --- a/cmd/workspace/clean-rooms/clean-rooms.go +++ b/cmd/workspace/clean-rooms/clean-rooms.go @@ -3,6 +3,7 @@ package clean_rooms import ( + "context" "fmt" "time" @@ -18,20 +19,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "clean-rooms", - Short: `A clean room uses Delta Sharing and serverless compute to provide a secure and privacy-protecting environment where multiple parties can work together on sensitive enterprise data without direct access to each other's data.`, - Long: `A clean room uses Delta Sharing and serverless compute to provide a secure and +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "clean-rooms", + Short: `A clean room uses Delta Sharing and serverless compute to provide a secure and privacy-protecting environment where multiple parties can work together on sensitive enterprise data without direct access to each other's data.`, + GroupID: "cleanrooms", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A clean room uses Delta Sharing and serverless compute to provide a secure and privacy-protecting environment where multiple parties can work together on - sensitive enterprise data without direct access to each other's data.`, - GroupID: "cleanrooms", - RunE: root.ReportUnknownSubcommand, - } + sensitive enterprise data without direct access to each other's data.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -45,8 +50,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/cluster-policies/cluster-policies.go b/cmd/workspace/cluster-policies/cluster-policies.go index c601693c28c..dd5fb2aee33 100644 --- a/cmd/workspace/cluster-policies/cluster-policies.go +++ b/cmd/workspace/cluster-policies/cluster-policies.go @@ -3,6 +3,7 @@ package cluster_policies import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "cluster-policies", - Short: `You can use cluster policies to control users' ability to configure clusters based on a set of rules.`, - Long: `You can use cluster policies to control users' ability to configure clusters +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "cluster-policies", + Short: `You can use cluster policies to control users' ability to configure clusters based on a set of rules.`, + GroupID: "compute", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `You can use cluster policies to control users' ability to configure clusters based on a set of rules. These rules specify which attributes or attribute values can be used during cluster creation. Cluster policies have ACLs that limit their use to specific users and groups. @@ -44,14 +50,13 @@ func New() *cobra.Command { If no policies exist in the workspace, the Policy drop-down doesn't appear. Only admin users can create, edit, and delete policies. Admin users also have - access to all policies.`, - GroupID: "compute", - RunE: root.ReportUnknownSubcommand, - } + access to all policies.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -68,8 +73,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/clusters/clusters.go b/cmd/workspace/clusters/clusters.go index d0b0302b66f..11b65b2e241 100644 --- a/cmd/workspace/clusters/clusters.go +++ b/cmd/workspace/clusters/clusters.go @@ -3,6 +3,7 @@ package clusters import ( + "context" "errors" "fmt" "time" @@ -19,11 +20,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "clusters", - Short: `The Clusters API allows you to create, start, edit, list, terminate, and delete clusters.`, - Long: `The Clusters API allows you to create, start, edit, list, terminate, and +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "clusters", + Short: `The Clusters API allows you to create, start, edit, list, terminate, and delete clusters.`, + GroupID: "compute", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Clusters API allows you to create, start, edit, list, terminate, and delete clusters. Databricks maps cluster node instance types to compute units known as DBUs. @@ -48,14 +54,13 @@ func New() *cobra.Command { IMPORTANT: Databricks retains cluster configuration information for terminated clusters for 30 days. To keep an all-purpose cluster configuration even after it has been terminated for more than 30 days, an administrator can pin a - cluster to the cluster list.`, - GroupID: "compute", - RunE: root.ReportUnknownSubcommand, - } + cluster to the cluster list.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newChangeOwner()) @@ -84,8 +89,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start change-owner command diff --git a/cmd/workspace/cmd.go b/cmd/workspace/cmd.go index 58d58cafcef..14585891bc0 100644 --- a/cmd/workspace/cmd.go +++ b/cmd/workspace/cmd.go @@ -3,6 +3,7 @@ package workspace import ( + "github.com/databricks/cli/cmd/root" access_control "github.com/databricks/cli/cmd/workspace/access-control" agent_bricks "github.com/databricks/cli/cmd/workspace/agent-bricks" agent_kit "github.com/databricks/cli/cmd/workspace/agent-kit" @@ -136,153 +137,153 @@ import ( workspace_entity_tag_assignments "github.com/databricks/cli/cmd/workspace/workspace-entity-tag-assignments" workspace_iam_v2 "github.com/databricks/cli/cmd/workspace/workspace-iam-v2" workspace_settings_v2 "github.com/databricks/cli/cmd/workspace/workspace-settings-v2" - "github.com/spf13/cobra" groups "github.com/databricks/cli/cmd/workspace/groups" service_principals "github.com/databricks/cli/cmd/workspace/service-principals" users "github.com/databricks/cli/cmd/workspace/users" ) -func All() []*cobra.Command { - var out []*cobra.Command +// All returns the specs of the workspace commands. +func All() []root.CommandSpec { + var out []root.CommandSpec - out = append(out, access_control.New()) - out = append(out, agent_bricks.New()) - out = append(out, agent_kit.New()) - out = append(out, ai_functions.New()) - out = append(out, ai_gateway.New()) - out = append(out, ai_search.New()) - out = append(out, alerts.New()) - out = append(out, alerts_legacy.New()) - out = append(out, alerts_v2.New()) - out = append(out, apps.New()) - out = append(out, apps_settings.New()) - out = append(out, artifact_allowlists.New()) - out = append(out, bundle_deployments.New()) - out = append(out, catalogs.New()) - out = append(out, clean_room_asset_revisions.New()) - out = append(out, clean_room_assets.New()) - out = append(out, clean_room_auto_approval_rules.New()) - out = append(out, clean_room_task_runs.New()) - out = append(out, clean_rooms.New()) - out = append(out, cluster_policies.New()) - out = append(out, clusters.New()) - out = append(out, compute_migrations.New()) - out = append(out, connections.New()) - out = append(out, consumer_fulfillments.New()) - out = append(out, consumer_installations.New()) - out = append(out, consumer_listings.New()) - out = append(out, consumer_personalization_requests.New()) - out = append(out, consumer_providers.New()) - out = append(out, credentials.New()) - out = append(out, credentials_manager.New()) - out = append(out, current_user.New()) - out = append(out, dashboard_widgets.New()) - out = append(out, dashboards.New()) - out = append(out, data_classification.New()) - out = append(out, data_quality.New()) - out = append(out, data_sources.New()) - out = append(out, database.New()) - out = append(out, domains.New()) - out = append(out, entity_tag_assignments.New()) - out = append(out, environments.New()) - out = append(out, experiments.New()) - out = append(out, external_lineage.New()) - out = append(out, external_locations.New()) - out = append(out, external_metadata.New()) - out = append(out, feature_engineering.New()) - out = append(out, feature_store.New()) - out = append(out, forecasting.New()) - out = append(out, functions.New()) - out = append(out, genie.New()) - out = append(out, genie_agents.New()) - out = append(out, git_credentials.New()) - out = append(out, global_init_scripts.New()) - out = append(out, grants.New()) - out = append(out, groups_v2.New()) - out = append(out, instance_pools.New()) - out = append(out, instance_profiles.New()) - out = append(out, ip_access_lists.New()) - out = append(out, jobs.New()) - out = append(out, knowledge_assistants.New()) - out = append(out, lakeview.New()) - out = append(out, lakeview_embedded.New()) - out = append(out, lakewatch.New()) - out = append(out, libraries.New()) - out = append(out, materialized_features.New()) - out = append(out, metastores.New()) - out = append(out, model_registry.New()) - out = append(out, model_versions.New()) - out = append(out, notification_destinations.New()) - out = append(out, online_tables.New()) - out = append(out, permission_migration.New()) - out = append(out, permissions.New()) - out = append(out, pipelines.New()) - out = append(out, policies.New()) - out = append(out, policy_compliance_for_clusters.New()) - out = append(out, policy_compliance_for_jobs.New()) - out = append(out, policy_families.New()) - out = append(out, postgres.New()) - out = append(out, provider_exchange_filters.New()) - out = append(out, provider_exchanges.New()) - out = append(out, provider_files.New()) - out = append(out, provider_listings.New()) - out = append(out, provider_personalization_requests.New()) - out = append(out, provider_provider_analytics_dashboards.New()) - out = append(out, provider_providers.New()) - out = append(out, providers.New()) - out = append(out, quality_monitor_v2.New()) - out = append(out, quality_monitors.New()) - out = append(out, queries.New()) - out = append(out, queries_legacy.New()) - out = append(out, query_history.New()) - out = append(out, query_visualizations.New()) - out = append(out, query_visualizations_legacy.New()) - out = append(out, recipient_activation.New()) - out = append(out, recipient_federation_policies.New()) - out = append(out, recipients.New()) - out = append(out, redash_config.New()) - out = append(out, registered_models.New()) - out = append(out, repos.New()) - out = append(out, resource_quotas.New()) - out = append(out, rfa.New()) - out = append(out, sandbox.New()) - out = append(out, schemas.New()) - out = append(out, secrets.New()) - out = append(out, secrets_uc.New()) - out = append(out, serverless_compute_service.New()) - out = append(out, service_principal_secrets_proxy.New()) - out = append(out, service_principals_v2.New()) - out = append(out, serving_endpoints.New()) - out = append(out, settings.New()) - out = append(out, shares.New()) - out = append(out, software_artifacts.New()) - out = append(out, storage_credentials.New()) - out = append(out, supervisor_agents.New()) - out = append(out, system_schemas.New()) - out = append(out, table_constraints.New()) - out = append(out, tables.New()) - out = append(out, tag_policies.New()) - out = append(out, temporary_path_credentials.New()) - out = append(out, temporary_table_credentials.New()) - out = append(out, temporary_volume_credentials.New()) - out = append(out, token_management.New()) - out = append(out, tokens.New()) - out = append(out, users_v2.New()) - out = append(out, vector_search_endpoints.New()) - out = append(out, vector_search_indexes.New()) - out = append(out, volumes.New()) - out = append(out, warehouses.New()) - out = append(out, workspace.New()) - out = append(out, workspace_bindings.New()) - out = append(out, workspace_conf.New()) - out = append(out, workspace_entity_tag_assignments.New()) - out = append(out, workspace_iam_v2.New()) - out = append(out, workspace_settings_v2.New()) + out = append(out, access_control.Spec) + out = append(out, agent_bricks.Spec) + out = append(out, agent_kit.Spec) + out = append(out, ai_functions.Spec) + out = append(out, ai_gateway.Spec) + out = append(out, ai_search.Spec) + out = append(out, alerts.Spec) + out = append(out, alerts_legacy.Spec) + out = append(out, alerts_v2.Spec) + out = append(out, apps.Spec) + out = append(out, apps_settings.Spec) + out = append(out, artifact_allowlists.Spec) + out = append(out, bundle_deployments.Spec) + out = append(out, catalogs.Spec) + out = append(out, clean_room_asset_revisions.Spec) + out = append(out, clean_room_assets.Spec) + out = append(out, clean_room_auto_approval_rules.Spec) + out = append(out, clean_room_task_runs.Spec) + out = append(out, clean_rooms.Spec) + out = append(out, cluster_policies.Spec) + out = append(out, clusters.Spec) + out = append(out, compute_migrations.Spec) + out = append(out, connections.Spec) + out = append(out, consumer_fulfillments.Spec) + out = append(out, consumer_installations.Spec) + out = append(out, consumer_listings.Spec) + out = append(out, consumer_personalization_requests.Spec) + out = append(out, consumer_providers.Spec) + out = append(out, credentials.Spec) + out = append(out, credentials_manager.Spec) + out = append(out, current_user.Spec) + out = append(out, dashboard_widgets.Spec) + out = append(out, dashboards.Spec) + out = append(out, data_classification.Spec) + out = append(out, data_quality.Spec) + out = append(out, data_sources.Spec) + out = append(out, database.Spec) + out = append(out, domains.Spec) + out = append(out, entity_tag_assignments.Spec) + out = append(out, environments.Spec) + out = append(out, experiments.Spec) + out = append(out, external_lineage.Spec) + out = append(out, external_locations.Spec) + out = append(out, external_metadata.Spec) + out = append(out, feature_engineering.Spec) + out = append(out, feature_store.Spec) + out = append(out, forecasting.Spec) + out = append(out, functions.Spec) + out = append(out, genie.Spec) + out = append(out, genie_agents.Spec) + out = append(out, git_credentials.Spec) + out = append(out, global_init_scripts.Spec) + out = append(out, grants.Spec) + out = append(out, groups_v2.Spec) + out = append(out, instance_pools.Spec) + out = append(out, instance_profiles.Spec) + out = append(out, ip_access_lists.Spec) + out = append(out, jobs.Spec) + out = append(out, knowledge_assistants.Spec) + out = append(out, lakeview.Spec) + out = append(out, lakeview_embedded.Spec) + out = append(out, lakewatch.Spec) + out = append(out, libraries.Spec) + out = append(out, materialized_features.Spec) + out = append(out, metastores.Spec) + out = append(out, model_registry.Spec) + out = append(out, model_versions.Spec) + out = append(out, notification_destinations.Spec) + out = append(out, online_tables.Spec) + out = append(out, permission_migration.Spec) + out = append(out, permissions.Spec) + out = append(out, pipelines.Spec) + out = append(out, policies.Spec) + out = append(out, policy_compliance_for_clusters.Spec) + out = append(out, policy_compliance_for_jobs.Spec) + out = append(out, policy_families.Spec) + out = append(out, postgres.Spec) + out = append(out, provider_exchange_filters.Spec) + out = append(out, provider_exchanges.Spec) + out = append(out, provider_files.Spec) + out = append(out, provider_listings.Spec) + out = append(out, provider_personalization_requests.Spec) + out = append(out, provider_provider_analytics_dashboards.Spec) + out = append(out, provider_providers.Spec) + out = append(out, providers.Spec) + out = append(out, quality_monitor_v2.Spec) + out = append(out, quality_monitors.Spec) + out = append(out, queries.Spec) + out = append(out, queries_legacy.Spec) + out = append(out, query_history.Spec) + out = append(out, query_visualizations.Spec) + out = append(out, query_visualizations_legacy.Spec) + out = append(out, recipient_activation.Spec) + out = append(out, recipient_federation_policies.Spec) + out = append(out, recipients.Spec) + out = append(out, redash_config.Spec) + out = append(out, registered_models.Spec) + out = append(out, repos.Spec) + out = append(out, resource_quotas.Spec) + out = append(out, rfa.Spec) + out = append(out, sandbox.Spec) + out = append(out, schemas.Spec) + out = append(out, secrets.Spec) + out = append(out, secrets_uc.Spec) + out = append(out, serverless_compute_service.Spec) + out = append(out, service_principal_secrets_proxy.Spec) + out = append(out, service_principals_v2.Spec) + out = append(out, serving_endpoints.Spec) + out = append(out, settings.Spec) + out = append(out, shares.Spec) + out = append(out, software_artifacts.Spec) + out = append(out, storage_credentials.Spec) + out = append(out, supervisor_agents.Spec) + out = append(out, system_schemas.Spec) + out = append(out, table_constraints.Spec) + out = append(out, tables.Spec) + out = append(out, tag_policies.Spec) + out = append(out, temporary_path_credentials.Spec) + out = append(out, temporary_table_credentials.Spec) + out = append(out, temporary_volume_credentials.Spec) + out = append(out, token_management.Spec) + out = append(out, tokens.Spec) + out = append(out, users_v2.Spec) + out = append(out, vector_search_endpoints.Spec) + out = append(out, vector_search_indexes.Spec) + out = append(out, volumes.Spec) + out = append(out, warehouses.Spec) + out = append(out, workspace.Spec) + out = append(out, workspace_bindings.Spec) + out = append(out, workspace_conf.Spec) + out = append(out, workspace_entity_tag_assignments.Spec) + out = append(out, workspace_iam_v2.Spec) + out = append(out, workspace_settings_v2.Spec) - out = append(out, groups.New()) - out = append(out, service_principals.New()) - out = append(out, users.New()) + out = append(out, groups.Spec) + out = append(out, service_principals.Spec) + out = append(out, users.Spec) return out } diff --git a/cmd/workspace/compliance-security-profile/compliance-security-profile.go b/cmd/workspace/compliance-security-profile/compliance-security-profile.go index 0a87f8a7bc9..e650978827c 100644 --- a/cmd/workspace/compliance-security-profile/compliance-security-profile.go +++ b/cmd/workspace/compliance-security-profile/compliance-security-profile.go @@ -3,6 +3,7 @@ package compliance_security_profile import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,23 +18,27 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "compliance-security-profile", - Short: `*Public Preview* Controls whether to enable the compliance security profile for the current workspace.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "compliance-security-profile", + Short: `*Public Preview* Controls whether to enable the compliance security profile for the current workspace.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Controls whether to enable the compliance security profile for the current workspace. Enabling it on a workspace is permanent. By default, it is turned off. - This settings can NOT be disabled once it is enabled.`, - RunE: root.ReportUnknownSubcommand, - } + This settings can NOT be disabled once it is enabled.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newGet()) @@ -43,8 +48,6 @@ Controls whether to enable the compliance security profile for the current for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/workspace/compute-migrations/compute-migrations.go b/cmd/workspace/compute-migrations/compute-migrations.go index 03e997f929c..3047984317b 100644 --- a/cmd/workspace/compute-migrations/compute-migrations.go +++ b/cmd/workspace/compute-migrations/compute-migrations.go @@ -3,6 +3,7 @@ package compute_migrations import ( + "context" "errors" "fmt" @@ -18,21 +19,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "compute-migrations", - Short: `Manage migrations of Classic compute workloads to Serverless.`, - Long: `Manage migrations of Classic compute workloads to Serverless.`, - GroupID: "compute", +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "compute-migrations", + Short: `Manage migrations of Classic compute workloads to Serverless.`, + GroupID: "compute", - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Manage migrations of Classic compute workloads to Serverless.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newApproveMigrationExecution()) @@ -49,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start approve-migration-execution command diff --git a/cmd/workspace/connections/connections.go b/cmd/workspace/connections/connections.go index 2a923fabda6..1c2c332fd81 100644 --- a/cmd/workspace/connections/connections.go +++ b/cmd/workspace/connections/connections.go @@ -3,6 +3,7 @@ package connections import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "connections", - Short: `A connection represents an external data source for use within Databricks.`, - Long: `A connection represents an external data source for use within Databricks. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "connections", + Short: `A connection represents an external data source for use within Databricks.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A connection represents an external data source for use within Databricks. Creating a connection object is the first step to managing external data sources within Unity Catalog. The second step is creating a data object @@ -30,14 +36,13 @@ func New() *cobra.Command { connection can be written to or read from similar to other Unity Catalog data objects based on cloud storage. You can create different types of connections, and each connection has a unique set of configuration options to support - credential management and other settings.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + credential management and other settings.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -50,8 +55,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/consumer-fulfillments/consumer-fulfillments.go b/cmd/workspace/consumer-fulfillments/consumer-fulfillments.go index 5444f2c42f6..65e0f58ace1 100644 --- a/cmd/workspace/consumer-fulfillments/consumer-fulfillments.go +++ b/cmd/workspace/consumer-fulfillments/consumer-fulfillments.go @@ -3,6 +3,7 @@ package consumer_fulfillments import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -16,18 +17,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "consumer-fulfillments", - Short: `Fulfillments are entities that allow consumers to preview installations.`, - Long: `Fulfillments are entities that allow consumers to preview installations.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "consumer-fulfillments", + Short: `Fulfillments are entities that allow consumers to preview installations.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Fulfillments are entities that allow consumers to preview installations.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGet()) @@ -37,8 +42,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/workspace/consumer-installations/consumer-installations.go b/cmd/workspace/consumer-installations/consumer-installations.go index 9f9e332b49b..eb2e9513ca9 100644 --- a/cmd/workspace/consumer-installations/consumer-installations.go +++ b/cmd/workspace/consumer-installations/consumer-installations.go @@ -3,6 +3,7 @@ package consumer_installations import ( + "context" "errors" "fmt" @@ -18,19 +19,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "consumer-installations", - Short: `Installations are entities that allow consumers to interact with Databricks Marketplace listings.`, - Long: `Installations are entities that allow consumers to interact with Databricks - Marketplace listings.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "consumer-installations", + Short: `Installations are entities that allow consumers to interact with Databricks Marketplace listings.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Installations are entities that allow consumers to interact with Databricks + Marketplace listings.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -43,8 +48,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/consumer-listings/consumer-listings.go b/cmd/workspace/consumer-listings/consumer-listings.go index 7e513847acb..c28bb1768f2 100644 --- a/cmd/workspace/consumer-listings/consumer-listings.go +++ b/cmd/workspace/consumer-listings/consumer-listings.go @@ -3,6 +3,7 @@ package consumer_listings import ( + "context" "errors" "fmt" @@ -17,19 +18,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "consumer-listings", - Short: `Listings are the core entities in the Marketplace.`, - Long: `Listings are the core entities in the Marketplace. They represent the products - that are available for consumption.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "consumer-listings", + Short: `Listings are the core entities in the Marketplace.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Listings are the core entities in the Marketplace. They represent the products + that are available for consumption.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newBatchGet()) @@ -41,8 +46,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start batch-get command diff --git a/cmd/workspace/consumer-personalization-requests/consumer-personalization-requests.go b/cmd/workspace/consumer-personalization-requests/consumer-personalization-requests.go index 7c1d7f0ad0f..ab079fd9e1a 100644 --- a/cmd/workspace/consumer-personalization-requests/consumer-personalization-requests.go +++ b/cmd/workspace/consumer-personalization-requests/consumer-personalization-requests.go @@ -3,6 +3,7 @@ package consumer_personalization_requests import ( + "context" "errors" "fmt" @@ -18,19 +19,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "consumer-personalization-requests", - Short: `Personalization Requests allow customers to interact with the individualized Marketplace listing flow.`, - Long: `Personalization Requests allow customers to interact with the individualized - Marketplace listing flow.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "consumer-personalization-requests", + Short: `Personalization Requests allow customers to interact with the individualized Marketplace listing flow.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Personalization Requests allow customers to interact with the individualized + Marketplace listing flow.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -41,8 +46,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/consumer-providers/consumer-providers.go b/cmd/workspace/consumer-providers/consumer-providers.go index e03eb48a4a9..92bf16bcccc 100644 --- a/cmd/workspace/consumer-providers/consumer-providers.go +++ b/cmd/workspace/consumer-providers/consumer-providers.go @@ -3,6 +3,7 @@ package consumer_providers import ( + "context" "errors" "fmt" @@ -17,18 +18,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "consumer-providers", - Short: `Providers are the entities that publish listings to the Marketplace.`, - Long: `Providers are the entities that publish listings to the Marketplace.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "consumer-providers", + Short: `Providers are the entities that publish listings to the Marketplace.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Providers are the entities that publish listings to the Marketplace.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newBatchGet()) @@ -39,8 +44,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start batch-get command diff --git a/cmd/workspace/credentials-manager/credentials-manager.go b/cmd/workspace/credentials-manager/credentials-manager.go index 6c960ed692f..8e7cd3e71a8 100644 --- a/cmd/workspace/credentials-manager/credentials-manager.go +++ b/cmd/workspace/credentials-manager/credentials-manager.go @@ -3,6 +3,7 @@ package credentials_manager import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,22 +18,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "credentials-manager", - Short: `Credentials manager interacts with with Identity Providers to to perform token exchanges using stored credentials and refresh tokens.`, - Long: `Credentials manager interacts with with Identity Providers to to perform token - exchanges using stored credentials and refresh tokens.`, - GroupID: "settings", - - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "credentials-manager", + Short: `Credentials manager interacts with with Identity Providers to to perform token exchanges using stored credentials and refresh tokens.`, + GroupID: "settings", - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Credentials manager interacts with with Identity Providers to to perform token + exchanges using stored credentials and refresh tokens.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newExchangeToken()) @@ -41,8 +46,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start exchange-token command diff --git a/cmd/workspace/credentials/credentials.go b/cmd/workspace/credentials/credentials.go index 0775db41324..1bd4b22d643 100644 --- a/cmd/workspace/credentials/credentials.go +++ b/cmd/workspace/credentials/credentials.go @@ -3,6 +3,7 @@ package credentials import ( + "context" "errors" "fmt" @@ -18,25 +19,29 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "credentials", - Short: `A credential represents an authentication and authorization mechanism for accessing services on your cloud tenant.`, - Long: `A credential represents an authentication and authorization mechanism for +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "credentials", + Short: `A credential represents an authentication and authorization mechanism for accessing services on your cloud tenant.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A credential represents an authentication and authorization mechanism for accessing services on your cloud tenant. Each credential is subject to Unity Catalog access-control policies that control which users and groups can access the credential. To create credentials, you must be a Databricks account admin or have the CREATE SERVICE CREDENTIAL privilege. The user who creates the credential can - delegate ownership to another user or group to manage permissions on it.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + delegate ownership to another user or group to manage permissions on it.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateCredential()) @@ -51,8 +56,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-credential command diff --git a/cmd/workspace/current-user/current-user.go b/cmd/workspace/current-user/current-user.go index de32f481229..5909b47997e 100644 --- a/cmd/workspace/current-user/current-user.go +++ b/cmd/workspace/current-user/current-user.go @@ -3,6 +3,8 @@ package current_user import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -14,21 +16,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "current-user", - Short: `*Public Preview* This API allows retrieving information about currently authenticated user or service principal.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "current-user", + Short: `*Public Preview* This API allows retrieving information about currently authenticated user or service principal.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. This API allows retrieving information about currently authenticated user or - service principal.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } + service principal.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newMe()) @@ -37,8 +43,6 @@ This API allows retrieving information about currently authenticated user or for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start me command diff --git a/cmd/workspace/dashboard-email-subscriptions/dashboard-email-subscriptions.go b/cmd/workspace/dashboard-email-subscriptions/dashboard-email-subscriptions.go index b8cb554761f..50c9e1e9172 100644 --- a/cmd/workspace/dashboard-email-subscriptions/dashboard-email-subscriptions.go +++ b/cmd/workspace/dashboard-email-subscriptions/dashboard-email-subscriptions.go @@ -3,6 +3,7 @@ package dashboard_email_subscriptions import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,21 +18,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "dashboard-email-subscriptions", - Short: `*Public Preview* Controls whether schedules or workload tasks for refreshing AI/BI Dashboards in the workspace can send subscription emails containing PDFs and/or images of the dashboard.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "dashboard-email-subscriptions", + Short: `*Public Preview* Controls whether schedules or workload tasks for refreshing AI/BI Dashboards in the workspace can send subscription emails containing PDFs and/or images of the dashboard.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Controls whether schedules or workload tasks for refreshing AI/BI Dashboards in the workspace can send subscription emails containing PDFs and/or images of - the dashboard. By default, this setting is enabled (set to true)`, - RunE: root.ReportUnknownSubcommand, - } + the dashboard. By default, this setting is enabled (set to true)` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newDelete()) @@ -42,8 +47,6 @@ Controls whether schedules or workload tasks for refreshing AI/BI Dashboards for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/dashboard-widgets/dashboard-widgets.go b/cmd/workspace/dashboard-widgets/dashboard-widgets.go index b417deb6c32..5315be63ab1 100644 --- a/cmd/workspace/dashboard-widgets/dashboard-widgets.go +++ b/cmd/workspace/dashboard-widgets/dashboard-widgets.go @@ -3,6 +3,7 @@ package dashboard_widgets import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,24 +18,28 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "dashboard-widgets", - Short: `This is an evolving API that facilitates the addition and removal of widgets from existing dashboards within the Databricks Workspace.`, - Long: `This is an evolving API that facilitates the addition and removal of widgets +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "dashboard-widgets", + Short: `This is an evolving API that facilitates the addition and removal of widgets from existing dashboards within the Databricks Workspace.`, + GroupID: "sql", + + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This is an evolving API that facilitates the addition and removal of widgets from existing dashboards within the Databricks Workspace. Data structures may - change over time.`, - GroupID: "sql", + change over time.` + cmd.RunE = root.ReportUnknownSubcommand - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", } - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" - // Add methods cmd.AddCommand(newCreate()) cmd.AddCommand(newDelete()) @@ -44,8 +49,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/dashboards/dashboards.go b/cmd/workspace/dashboards/dashboards.go index 5eb7ed2d3a1..7f60303e456 100644 --- a/cmd/workspace/dashboards/dashboards.go +++ b/cmd/workspace/dashboards/dashboards.go @@ -3,6 +3,7 @@ package dashboards import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "dashboards", - Short: `In general, there is little need to modify dashboards using the API.`, - Long: `In general, there is little need to modify dashboards using the API. However, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "dashboards", + Short: `In general, there is little need to modify dashboards using the API.`, + GroupID: "sql", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `In general, there is little need to modify dashboards using the API. However, it can be useful to use dashboard objects to look-up a collection of related query IDs. The API can also be used to duplicate multiple dashboards at once since you can get a dashboard definition with a GET request and then POST it @@ -31,14 +37,13 @@ func New() *cobra.Command { **Warning**: This API is deprecated. Please use the AI/BI Dashboards API instead. [Learn more] - [Learn more]: https://docs.databricks.com/en/dashboards/`, - GroupID: "sql", - RunE: root.ReportUnknownSubcommand, - } + [Learn more]: https://docs.databricks.com/en/dashboards/` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newDelete()) @@ -51,8 +56,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/data-classification/data-classification.go b/cmd/workspace/data-classification/data-classification.go index edc73c21d4b..d5f812434af 100644 --- a/cmd/workspace/data-classification/data-classification.go +++ b/cmd/workspace/data-classification/data-classification.go @@ -3,6 +3,7 @@ package data_classification import ( + "context" "strings" "github.com/databricks/cli/cmd/root" @@ -18,21 +19,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "data-classification", - Short: `Manage data classification for Unity Catalog catalogs.`, - Long: `Manage data classification for Unity Catalog catalogs. Data classification +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "data-classification", + Short: `Manage data classification for Unity Catalog catalogs.`, + GroupID: "dataclassification", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Manage data classification for Unity Catalog catalogs. Data classification automatically identifies and tags sensitive data (PII) in Unity Catalog tables. Each catalog can have at most one configuration resource that controls - scanning behavior and auto-tagging rules.`, - GroupID: "dataclassification", - RunE: root.ReportUnknownSubcommand, - } + scanning behavior and auto-tagging rules.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateCatalogConfig()) @@ -44,8 +49,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-catalog-config command diff --git a/cmd/workspace/data-quality/data-quality.go b/cmd/workspace/data-quality/data-quality.go index b54eaf0f660..e51399c843f 100644 --- a/cmd/workspace/data-quality/data-quality.go +++ b/cmd/workspace/data-quality/data-quality.go @@ -3,6 +3,7 @@ package data_quality import ( + "context" "errors" "fmt" @@ -18,19 +19,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "data-quality", - Short: `Manage the data quality of Unity Catalog objects (currently support schema and table).`, - Long: `Manage the data quality of Unity Catalog objects (currently support schema - and table)`, - GroupID: "dataquality", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "data-quality", + Short: `Manage the data quality of Unity Catalog objects (currently support schema and table).`, + GroupID: "dataquality", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Manage the data quality of Unity Catalog objects (currently support schema + and table)` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCancelRefresh()) @@ -49,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start cancel-refresh command diff --git a/cmd/workspace/data-sources/data-sources.go b/cmd/workspace/data-sources/data-sources.go index 33bee7f17bf..3f30846c723 100644 --- a/cmd/workspace/data-sources/data-sources.go +++ b/cmd/workspace/data-sources/data-sources.go @@ -3,6 +3,8 @@ package data_sources import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -13,11 +15,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "data-sources", - Short: `This API is provided to assist you in making new query objects.`, - Long: `This API is provided to assist you in making new query objects. When creating +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "data-sources", + Short: `This API is provided to assist you in making new query objects.`, + GroupID: "sql", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This API is provided to assist you in making new query objects. When creating a query object, you may optionally specify a data_source_id for the SQL warehouse against which it will run. If you don't already know the data_source_id for your desired SQL warehouse, this API will help you find @@ -31,14 +38,13 @@ func New() *cobra.Command { **Warning**: This API is deprecated. Please see the latest version of the Databricks SQL API. [Learn more] - [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html`, - GroupID: "sql", - RunE: root.ReportUnknownSubcommand, - } + [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newList()) @@ -47,8 +53,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start list command diff --git a/cmd/workspace/database/database.go b/cmd/workspace/database/database.go index 7c9107e708c..59eb3d6bbc5 100644 --- a/cmd/workspace/database/database.go +++ b/cmd/workspace/database/database.go @@ -3,6 +3,7 @@ package database import ( + "context" "errors" "fmt" "time" @@ -19,25 +20,29 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "database", - Short: `*Public Preview* Database Instances provide access to a database via REST API or direct SQL.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "database", + Short: `*Public Preview* Database Instances provide access to a database via REST API or direct SQL.`, + GroupID: "database", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Database Instances provide access to a database via REST API or direct SQL. For new workloads, Databricks recommends the [Postgres API], which supports the latest Lakebase features. - [Postgres API]: https://docs.databricks.com/api/postgres/v1/postgres`, - GroupID: "database", - RunE: root.ReportUnknownSubcommand, - } + [Postgres API]: https://docs.databricks.com/api/postgres/v1/postgres` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreateDatabaseCatalog()) @@ -69,8 +74,6 @@ Database Instances provide access to a database via REST API or direct SQL. for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-database-catalog command diff --git a/cmd/workspace/default-namespace/default-namespace.go b/cmd/workspace/default-namespace/default-namespace.go index c0ebe0ed600..c8ecff7343b 100644 --- a/cmd/workspace/default-namespace/default-namespace.go +++ b/cmd/workspace/default-namespace/default-namespace.go @@ -3,6 +3,7 @@ package default_namespace import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,15 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "default-namespace", - Short: `*Public Preview* The default namespace setting API allows users to configure the default namespace for a Databricks workspace.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "default-namespace", + Short: `*Public Preview* The default namespace setting API allows users to configure the default namespace for a Databricks workspace.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. The default namespace setting API allows users to configure the default namespace for a Databricks workspace. @@ -34,13 +39,13 @@ The default namespace setting API allows users to configure the default This setting requires a restart of clusters and SQL warehouses to take effect. Additionally, the default namespace only applies when using Unity - Catalog-enabled compute.`, - RunE: root.ReportUnknownSubcommand, - } + Catalog-enabled compute.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newDelete()) @@ -51,8 +56,6 @@ The default namespace setting API allows users to configure the default for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/default-warehouse-id/default-warehouse-id.go b/cmd/workspace/default-warehouse-id/default-warehouse-id.go index 491ac6b972c..ab5d963b7cb 100644 --- a/cmd/workspace/default-warehouse-id/default-warehouse-id.go +++ b/cmd/workspace/default-warehouse-id/default-warehouse-id.go @@ -3,6 +3,7 @@ package default_warehouse_id import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,21 +18,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "default-warehouse-id", - Short: `Warehouse to be selected by default for users in this workspace.`, - Long: `Warehouse to be selected by default for users in this workspace. Covers SQL - workloads only and can be overridden by users.`, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "default-warehouse-id", + Short: `Warehouse to be selected by default for users in this workspace.`, - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Warehouse to be selected by default for users in this workspace. Covers SQL + workloads only and can be overridden by users.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newDelete()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/disable-legacy-access/disable-legacy-access.go b/cmd/workspace/disable-legacy-access/disable-legacy-access.go index 5a4c9639605..c9a7bb96019 100644 --- a/cmd/workspace/disable-legacy-access/disable-legacy-access.go +++ b/cmd/workspace/disable-legacy-access/disable-legacy-access.go @@ -3,6 +3,7 @@ package disable_legacy_access import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,22 +18,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "disable-legacy-access", - Short: `'Disabling legacy access' has the following impacts: 1.`, - Long: `'Disabling legacy access' has the following impacts: +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "disable-legacy-access", + Short: `'Disabling legacy access' has the following impacts: 1.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `'Disabling legacy access' has the following impacts: 1. Disables direct access to Hive Metastores from the workspace. However, you can still access a Hive Metastore through Hive Metastore federation. 2. Disables fallback mode on external location access from the workspace. 3. - Disables Databricks Runtime versions prior to 13.3LTS.`, - RunE: root.ReportUnknownSubcommand, - } + Disables Databricks Runtime versions prior to 13.3LTS.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newDelete()) @@ -43,8 +48,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/disable-legacy-dbfs/disable-legacy-dbfs.go b/cmd/workspace/disable-legacy-dbfs/disable-legacy-dbfs.go index b624e1bffa8..426bb48bb57 100644 --- a/cmd/workspace/disable-legacy-dbfs/disable-legacy-dbfs.go +++ b/cmd/workspace/disable-legacy-dbfs/disable-legacy-dbfs.go @@ -3,6 +3,7 @@ package disable_legacy_dbfs import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,15 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "disable-legacy-dbfs", - Short: `Disabling legacy DBFS has the following implications: 1.`, - Long: `Disabling legacy DBFS has the following implications: +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "disable-legacy-dbfs", + Short: `Disabling legacy DBFS has the following implications: 1.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Disabling legacy DBFS has the following implications: 1. Access to DBFS root and DBFS mounts is disallowed (as well as the creation of new mounts). 2. Disables Databricks Runtime versions prior to 13.3LTS. @@ -29,13 +34,13 @@ func New() *cobra.Command { When the setting is off, all DBFS functionality is enabled and no restrictions are imposed on Databricks Runtime versions. This setting can take up to 20 minutes to take effect and requires a manual restart of all-purpose compute - clusters and SQL warehouses.`, - RunE: root.ReportUnknownSubcommand, - } + clusters and SQL warehouses.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newDelete()) @@ -46,8 +51,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/domains/domains.go b/cmd/workspace/domains/domains.go index 5c4b670cb32..f71f1605309 100644 --- a/cmd/workspace/domains/domains.go +++ b/cmd/workspace/domains/domains.go @@ -3,6 +3,7 @@ package domains import ( + "context" "errors" "fmt" "strings" @@ -20,20 +21,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "domains", - Short: `*Beta* Manage domains for organizing and discovering data assets.`, - Long: `This command is in Beta and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "domains", + Short: `*Beta* Manage domains for organizing and discovering data assets.`, + GroupID: "domains", + Build: buildCommand, +} -Manage domains for organizing and discovering data assets.`, - GroupID: "domains", - RunE: root.ReportUnknownSubcommand, - } +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Beta and may change without notice. - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_BETA" - cmd.Annotations["launch_stage_display"] = "Beta" +Manage domains for organizing and discovering data assets.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_BETA", + "launch_stage_display": "Beta", + } // Add methods cmd.AddCommand(newCreateDomain()) @@ -46,8 +51,6 @@ Manage domains for organizing and discovering data assets.`, for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-domain command diff --git a/cmd/workspace/enable-export-notebook/enable-export-notebook.go b/cmd/workspace/enable-export-notebook/enable-export-notebook.go index 234e724440d..03733f6d5db 100644 --- a/cmd/workspace/enable-export-notebook/enable-export-notebook.go +++ b/cmd/workspace/enable-export-notebook/enable-export-notebook.go @@ -3,6 +3,7 @@ package enable_export_notebook import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,20 +18,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "enable-export-notebook", - Short: `*Public Preview* Controls whether users can export notebooks and files from the Workspace UI.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "enable-export-notebook", + Short: `*Public Preview* Controls whether users can export notebooks and files from the Workspace UI.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Controls whether users can export notebooks and files from the Workspace UI. - By default, this setting is enabled.`, - RunE: root.ReportUnknownSubcommand, - } + By default, this setting is enabled.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newGetEnableExportNotebook()) @@ -40,8 +45,6 @@ Controls whether users can export notebooks and files from the Workspace UI. for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-enable-export-notebook command diff --git a/cmd/workspace/enable-notebook-table-clipboard/enable-notebook-table-clipboard.go b/cmd/workspace/enable-notebook-table-clipboard/enable-notebook-table-clipboard.go index 48e11680f9f..9fffb7d11a2 100644 --- a/cmd/workspace/enable-notebook-table-clipboard/enable-notebook-table-clipboard.go +++ b/cmd/workspace/enable-notebook-table-clipboard/enable-notebook-table-clipboard.go @@ -3,6 +3,7 @@ package enable_notebook_table_clipboard import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,20 +18,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "enable-notebook-table-clipboard", - Short: `*Public Preview* Controls whether users can copy tabular data to the clipboard via the UI.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "enable-notebook-table-clipboard", + Short: `*Public Preview* Controls whether users can copy tabular data to the clipboard via the UI.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Controls whether users can copy tabular data to the clipboard via the UI. By - default, this setting is enabled.`, - RunE: root.ReportUnknownSubcommand, - } + default, this setting is enabled.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newGetEnableNotebookTableClipboard()) @@ -40,8 +45,6 @@ Controls whether users can copy tabular data to the clipboard via the UI. By for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-enable-notebook-table-clipboard command diff --git a/cmd/workspace/enable-results-downloading/enable-results-downloading.go b/cmd/workspace/enable-results-downloading/enable-results-downloading.go index 9d417344d76..140451107f6 100644 --- a/cmd/workspace/enable-results-downloading/enable-results-downloading.go +++ b/cmd/workspace/enable-results-downloading/enable-results-downloading.go @@ -3,6 +3,7 @@ package enable_results_downloading import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,20 +18,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "enable-results-downloading", - Short: `*Public Preview* Controls whether users can download notebook results.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "enable-results-downloading", + Short: `*Public Preview* Controls whether users can download notebook results.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Controls whether users can download notebook results. By default, this setting - is enabled.`, - RunE: root.ReportUnknownSubcommand, - } + is enabled.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newGetEnableResultsDownloading()) @@ -40,8 +45,6 @@ Controls whether users can download notebook results. By default, this setting for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-enable-results-downloading command diff --git a/cmd/workspace/enhanced-security-monitoring/enhanced-security-monitoring.go b/cmd/workspace/enhanced-security-monitoring/enhanced-security-monitoring.go index ee5eb69c722..b365582f48d 100644 --- a/cmd/workspace/enhanced-security-monitoring/enhanced-security-monitoring.go +++ b/cmd/workspace/enhanced-security-monitoring/enhanced-security-monitoring.go @@ -3,6 +3,7 @@ package enhanced_security_monitoring import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,15 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "enhanced-security-monitoring", - Short: `*Public Preview* Controls whether enhanced security monitoring is enabled for the current workspace.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "enhanced-security-monitoring", + Short: `*Public Preview* Controls whether enhanced security monitoring is enabled for the current workspace.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Controls whether enhanced security monitoring is enabled for the current workspace. If the compliance security profile is enabled, this is @@ -29,13 +34,13 @@ Controls whether enhanced security monitoring is enabled for the current security profile is enabled, this is automatically enabled. If the compliance security profile is disabled, you can enable or disable this - setting and it is not permanent.`, - RunE: root.ReportUnknownSubcommand, - } + setting and it is not permanent.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newGet()) @@ -45,8 +50,6 @@ Controls whether enhanced security monitoring is enabled for the current for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/workspace/entity-tag-assignments/entity-tag-assignments.go b/cmd/workspace/entity-tag-assignments/entity-tag-assignments.go index d7caf1bbab7..25e39992e1c 100644 --- a/cmd/workspace/entity-tag-assignments/entity-tag-assignments.go +++ b/cmd/workspace/entity-tag-assignments/entity-tag-assignments.go @@ -3,6 +3,7 @@ package entity_tag_assignments import ( + "context" "errors" "fmt" @@ -18,22 +19,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "entity-tag-assignments", - Short: `Tags are attributes that include keys and optional values that you can use to organize and categorize entities in Unity Catalog.`, - Long: `Tags are attributes that include keys and optional values that you can use to +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "entity-tag-assignments", + Short: `Tags are attributes that include keys and optional values that you can use to organize and categorize entities in Unity Catalog.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Tags are attributes that include keys and optional values that you can use to organize and categorize entities in Unity Catalog. Entity tagging is supported on catalogs, schemas, tables (including views), columns, and volumes. With these APIs, you can create, update, delete, and list tag assignments across - Unity Catalog entities.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + Unity Catalog entities.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -46,8 +51,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/environments/environments.go b/cmd/workspace/environments/environments.go index a11d550a52d..1950156c0d2 100644 --- a/cmd/workspace/environments/environments.go +++ b/cmd/workspace/environments/environments.go @@ -3,6 +3,7 @@ package environments import ( + "context" "errors" "fmt" "strings" @@ -22,23 +23,27 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "environments", - Short: `APIs to manage environment resources.`, - Long: `APIs to manage environment resources. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "environments", + Short: `APIs to manage environment resources.`, + GroupID: "environments", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `APIs to manage environment resources. The Environments API provides management capabilities for different types of environments including workspace-level base environments that define the environment version and dependencies to be used in serverless notebooks and - jobs.`, - GroupID: "environments", - RunE: root.ReportUnknownSubcommand, - } + jobs.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateWorkspaceBaseEnvironment()) @@ -55,8 +60,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-workspace-base-environment command diff --git a/cmd/workspace/experiments/experiments.go b/cmd/workspace/experiments/experiments.go index c2f5d936b19..0bd2c3d6442 100644 --- a/cmd/workspace/experiments/experiments.go +++ b/cmd/workspace/experiments/experiments.go @@ -3,6 +3,7 @@ package experiments import ( + "context" "encoding/json" "errors" "fmt" @@ -22,11 +23,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "experiments", - Short: `Experiments are the primary unit of organization in MLflow; all MLflow runs belong to an experiment.`, - Long: `Experiments are the primary unit of organization in MLflow; all MLflow runs +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "experiments", + Short: `Experiments are the primary unit of organization in MLflow; all MLflow runs belong to an experiment.`, + GroupID: "ml", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Experiments are the primary unit of organization in MLflow; all MLflow runs belong to an experiment. Each experiment lets you visualize, search, and compare runs, as well as download run artifacts or metadata for analysis in other tools. Experiments are maintained in a Databricks hosted MLflow tracking @@ -34,14 +40,13 @@ func New() *cobra.Command { Experiments are located in the workspace file tree. You manage experiments using the same tools you use to manage other workspace objects such as - folders, notebooks, and libraries.`, - GroupID: "ml", - RunE: root.ReportUnknownSubcommand, - } + folders, notebooks, and libraries.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateExperiment()) @@ -92,8 +97,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-experiment command diff --git a/cmd/workspace/external-lineage/external-lineage.go b/cmd/workspace/external-lineage/external-lineage.go index 7d6cec7c938..69142d7cf66 100644 --- a/cmd/workspace/external-lineage/external-lineage.go +++ b/cmd/workspace/external-lineage/external-lineage.go @@ -3,6 +3,7 @@ package external_lineage import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "external-lineage", - Short: `*Public Preview* External Lineage APIs enable defining and managing lineage relationships between Databricks objects and external systems.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "external-lineage", + Short: `*Public Preview* External Lineage APIs enable defining and managing lineage relationships between Databricks objects and external systems.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. External Lineage APIs enable defining and managing lineage relationships between Databricks objects and external systems. These APIs allow users to @@ -30,14 +36,13 @@ External Lineage APIs enable defining and managing lineage relationships external metadata objects. With these APIs, users can create, update, delete, and list lineage - relationships with support for column-level mappings and custom properties.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + relationships with support for column-level mappings and custom properties.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreateExternalLineageRelationship()) @@ -49,8 +54,6 @@ External Lineage APIs enable defining and managing lineage relationships for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-external-lineage-relationship command diff --git a/cmd/workspace/external-locations/external-locations.go b/cmd/workspace/external-locations/external-locations.go index edd702cb4ec..74a4332ad48 100644 --- a/cmd/workspace/external-locations/external-locations.go +++ b/cmd/workspace/external-locations/external-locations.go @@ -3,6 +3,7 @@ package external_locations import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "external-locations", - Short: `An external location is an object that combines a cloud storage path with a storage credential that authorizes access to the cloud storage path.`, - Long: `An external location is an object that combines a cloud storage path with a +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "external-locations", + Short: `An external location is an object that combines a cloud storage path with a storage credential that authorizes access to the cloud storage path.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `An external location is an object that combines a cloud storage path with a storage credential that authorizes access to the cloud storage path. Each external location is subject to Unity Catalog access-control policies that control which users and groups can access the credential. If a user does not @@ -34,14 +40,13 @@ func New() *cobra.Command { credentials directly. To create external locations, you must be a metastore admin or a user with the - **CREATE_EXTERNAL_LOCATION** privilege.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + **CREATE_EXTERNAL_LOCATION** privilege.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -54,8 +59,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/external-metadata/external-metadata.go b/cmd/workspace/external-metadata/external-metadata.go index 3d8e7dac3db..e5ecec90d28 100644 --- a/cmd/workspace/external-metadata/external-metadata.go +++ b/cmd/workspace/external-metadata/external-metadata.go @@ -3,6 +3,7 @@ package external_metadata import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "external-metadata", - Short: `*Public Preview* External Metadata objects enable customers to register and manage metadata about external systems within Unity Catalog.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "external-metadata", + Short: `*Public Preview* External Metadata objects enable customers to register and manage metadata about external systems within Unity Catalog.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. External Metadata objects enable customers to register and manage metadata about external systems within Unity Catalog. @@ -30,14 +36,13 @@ External Metadata objects enable customers to register and manage metadata These APIs provide a standardized way to create, update, retrieve, list, and delete external metadata objects. Fine-grained authorization ensures that only users with appropriate permissions can view and manage external metadata - objects.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + objects.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreateExternalMetadata()) @@ -50,8 +55,6 @@ External Metadata objects enable customers to register and manage metadata for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-external-metadata command diff --git a/cmd/workspace/feature-engineering/feature-engineering.go b/cmd/workspace/feature-engineering/feature-engineering.go index d081e5a5bb4..132d8921ba0 100644 --- a/cmd/workspace/feature-engineering/feature-engineering.go +++ b/cmd/workspace/feature-engineering/feature-engineering.go @@ -3,6 +3,7 @@ package feature_engineering import ( + "context" "errors" "fmt" "strings" @@ -22,19 +23,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "feature-engineering", - Short: `Feature Engineering provides APIs for managing features and materialized features.`, - Long: `Feature Engineering provides APIs for managing features and materialized - features.`, - GroupID: "ml", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "feature-engineering", + Short: `Feature Engineering provides APIs for managing features and materialized features.`, + GroupID: "ml", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Feature Engineering provides APIs for managing features and materialized + features.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newBackfillFeatures()) @@ -74,8 +79,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start backfill-features command diff --git a/cmd/workspace/feature-store/feature-store.go b/cmd/workspace/feature-store/feature-store.go index 1bb57ee7a48..188ceb265b0 100644 --- a/cmd/workspace/feature-store/feature-store.go +++ b/cmd/workspace/feature-store/feature-store.go @@ -3,6 +3,7 @@ package feature_store import ( + "context" "errors" "fmt" @@ -18,28 +19,32 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "feature-store", - Short: `A feature store is a centralized repository that enables data scientists to find and share features.`, - Long: `A feature store is a centralized repository that enables data scientists to +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "feature-store", + Short: `A feature store is a centralized repository that enables data scientists to find and share features.`, + GroupID: "ml", + + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A feature store is a centralized repository that enables data scientists to find and share features. Using a feature store also ensures that the code used to compute feature values is the same during model training and when the model is used for inference. An online store is a low-latency database used for feature lookup during - real-time model inference or serve feature for real-time applications.`, - GroupID: "ml", + real-time model inference or serve feature for real-time applications.` + cmd.RunE = root.ReportUnknownSubcommand - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", } - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" - // Add methods cmd.AddCommand(newCreateOnlineStore()) cmd.AddCommand(newDeleteOnlineStore()) @@ -53,8 +58,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-online-store command diff --git a/cmd/workspace/forecasting/forecasting.go b/cmd/workspace/forecasting/forecasting.go index 29aa8a08fba..1376774de57 100644 --- a/cmd/workspace/forecasting/forecasting.go +++ b/cmd/workspace/forecasting/forecasting.go @@ -3,6 +3,7 @@ package forecasting import ( + "context" "errors" "fmt" "time" @@ -19,22 +20,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "forecasting", - Short: `The Forecasting API allows you to create and get serverless forecasting experiments.`, - Long: `The Forecasting API allows you to create and get serverless forecasting - experiments`, - GroupID: "ml", - - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "forecasting", + Short: `The Forecasting API allows you to create and get serverless forecasting experiments.`, + GroupID: "ml", - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Forecasting API allows you to create and get serverless forecasting + experiments` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newCreateExperiment()) @@ -44,8 +49,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-experiment command diff --git a/cmd/workspace/functions/functions.go b/cmd/workspace/functions/functions.go index 4b00519ea87..8220fde222b 100644 --- a/cmd/workspace/functions/functions.go +++ b/cmd/workspace/functions/functions.go @@ -3,6 +3,7 @@ package functions import ( + "context" "errors" "fmt" @@ -18,23 +19,27 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "functions", - Short: `Functions implement User-Defined Functions (UDFs) in Unity Catalog.`, - Long: `Functions implement User-Defined Functions (UDFs) in Unity Catalog. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "functions", + Short: `Functions implement User-Defined Functions (UDFs) in Unity Catalog.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Functions implement User-Defined Functions (UDFs) in Unity Catalog. The function implementation can be any SQL expression or Query, and it can be invoked wherever a table reference is allowed in a query. In Unity Catalog, a function resides at the same level as a table, so it can be referenced with - the form __catalog_name__.__schema_name__.__function_name__.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + the form __catalog_name__.__schema_name__.__function_name__.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -47,8 +52,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/genie-agents/genie-agents.go b/cmd/workspace/genie-agents/genie-agents.go index d7d9e866c50..afd9996b02e 100644 --- a/cmd/workspace/genie-agents/genie-agents.go +++ b/cmd/workspace/genie-agents/genie-agents.go @@ -3,6 +3,7 @@ package genie_agents import ( + "context" "errors" "fmt" "strings" @@ -20,26 +21,30 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "genie-agents", - Short: `Genie provides a no-code experience for business users, powered by AI/BI.`, - Long: `Genie provides a no-code experience for business users, powered by AI/BI. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "genie-agents", + Short: `Genie provides a no-code experience for business users, powered by AI/BI.`, + GroupID: "dashboards", + + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Genie provides a no-code experience for business users, powered by AI/BI. Analysts set up Genie Agents that business users can use to ask questions using natural language. Genie uses data registered to Unity Catalog and requires at least CAN USE permission on a Pro or Serverless SQL warehouse. - Also, Databricks Assistant must be enabled.`, - GroupID: "dashboards", + Also, Databricks Assistant must be enabled.` + cmd.RunE = root.ReportUnknownSubcommand - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", } - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" - // Add methods cmd.AddCommand(newCreateGenieAgent()) cmd.AddCommand(newDeleteGenieAgent()) @@ -51,8 +56,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-genie-agent command diff --git a/cmd/workspace/genie/genie.go b/cmd/workspace/genie/genie.go index 4d4e9dda5ac..ef71c0153c5 100644 --- a/cmd/workspace/genie/genie.go +++ b/cmd/workspace/genie/genie.go @@ -3,6 +3,7 @@ package genie import ( + "context" "errors" "fmt" "time" @@ -19,22 +20,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "genie", - Short: `Genie provides a no-code experience for business users, powered by AI/BI.`, - Long: `Genie provides a no-code experience for business users, powered by AI/BI. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "genie", + Short: `Genie provides a no-code experience for business users, powered by AI/BI.`, + GroupID: "dashboards", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Genie provides a no-code experience for business users, powered by AI/BI. Analysts set up spaces that business users can use to ask questions using natural language. Genie uses data registered to Unity Catalog and requires at least CAN USE permission on a Pro or Serverless SQL warehouse. Also, - Databricks Assistant must be enabled.`, - GroupID: "dashboards", - RunE: root.ReportUnknownSubcommand, - } + Databricks Assistant must be enabled.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateMessage()) @@ -72,8 +77,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-message command diff --git a/cmd/workspace/git-credentials/git-credentials.go b/cmd/workspace/git-credentials/git-credentials.go index 9288c2b5941..3ce468c8013 100644 --- a/cmd/workspace/git-credentials/git-credentials.go +++ b/cmd/workspace/git-credentials/git-credentials.go @@ -3,6 +3,7 @@ package git_credentials import ( + "context" "errors" "fmt" @@ -18,23 +19,27 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "git-credentials", - Short: `Registers personal access token for Databricks to do operations on behalf of the user.`, - Long: `Registers personal access token for Databricks to do operations on behalf of +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "git-credentials", + Short: `Registers personal access token for Databricks to do operations on behalf of the user.`, + GroupID: "workspace", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Registers personal access token for Databricks to do operations on behalf of the user. See [more info]. - [more info]: https://docs.databricks.com/repos/get-access-tokens-from-git-provider.html`, - GroupID: "workspace", - RunE: root.ReportUnknownSubcommand, - } + [more info]: https://docs.databricks.com/repos/get-access-tokens-from-git-provider.html` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -47,8 +52,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/global-init-scripts/global-init-scripts.go b/cmd/workspace/global-init-scripts/global-init-scripts.go index 674173ea22b..dad32ccc6a4 100644 --- a/cmd/workspace/global-init-scripts/global-init-scripts.go +++ b/cmd/workspace/global-init-scripts/global-init-scripts.go @@ -3,6 +3,7 @@ package global_init_scripts import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "global-init-scripts", - Short: `The Global Init Scripts API enables Workspace administrators to configure global initialization scripts for their workspace.`, - Long: `The Global Init Scripts API enables Workspace administrators to configure +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "global-init-scripts", + Short: `The Global Init Scripts API enables Workspace administrators to configure global initialization scripts for their workspace.`, + GroupID: "compute", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Global Init Scripts API enables Workspace administrators to configure global initialization scripts for their workspace. These scripts run on every node in every cluster in the workspace. @@ -30,14 +36,13 @@ func New() *cobra.Command { to global init scripts. Global init scripts are run in order. If the init script returns with a bad exit code, the Apache Spark container fails to launch and init scripts with later position are skipped. If enough containers - fail, the entire cluster fails with a GLOBAL_INIT_SCRIPT_FAILURE error code.`, - GroupID: "compute", - RunE: root.ReportUnknownSubcommand, - } + fail, the entire cluster fails with a GLOBAL_INIT_SCRIPT_FAILURE error code.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -50,8 +55,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/grants/grants.go b/cmd/workspace/grants/grants.go index 800e48fe5d2..e7c375802e2 100644 --- a/cmd/workspace/grants/grants.go +++ b/cmd/workspace/grants/grants.go @@ -3,6 +3,7 @@ package grants import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "grants", - Short: `In Unity Catalog, data is secure by default.`, - Long: `In Unity Catalog, data is secure by default. Initially, users have no access +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "grants", + Short: `In Unity Catalog, data is secure by default.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `In Unity Catalog, data is secure by default. Initially, users have no access to data in a metastore. Access can be granted by either a metastore admin, the owner of an object, or the owner of the catalog or schema that contains the object. Securable objects in Unity Catalog are hierarchical and privileges are @@ -30,14 +36,13 @@ func New() *cobra.Command { This means that granting a privilege on the catalog automatically grants the privilege to all current and future objects within the catalog. Similarly, privileges granted on a schema are inherited by all current and future objects - within that schema.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + within that schema.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGet()) @@ -50,8 +55,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/workspace/groups-v2/groups-v2.go b/cmd/workspace/groups-v2/groups-v2.go index 64b5439cb7a..0b382057187 100644 --- a/cmd/workspace/groups-v2/groups-v2.go +++ b/cmd/workspace/groups-v2/groups-v2.go @@ -3,6 +3,7 @@ package groups_v2 import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "groups-v2", - Short: `*Public Preview* Groups simplify identity management, making it easier to assign access to Databricks workspace, data, and other securable objects.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "groups-v2", + Short: `*Public Preview* Groups simplify identity management, making it easier to assign access to Databricks workspace, data, and other securable objects.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Groups simplify identity management, making it easier to assign access to Databricks workspace, data, and other securable objects. @@ -29,14 +35,13 @@ Groups simplify identity management, making it easier to assign access to It is best practice to assign access to workspaces and access-control policies in Unity Catalog to groups, instead of to users individually. All Databricks workspace identities can be assigned as members of groups, and members inherit - permissions that are assigned to their group.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } + permissions that are assigned to their group.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreate()) @@ -50,8 +55,6 @@ Groups simplify identity management, making it easier to assign access to for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/groups/groups.go b/cmd/workspace/groups/groups.go index 595c03218bb..a51711a076c 100755 --- a/cmd/workspace/groups/groups.go +++ b/cmd/workspace/groups/groups.go @@ -6,6 +6,7 @@ package groups import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -20,23 +21,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "groups", - Short: `Groups simplify identity management, making it easier to assign access to Databricks workspace, data, and other securable objects.`, - Long: `Groups simplify identity management, making it easier to assign access to +// Spec declares the groups command. +var Spec = root.CommandSpec{ + Use: "groups", + Short: `Groups simplify identity management, making it easier to assign access to Databricks workspace, data, and other securable objects.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Annotations = map[string]string{ + "package": "iam", + } + cmd.Long = `Groups simplify identity management, making it easier to assign access to Databricks workspace, data, and other securable objects. It is best practice to assign access to workspaces and access-control policies in Unity Catalog to groups, instead of to users individually. All Databricks workspace identities can be assigned as members of groups, and members inherit - permissions that are assigned to their group.`, - GroupID: "iam", - Annotations: map[string]string{ - "package": "iam", - }, - RunE: root.ReportUnknownSubcommand, - } + permissions that are assigned to their group.` + cmd.RunE = root.ReportUnknownSubcommand // Add methods cmd.AddCommand(newCreate()) @@ -50,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/instance-pools/instance-pools.go b/cmd/workspace/instance-pools/instance-pools.go index 08e8c91b425..27bfaef2c72 100644 --- a/cmd/workspace/instance-pools/instance-pools.go +++ b/cmd/workspace/instance-pools/instance-pools.go @@ -3,6 +3,7 @@ package instance_pools import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "instance-pools", - Short: `Instance Pools API are used to create, edit, delete and list instance pools by using ready-to-use cloud instances which reduces a cluster start and auto-scaling times.`, - Long: `Instance Pools API are used to create, edit, delete and list instance pools by +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "instance-pools", + Short: `Instance Pools API are used to create, edit, delete and list instance pools by using ready-to-use cloud instances which reduces a cluster start and auto-scaling times.`, + GroupID: "compute", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Instance Pools API are used to create, edit, delete and list instance pools by using ready-to-use cloud instances which reduces a cluster start and auto-scaling times. @@ -39,14 +45,13 @@ func New() *cobra.Command { the same pool for both. Databricks does not charge DBUs while instances are idle in the pool. Instance - provider billing does apply. See pricing.`, - GroupID: "compute", - RunE: root.ReportUnknownSubcommand, - } + provider billing does apply. See pricing.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -63,8 +68,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/instance-profiles/instance-profiles.go b/cmd/workspace/instance-profiles/instance-profiles.go index 8ddbdaf8f2f..27e6535f402 100644 --- a/cmd/workspace/instance-profiles/instance-profiles.go +++ b/cmd/workspace/instance-profiles/instance-profiles.go @@ -3,6 +3,7 @@ package instance_profiles import ( + "context" "errors" "fmt" @@ -18,23 +19,27 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "instance-profiles", - Short: `The Instance Profiles API allows admins to add, list, and remove instance profiles that users can launch clusters with.`, - Long: `The Instance Profiles API allows admins to add, list, and remove instance +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "instance-profiles", + Short: `The Instance Profiles API allows admins to add, list, and remove instance profiles that users can launch clusters with.`, + GroupID: "compute", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Instance Profiles API allows admins to add, list, and remove instance profiles that users can launch clusters with. Regular users can list the instance profiles available to them. See [Secure access to S3 buckets] using instance profiles for more information. - [Secure access to S3 buckets]: https://docs.databricks.com/administration-guide/cloud-configurations/aws/instance-profiles.html`, - GroupID: "compute", - RunE: root.ReportUnknownSubcommand, - } + [Secure access to S3 buckets]: https://docs.databricks.com/administration-guide/cloud-configurations/aws/instance-profiles.html` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newAdd()) @@ -46,8 +51,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start add command diff --git a/cmd/workspace/ip-access-lists/ip-access-lists.go b/cmd/workspace/ip-access-lists/ip-access-lists.go index 2916a1d55b0..ddb7799fdd8 100644 --- a/cmd/workspace/ip-access-lists/ip-access-lists.go +++ b/cmd/workspace/ip-access-lists/ip-access-lists.go @@ -3,6 +3,7 @@ package ip_access_lists import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "ip-access-lists", - Short: `IP Access List enables admins to configure IP access lists.`, - Long: `IP Access List enables admins to configure IP access lists. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "ip-access-lists", + Short: `IP Access List enables admins to configure IP access lists.`, + GroupID: "settings", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `IP Access List enables admins to configure IP access lists. IP access lists affect web application access and REST API access to this workspace only. If the feature is disabled for a workspace, all access is @@ -42,14 +48,13 @@ func New() *cobra.Command { of 1000 IP/CIDR values, where one CIDR counts as a single value. After changes to the IP access list feature, it can take a few minutes for - changes to take effect.`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } + changes to take effect.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -63,8 +68,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/jobs/jobs.go b/cmd/workspace/jobs/jobs.go index 17d8aff87cf..4240b26aac4 100644 --- a/cmd/workspace/jobs/jobs.go +++ b/cmd/workspace/jobs/jobs.go @@ -3,6 +3,7 @@ package jobs import ( + "context" "errors" "fmt" "time" @@ -19,11 +20,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "jobs", - Short: `The Jobs API allows you to create, edit, and delete jobs.`, - Long: `The Jobs API allows you to create, edit, and delete jobs. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "jobs", + Short: `The Jobs API allows you to create, edit, and delete jobs.`, + GroupID: "lakeflow", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Jobs API allows you to create, edit, and delete jobs. You can use a Databricks job to run a data processing or data analysis task in a Databricks cluster with scalable resources. Your job can consist of a single @@ -40,14 +46,13 @@ func New() *cobra.Command { [Databricks CLI]: https://docs.databricks.com/dev-tools/cli/index.html [Secrets CLI]: https://docs.databricks.com/dev-tools/cli/secrets-cli.html - [Secrets utility]: https://docs.databricks.com/dev-tools/databricks-utils.html#dbutils-secrets`, - GroupID: "lakeflow", - RunE: root.ReportUnknownSubcommand, - } + [Secrets utility]: https://docs.databricks.com/dev-tools/databricks-utils.html#dbutils-secrets` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCancelAllRuns()) @@ -75,8 +80,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start cancel-all-runs command diff --git a/cmd/workspace/knowledge-assistants/knowledge-assistants.go b/cmd/workspace/knowledge-assistants/knowledge-assistants.go index 86fa0ec60c8..603eefe6c65 100644 --- a/cmd/workspace/knowledge-assistants/knowledge-assistants.go +++ b/cmd/workspace/knowledge-assistants/knowledge-assistants.go @@ -3,6 +3,7 @@ package knowledge_assistants import ( + "context" "errors" "fmt" "strings" @@ -20,20 +21,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "knowledge-assistants", - Short: `*Beta* Manage legacy Knowledge Assistants and related resources.`, - Long: `This command is in Beta and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "knowledge-assistants", + Short: `*Beta* Manage legacy Knowledge Assistants and related resources.`, + GroupID: "agentbricks", + Build: buildCommand, +} -Manage legacy Knowledge Assistants and related resources.`, - GroupID: "agentbricks", - RunE: root.ReportUnknownSubcommand, - } +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Beta and may change without notice. - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_BETA" - cmd.Annotations["launch_stage_display"] = "Beta" +Manage legacy Knowledge Assistants and related resources.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_BETA", + "launch_stage_display": "Beta", + } // Add methods cmd.AddCommand(newCreateExample()) @@ -61,8 +66,6 @@ Manage legacy Knowledge Assistants and related resources.`, for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-example command diff --git a/cmd/workspace/lakeview-embedded/lakeview-embedded.go b/cmd/workspace/lakeview-embedded/lakeview-embedded.go index 76a4d5b35b7..93e84ae1f9f 100644 --- a/cmd/workspace/lakeview-embedded/lakeview-embedded.go +++ b/cmd/workspace/lakeview-embedded/lakeview-embedded.go @@ -3,6 +3,8 @@ package lakeview_embedded import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -14,18 +16,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "lakeview-embedded", - Short: `Token-based Lakeview APIs for embedding dashboards in external applications.`, - Long: `Token-based Lakeview APIs for embedding dashboards in external applications.`, - GroupID: "dashboards", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "lakeview-embedded", + Short: `Token-based Lakeview APIs for embedding dashboards in external applications.`, + GroupID: "dashboards", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Token-based Lakeview APIs for embedding dashboards in external applications.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGetPublishedDashboardTokenInfo()) @@ -34,8 +40,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-published-dashboard-token-info command diff --git a/cmd/workspace/lakeview/lakeview.go b/cmd/workspace/lakeview/lakeview.go index f7b2d2f3c46..6c27c4f10d4 100644 --- a/cmd/workspace/lakeview/lakeview.go +++ b/cmd/workspace/lakeview/lakeview.go @@ -3,6 +3,7 @@ package lakeview import ( + "context" "errors" "fmt" @@ -18,20 +19,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "lakeview", - Short: `These APIs provide specific management operations for Lakeview dashboards.`, - Long: `These APIs provide specific management operations for Lakeview dashboards. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "lakeview", + Short: `These APIs provide specific management operations for Lakeview dashboards.`, + GroupID: "dashboards", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs provide specific management operations for Lakeview dashboards. Generic resource management can be done with Workspace API (import, export, - get-status, list, delete).`, - GroupID: "dashboards", - RunE: root.ReportUnknownSubcommand, - } + get-status, list, delete).` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -58,8 +63,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/lakewatch/lakewatch.go b/cmd/workspace/lakewatch/lakewatch.go index 511c70d4f28..086f6f60206 100644 --- a/cmd/workspace/lakewatch/lakewatch.go +++ b/cmd/workspace/lakewatch/lakewatch.go @@ -3,6 +3,7 @@ package lakewatch import ( + "context" "encoding/json" "errors" "fmt" @@ -22,21 +23,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "lakewatch", - Short: `*Beta* Manage Lakewatch: security-analytics data sources, detection rules, and per-catalog configuration.`, - Long: `This command is in Beta and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "lakewatch", + Short: `*Beta* Manage Lakewatch: security-analytics data sources, detection rules, and per-catalog configuration.`, + GroupID: "lakewatch", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Beta and may change without notice. Manage Lakewatch: security-analytics data sources, detection rules, and - per-catalog configuration.`, - GroupID: "lakewatch", - RunE: root.ReportUnknownSubcommand, - } + per-catalog configuration.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_BETA" - cmd.Annotations["launch_stage_display"] = "Beta" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_BETA", + "launch_stage_display": "Beta", + } // Add methods cmd.AddCommand(newCreateDatasource()) @@ -62,8 +67,6 @@ Manage Lakewatch: security-analytics data sources, detection rules, and for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-datasource command diff --git a/cmd/workspace/libraries/libraries.go b/cmd/workspace/libraries/libraries.go index 92b71e73019..2ea301001c0 100644 --- a/cmd/workspace/libraries/libraries.go +++ b/cmd/workspace/libraries/libraries.go @@ -3,6 +3,7 @@ package libraries import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "libraries", - Short: `The Libraries API allows you to install and uninstall libraries and get the status of libraries on a cluster.`, - Long: `The Libraries API allows you to install and uninstall libraries and get the +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "libraries", + Short: `The Libraries API allows you to install and uninstall libraries and get the status of libraries on a cluster.`, + GroupID: "compute", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Libraries API allows you to install and uninstall libraries and get the status of libraries on a cluster. To make third-party or custom code available to notebooks and jobs running on @@ -37,14 +43,13 @@ func New() *cobra.Command { When you uninstall a library from a cluster, the library is removed only when you restart the cluster. Until you restart the cluster, the status of the - uninstalled library appears as Uninstall pending restart.`, - GroupID: "compute", - RunE: root.ReportUnknownSubcommand, - } + uninstalled library appears as Uninstall pending restart.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newAllClusterStatuses()) @@ -56,8 +61,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start all-cluster-statuses command diff --git a/cmd/workspace/llm-proxy-partner-powered-workspace/llm-proxy-partner-powered-workspace.go b/cmd/workspace/llm-proxy-partner-powered-workspace/llm-proxy-partner-powered-workspace.go index e7186373e02..803422f76c5 100644 --- a/cmd/workspace/llm-proxy-partner-powered-workspace/llm-proxy-partner-powered-workspace.go +++ b/cmd/workspace/llm-proxy-partner-powered-workspace/llm-proxy-partner-powered-workspace.go @@ -3,6 +3,7 @@ package llm_proxy_partner_powered_workspace import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,21 +18,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "llm-proxy-partner-powered-workspace", - Short: `Determines if partner powered models are enabled or not for a specific workspace.`, - Long: `Determines if partner powered models are enabled or not for a specific - workspace`, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "llm-proxy-partner-powered-workspace", + Short: `Determines if partner powered models are enabled or not for a specific workspace.`, - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Determines if partner powered models are enabled or not for a specific + workspace` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newDelete()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/materialized-features/materialized-features.go b/cmd/workspace/materialized-features/materialized-features.go index 8da35540e24..c80ed6ec483 100644 --- a/cmd/workspace/materialized-features/materialized-features.go +++ b/cmd/workspace/materialized-features/materialized-features.go @@ -3,6 +3,7 @@ package materialized_features import ( + "context" "errors" "fmt" @@ -18,22 +19,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "materialized-features", - Short: `Materialized Features are columns in tables and views that can be directly used as features to train and serve ML models.`, - Long: `Materialized Features are columns in tables and views that can be directly - used as features to train and serve ML models.`, - GroupID: "ml", - - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "materialized-features", + Short: `Materialized Features are columns in tables and views that can be directly used as features to train and serve ML models.`, + GroupID: "ml", - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Materialized Features are columns in tables and views that can be directly + used as features to train and serve ML models.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newCreateFeatureTag()) @@ -47,8 +52,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-feature-tag command diff --git a/cmd/workspace/metastores/metastores.go b/cmd/workspace/metastores/metastores.go index d0fa87e0033..05137065d13 100644 --- a/cmd/workspace/metastores/metastores.go +++ b/cmd/workspace/metastores/metastores.go @@ -3,6 +3,7 @@ package metastores import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "metastores", - Short: `A metastore is the top-level container of objects in Unity Catalog.`, - Long: `A metastore is the top-level container of objects in Unity Catalog. It stores +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "metastores", + Short: `A metastore is the top-level container of objects in Unity Catalog.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A metastore is the top-level container of objects in Unity Catalog. It stores data assets (tables and views) and the permissions that govern access to them. Databricks account admins can create metastores and assign them to Databricks workspaces to control which workloads use each metastore. For a workspace to @@ -34,14 +40,13 @@ func New() *cobra.Command { NOTE: This metastore is distinct from the metastore included in Databricks workspaces created before Unity Catalog was released. If your workspace includes a legacy Hive metastore, the data in that metastore is available in a - catalog named hive_metastore.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + catalog named hive_metastore.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newAssign()) @@ -60,8 +65,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start assign command diff --git a/cmd/workspace/model-registry/model-registry.go b/cmd/workspace/model-registry/model-registry.go index 2c88d8d7dc1..3d3076f8891 100644 --- a/cmd/workspace/model-registry/model-registry.go +++ b/cmd/workspace/model-registry/model-registry.go @@ -3,6 +3,7 @@ package model_registry import ( + "context" "errors" "fmt" @@ -18,25 +19,29 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "model-registry", - Short: `Note: This API reference documents APIs for the Workspace Model Registry.`, - Long: `Note: This API reference documents APIs for the Workspace Model Registry. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "model-registry", + Short: `Note: This API reference documents APIs for the Workspace Model Registry.`, + GroupID: "ml", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Note: This API reference documents APIs for the Workspace Model Registry. Databricks recommends using [Models in Unity Catalog](/api/workspace/registeredmodels) instead. Models in Unity Catalog provides centralized model governance, cross-workspace access, lineage, and deployment. Workspace Model Registry will be deprecated in the future. The Workspace Model Registry is a centralized model repository and a UI and - set of APIs that enable you to manage the full lifecycle of MLflow Models.`, - GroupID: "ml", - RunE: root.ReportUnknownSubcommand, - } + set of APIs that enable you to manage the full lifecycle of MLflow Models.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newApproveTransitionRequest()) @@ -80,8 +85,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start approve-transition-request command diff --git a/cmd/workspace/model-versions/model-versions.go b/cmd/workspace/model-versions/model-versions.go index 3d6e21a7f46..48089624931 100644 --- a/cmd/workspace/model-versions/model-versions.go +++ b/cmd/workspace/model-versions/model-versions.go @@ -3,6 +3,7 @@ package model_versions import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,24 +18,28 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "model-versions", - Short: `Databricks provides a hosted version of MLflow Model Registry in Unity Catalog.`, - Long: `Databricks provides a hosted version of MLflow Model Registry in Unity +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "model-versions", + Short: `Databricks provides a hosted version of MLflow Model Registry in Unity Catalog.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Databricks provides a hosted version of MLflow Model Registry in Unity Catalog. Models in Unity Catalog provide centralized access control, auditing, lineage, and discovery of ML models across Databricks workspaces. This API reference documents the REST endpoints for managing model versions in Unity Catalog. For more details, see the [registered models API - docs](/api/workspace/registeredmodels).`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + docs](/api/workspace/registeredmodels).` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newDelete()) @@ -47,8 +52,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/notification-destinations/notification-destinations.go b/cmd/workspace/notification-destinations/notification-destinations.go index e463527466a..a08199f0b8e 100644 --- a/cmd/workspace/notification-destinations/notification-destinations.go +++ b/cmd/workspace/notification-destinations/notification-destinations.go @@ -3,6 +3,7 @@ package notification_destinations import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,22 +18,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "notification-destinations", - Short: `The notification destinations API lets you programmatically manage a workspace's notification destinations.`, - Long: `The notification destinations API lets you programmatically manage a +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "notification-destinations", + Short: `The notification destinations API lets you programmatically manage a workspace's notification destinations.`, + GroupID: "settings", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The notification destinations API lets you programmatically manage a workspace's notification destinations. Notification destinations are used to send notifications for query alerts and jobs to destinations outside of Databricks. Only workspace admins can create, update, and delete notification - destinations.`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } + destinations.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -45,8 +50,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/online-tables/online-tables.go b/cmd/workspace/online-tables/online-tables.go index d634450328e..c8c9deee4b2 100644 --- a/cmd/workspace/online-tables/online-tables.go +++ b/cmd/workspace/online-tables/online-tables.go @@ -3,6 +3,7 @@ package online_tables import ( + "context" "fmt" "time" @@ -18,21 +19,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "online-tables", - Short: `*Public Preview* Online tables provide lower latency and higher QPS access to data from Delta tables.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "online-tables", + Short: `*Public Preview* Online tables provide lower latency and higher QPS access to data from Delta tables.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Online tables provide lower latency and higher QPS access to data from Delta - tables.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + tables.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreate()) @@ -43,8 +48,6 @@ Online tables provide lower latency and higher QPS access to data from Delta for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/permission-migration/permission-migration.go b/cmd/workspace/permission-migration/permission-migration.go index 3c9b6741b28..c7cdaf451da 100644 --- a/cmd/workspace/permission-migration/permission-migration.go +++ b/cmd/workspace/permission-migration/permission-migration.go @@ -3,6 +3,7 @@ package permission_migration import ( + "context" "errors" "fmt" @@ -18,22 +19,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "permission-migration", - Short: `APIs for migrating acl permissions, used only by the ucx tool: https://github.com/databrickslabs/ucx.`, - Long: `APIs for migrating acl permissions, used only by the ucx tool: - https://github.com/databrickslabs/ucx`, - GroupID: "iam", - - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "permission-migration", + Short: `APIs for migrating acl permissions, used only by the ucx tool: https://github.com/databrickslabs/ucx.`, + GroupID: "iam", - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `APIs for migrating acl permissions, used only by the ucx tool: + https://github.com/databrickslabs/ucx` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newMigratePermissions()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start migrate-permissions command diff --git a/cmd/workspace/permissions/permissions.go b/cmd/workspace/permissions/permissions.go index 02bd53c875d..975069dfc10 100644 --- a/cmd/workspace/permissions/permissions.go +++ b/cmd/workspace/permissions/permissions.go @@ -3,6 +3,8 @@ package permissions import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -15,11 +17,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "permissions", - Short: `Permissions API are used to create read, write, edit, update and manage access for various users on different objects and endpoints.`, - Long: `Permissions API are used to create read, write, edit, update and manage access +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "permissions", + Short: `Permissions API are used to create read, write, edit, update and manage access for various users on different objects and endpoints.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Permissions API are used to create read, write, edit, update and manage access for various users on different objects and endpoints. * **[Apps permissions](:service:apps)** — Manage which users can manage or use apps. * **[Cluster permissions](:service:clusters)** — Manage which users can @@ -49,14 +56,13 @@ func New() *cobra.Command { access control on service principals, use **[Account Access Control Proxy](:service:accountaccesscontrolproxy)**. - [Access Control]: https://docs.databricks.com/security/auth-authz/access-control/index.html`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } + [Access Control]: https://docs.databricks.com/security/auth-authz/access-control/index.html` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGet()) @@ -68,8 +74,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/workspace/pipelines/pipelines.go b/cmd/workspace/pipelines/pipelines.go index 6806a5f7b70..2eb804c9003 100644 --- a/cmd/workspace/pipelines/pipelines.go +++ b/cmd/workspace/pipelines/pipelines.go @@ -3,6 +3,7 @@ package pipelines import ( + "context" "errors" "fmt" "time" @@ -19,11 +20,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "pipelines", - Short: `The Lakeflow Spark Declarative Pipelines API allows you to create, edit, delete, start, and view details about pipelines.`, - Long: `The Lakeflow Spark Declarative Pipelines API allows you to create, edit, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "pipelines", + Short: `The Lakeflow Spark Declarative Pipelines API allows you to create, edit, delete, start, and view details about pipelines.`, + GroupID: "lakeflow", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Lakeflow Spark Declarative Pipelines API allows you to create, edit, delete, start, and view details about pipelines. Spark Declarative Pipelines is a framework for building reliable, @@ -37,14 +43,13 @@ func New() *cobra.Command { based on a target schema you define for each processing step. You can also enforce data quality with Spark Declarative Pipelines expectations. Expectations allow you to define expected data quality and specify how to - handle records that fail those expectations.`, - GroupID: "lakeflow", - RunE: root.ReportUnknownSubcommand, - } + handle records that fail those expectations.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newApplyEnvironment()) @@ -68,8 +73,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start apply-environment command diff --git a/cmd/workspace/policies/policies.go b/cmd/workspace/policies/policies.go index c615faaed57..4622de218d6 100644 --- a/cmd/workspace/policies/policies.go +++ b/cmd/workspace/policies/policies.go @@ -3,6 +3,7 @@ package policies import ( + "context" "errors" "fmt" @@ -18,25 +19,29 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "policies", - Short: `Attribute-Based Access Control (ABAC) provides high leverage governance for enforcing compliance policies in Unity Catalog.`, - Long: `Attribute-Based Access Control (ABAC) provides high leverage governance for +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "policies", + Short: `Attribute-Based Access Control (ABAC) provides high leverage governance for enforcing compliance policies in Unity Catalog.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Attribute-Based Access Control (ABAC) provides high leverage governance for enforcing compliance policies in Unity Catalog. With ABAC policies, access is controlled in a hierarchical and scalable manner, based on data attributes rather than specific resources, enabling more flexible and comprehensive access control. ABAC policies in Unity Catalog support conditions on securable properties, governance tags, and environment contexts. Callers must have the MANAGE privilege on a securable to view, create, update, or delete ABAC - policies.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + policies.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreatePolicy()) @@ -49,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-policy command diff --git a/cmd/workspace/policy-compliance-for-clusters/policy-compliance-for-clusters.go b/cmd/workspace/policy-compliance-for-clusters/policy-compliance-for-clusters.go index e18a23b556f..2c2e4d9d915 100644 --- a/cmd/workspace/policy-compliance-for-clusters/policy-compliance-for-clusters.go +++ b/cmd/workspace/policy-compliance-for-clusters/policy-compliance-for-clusters.go @@ -3,6 +3,7 @@ package policy_compliance_for_clusters import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "policy-compliance-for-clusters", - Short: `The policy compliance APIs allow you to view and manage the policy compliance status of clusters in your workspace.`, - Long: `The policy compliance APIs allow you to view and manage the policy compliance +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "policy-compliance-for-clusters", + Short: `The policy compliance APIs allow you to view and manage the policy compliance status of clusters in your workspace.`, + GroupID: "compute", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The policy compliance APIs allow you to view and manage the policy compliance status of clusters in your workspace. A cluster is compliant with its policy if its configuration satisfies all its @@ -31,14 +37,13 @@ func New() *cobra.Command { The get and list compliance APIs allow you to view the policy compliance status of a cluster. The enforce compliance API allows you to update a cluster - to be compliant with the current version of its policy.`, - GroupID: "compute", - RunE: root.ReportUnknownSubcommand, - } + to be compliant with the current version of its policy.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCancelPendingClusterEnforcement()) @@ -50,8 +55,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start cancel-pending-cluster-enforcement command diff --git a/cmd/workspace/policy-compliance-for-jobs/policy-compliance-for-jobs.go b/cmd/workspace/policy-compliance-for-jobs/policy-compliance-for-jobs.go index 7925735e472..120dae06d7c 100644 --- a/cmd/workspace/policy-compliance-for-jobs/policy-compliance-for-jobs.go +++ b/cmd/workspace/policy-compliance-for-jobs/policy-compliance-for-jobs.go @@ -3,6 +3,7 @@ package policy_compliance_for_jobs import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "policy-compliance-for-jobs", - Short: `The compliance APIs allow you to view and manage the policy compliance status of jobs in your workspace.`, - Long: `The compliance APIs allow you to view and manage the policy compliance status +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "policy-compliance-for-jobs", + Short: `The compliance APIs allow you to view and manage the policy compliance status of jobs in your workspace.`, + GroupID: "lakeflow", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The compliance APIs allow you to view and manage the policy compliance status of jobs in your workspace. This API currently only supports compliance controls for cluster policies. @@ -34,14 +40,13 @@ func New() *cobra.Command { The get and list compliance APIs allow you to view the policy compliance status of a job. The enforce compliance API allows you to update a job so that - it becomes compliant with all of its policies.`, - GroupID: "lakeflow", - RunE: root.ReportUnknownSubcommand, - } + it becomes compliant with all of its policies.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newEnforceCompliance()) @@ -52,8 +57,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start enforce-compliance command diff --git a/cmd/workspace/policy-families/policy-families.go b/cmd/workspace/policy-families/policy-families.go index d760aaf7db6..5cb4b72b862 100644 --- a/cmd/workspace/policy-families/policy-families.go +++ b/cmd/workspace/policy-families/policy-families.go @@ -3,6 +3,7 @@ package policy_families import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -16,11 +17,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "policy-families", - Short: `View available policy families.`, - Long: `View available policy families. A policy family contains a policy definition +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "policy-families", + Short: `View available policy families.`, + GroupID: "compute", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `View available policy families. A policy family contains a policy definition providing best practices for configuring clusters for a particular use case. Databricks manages and provides policy families for several common cluster use @@ -28,14 +34,13 @@ func New() *cobra.Command { Policy families cannot be used directly to create clusters. Instead, you create cluster policies using a policy family. Cluster policies created using - a policy family inherit the policy family's policy definition.`, - GroupID: "compute", - RunE: root.ReportUnknownSubcommand, - } + a policy family inherit the policy family's policy definition.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGet()) @@ -45,8 +50,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/workspace/postgres/postgres.go b/cmd/workspace/postgres/postgres.go index 3dc3bc39615..4e4cc88ac76 100644 --- a/cmd/workspace/postgres/postgres.go +++ b/cmd/workspace/postgres/postgres.go @@ -3,6 +3,7 @@ package postgres import ( + "context" "encoding/json" "errors" "fmt" @@ -25,11 +26,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "postgres", - Short: `Use the Postgres API to create and manage Lakebase Autoscaling Postgres infrastructure, including projects, branches, compute endpoints, and roles.`, - Long: `Use the Postgres API to create and manage Lakebase Autoscaling Postgres +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "postgres", + Short: `Use the Postgres API to create and manage Lakebase Autoscaling Postgres infrastructure, including projects, branches, compute endpoints, and roles.`, + GroupID: "postgres", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Use the Postgres API to create and manage Lakebase Autoscaling Postgres infrastructure, including projects, branches, compute endpoints, and roles. This API manages database infrastructure only. To query or modify data, use @@ -40,14 +46,13 @@ func New() *cobra.Command { Resources are identified by hierarchical resource names like projects/{project_id}/branches/{branch_id}/endpoints/{endpoint_id}. The name field on each resource contains this full path and is output-only. Note - that name refers to this resource path, not the user-visible display_name.`, - GroupID: "postgres", - RunE: root.ReportUnknownSubcommand, - } + that name refers to this resource path, not the user-visible display_name.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newAcknowledgeAssessmentWarnings()) @@ -118,8 +123,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start acknowledge-assessment-warnings command diff --git a/cmd/workspace/provider-exchange-filters/provider-exchange-filters.go b/cmd/workspace/provider-exchange-filters/provider-exchange-filters.go index be9f29ef6c8..bfd69a5e42a 100644 --- a/cmd/workspace/provider-exchange-filters/provider-exchange-filters.go +++ b/cmd/workspace/provider-exchange-filters/provider-exchange-filters.go @@ -3,6 +3,7 @@ package provider_exchange_filters import ( + "context" "errors" "fmt" @@ -18,18 +19,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "provider-exchange-filters", - Short: `Marketplace exchanges filters curate which groups can access an exchange.`, - Long: `Marketplace exchanges filters curate which groups can access an exchange.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "provider-exchange-filters", + Short: `Marketplace exchanges filters curate which groups can access an exchange.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Marketplace exchanges filters curate which groups can access an exchange.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -41,8 +46,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/provider-exchanges/provider-exchanges.go b/cmd/workspace/provider-exchanges/provider-exchanges.go index 79fed15eb8b..b288aec722c 100644 --- a/cmd/workspace/provider-exchanges/provider-exchanges.go +++ b/cmd/workspace/provider-exchanges/provider-exchanges.go @@ -3,6 +3,7 @@ package provider_exchanges import ( + "context" "errors" "fmt" @@ -18,19 +19,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "provider-exchanges", - Short: `Marketplace exchanges allow providers to share their listings with a curated set of customers.`, - Long: `Marketplace exchanges allow providers to share their listings with a curated - set of customers.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "provider-exchanges", + Short: `Marketplace exchanges allow providers to share their listings with a curated set of customers.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Marketplace exchanges allow providers to share their listings with a curated + set of customers.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newAddListingToExchange()) @@ -47,8 +52,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start add-listing-to-exchange command diff --git a/cmd/workspace/provider-files/provider-files.go b/cmd/workspace/provider-files/provider-files.go index aba6c6a49f2..d7b8f0afe8b 100644 --- a/cmd/workspace/provider-files/provider-files.go +++ b/cmd/workspace/provider-files/provider-files.go @@ -3,6 +3,7 @@ package provider_files import ( + "context" "errors" "fmt" @@ -18,19 +19,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "provider-files", - Short: `Marketplace offers a set of file APIs for various purposes such as preview notebooks and provider icons.`, - Long: `Marketplace offers a set of file APIs for various purposes such as preview - notebooks and provider icons.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "provider-files", + Short: `Marketplace offers a set of file APIs for various purposes such as preview notebooks and provider icons.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Marketplace offers a set of file APIs for various purposes such as preview + notebooks and provider icons.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/provider-listings/provider-listings.go b/cmd/workspace/provider-listings/provider-listings.go index badadfaa846..3bab9cdeee7 100644 --- a/cmd/workspace/provider-listings/provider-listings.go +++ b/cmd/workspace/provider-listings/provider-listings.go @@ -3,6 +3,7 @@ package provider_listings import ( + "context" "errors" "fmt" @@ -18,19 +19,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "provider-listings", - Short: `Listings are the core entities in the Marketplace.`, - Long: `Listings are the core entities in the Marketplace. They represent the products - that are available for consumption.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "provider-listings", + Short: `Listings are the core entities in the Marketplace.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Listings are the core entities in the Marketplace. They represent the products + that are available for consumption.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -43,8 +48,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/provider-personalization-requests/provider-personalization-requests.go b/cmd/workspace/provider-personalization-requests/provider-personalization-requests.go index 23ade748e01..57d9521d651 100644 --- a/cmd/workspace/provider-personalization-requests/provider-personalization-requests.go +++ b/cmd/workspace/provider-personalization-requests/provider-personalization-requests.go @@ -3,6 +3,7 @@ package provider_personalization_requests import ( + "context" "errors" "fmt" @@ -18,19 +19,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "provider-personalization-requests", - Short: `Personalization requests are an alternate to instantly available listings.`, - Long: `Personalization requests are an alternate to instantly available listings. - Control the lifecycle of personalized solutions.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "provider-personalization-requests", + Short: `Personalization requests are an alternate to instantly available listings.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Personalization requests are an alternate to instantly available listings. + Control the lifecycle of personalized solutions.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newList()) @@ -40,8 +45,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start list command diff --git a/cmd/workspace/provider-provider-analytics-dashboards/provider-provider-analytics-dashboards.go b/cmd/workspace/provider-provider-analytics-dashboards/provider-provider-analytics-dashboards.go index 7cc971d283c..d42c9b664c6 100644 --- a/cmd/workspace/provider-provider-analytics-dashboards/provider-provider-analytics-dashboards.go +++ b/cmd/workspace/provider-provider-analytics-dashboards/provider-provider-analytics-dashboards.go @@ -3,6 +3,8 @@ package provider_provider_analytics_dashboards import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -15,18 +17,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "provider-provider-analytics-dashboards", - Short: `Manage templated analytics solution for providers.`, - Long: `Manage templated analytics solution for providers.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "provider-provider-analytics-dashboards", + Short: `Manage templated analytics solution for providers.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Manage templated analytics solution for providers.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -38,8 +44,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/provider-providers/provider-providers.go b/cmd/workspace/provider-providers/provider-providers.go index 8b9c94bcaca..c42c5bedae9 100644 --- a/cmd/workspace/provider-providers/provider-providers.go +++ b/cmd/workspace/provider-providers/provider-providers.go @@ -3,6 +3,7 @@ package provider_providers import ( + "context" "errors" "fmt" @@ -18,18 +19,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "provider-providers", - Short: `Providers are entities that manage assets in Marketplace.`, - Long: `Providers are entities that manage assets in Marketplace.`, - GroupID: "marketplace", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "provider-providers", + Short: `Providers are entities that manage assets in Marketplace.`, + GroupID: "marketplace", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Providers are entities that manage assets in Marketplace.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/providers/providers.go b/cmd/workspace/providers/providers.go index 8d234ff712b..6c95001e02f 100644 --- a/cmd/workspace/providers/providers.go +++ b/cmd/workspace/providers/providers.go @@ -3,6 +3,7 @@ package providers import ( + "context" "errors" "fmt" @@ -18,20 +19,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "providers", - Short: `A data provider is an object representing the organization in the real world who shares the data.`, - Long: `A data provider is an object representing the organization in the real world +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "providers", + Short: `A data provider is an object representing the organization in the real world who shares the data.`, + GroupID: "sharing", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A data provider is an object representing the organization in the real world who shares the data. A provider contains shares which further contain the - shared data.`, - GroupID: "sharing", - RunE: root.ReportUnknownSubcommand, - } + shared data.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -46,8 +51,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/quality-monitor-v2/quality-monitor-v2.go b/cmd/workspace/quality-monitor-v2/quality-monitor-v2.go index b9a515c72cb..8c889755472 100644 --- a/cmd/workspace/quality-monitor-v2/quality-monitor-v2.go +++ b/cmd/workspace/quality-monitor-v2/quality-monitor-v2.go @@ -3,6 +3,7 @@ package quality_monitor_v2 import ( + "context" "errors" "fmt" @@ -18,22 +19,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "quality-monitor-v2", - Short: `*Beta* Deprecated: Please use the Data Quality Monitoring API instead (REST: /api/data-quality/v1/monitors).`, - Long: `This command is in Beta and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "quality-monitor-v2", + Short: `*Beta* Deprecated: Please use the Data Quality Monitoring API instead (REST: /api/data-quality/v1/monitors).`, + GroupID: "qualitymonitor", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Beta and may change without notice. Deprecated: Please use the Data Quality Monitoring API instead (REST: /api/data-quality/v1/monitors). Manage data quality of UC objects (currently - support schema).`, - GroupID: "qualitymonitor", - RunE: root.ReportUnknownSubcommand, - } + support schema).` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_BETA" - cmd.Annotations["launch_stage_display"] = "Beta" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_BETA", + "launch_stage_display": "Beta", + } // Add methods cmd.AddCommand(newCreateQualityMonitor()) @@ -46,8 +51,6 @@ Deprecated: Please use the Data Quality Monitoring API instead (REST: for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-quality-monitor command diff --git a/cmd/workspace/quality-monitors/quality-monitors.go b/cmd/workspace/quality-monitors/quality-monitors.go index c8d43ee3b7f..4d795247c9d 100644 --- a/cmd/workspace/quality-monitors/quality-monitors.go +++ b/cmd/workspace/quality-monitors/quality-monitors.go @@ -3,6 +3,7 @@ package quality_monitors import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "quality-monitors", - Short: `Deprecated: Please use the Data Quality Monitors API instead (REST: /api/data-quality/v1/monitors), which manages both Data Profiling and Anomaly Detection.`, - Long: `Deprecated: Please use the Data Quality Monitors API instead (REST: +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "quality-monitors", + Short: `Deprecated: Please use the Data Quality Monitors API instead (REST: /api/data-quality/v1/monitors), which manages both Data Profiling and Anomaly Detection.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Deprecated: Please use the Data Quality Monitors API instead (REST: /api/data-quality/v1/monitors), which manages both Data Profiling and Anomaly Detection. @@ -32,14 +38,13 @@ func New() *cobra.Command { owner of the table (or its parent schema or parent catalog). Viewing the dashboard, computed metrics, or monitor configuration only requires the user to have **SELECT** privileges on the table (along with **USE_SCHEMA** and - **USE_CATALOG**).`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + **USE_CATALOG**).` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCancelRefresh()) @@ -56,8 +61,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start cancel-refresh command diff --git a/cmd/workspace/queries-legacy/queries-legacy.go b/cmd/workspace/queries-legacy/queries-legacy.go index c82909cdca8..2c1c3d3bfbf 100644 --- a/cmd/workspace/queries-legacy/queries-legacy.go +++ b/cmd/workspace/queries-legacy/queries-legacy.go @@ -3,6 +3,7 @@ package queries_legacy import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "queries-legacy", - Short: `These endpoints are used for CRUD operations on query definitions.`, - Long: `These endpoints are used for CRUD operations on query definitions. Query +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "queries-legacy", + Short: `These endpoints are used for CRUD operations on query definitions.`, + GroupID: "sql", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These endpoints are used for CRUD operations on query definitions. Query definitions include the target SQL warehouse, query text, name, description, tags, parameters, and visualizations. Queries can be scheduled using the sql_task type of the Jobs API, e.g. :method:jobs/create. @@ -29,14 +35,13 @@ func New() *cobra.Command { **Warning**: This API is deprecated. Please see the latest version of the Databricks SQL API. [Learn more] - [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html`, - GroupID: "sql", - RunE: root.ReportUnknownSubcommand, - } + [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -50,8 +55,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/queries/queries.go b/cmd/workspace/queries/queries.go index e0eb80cb58c..7d9f0e48f54 100644 --- a/cmd/workspace/queries/queries.go +++ b/cmd/workspace/queries/queries.go @@ -3,6 +3,7 @@ package queries import ( + "context" "errors" "fmt" @@ -18,21 +19,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "queries", - Short: `The queries API can be used to perform CRUD operations on queries.`, - Long: `The queries API can be used to perform CRUD operations on queries. A query is +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "queries", + Short: `The queries API can be used to perform CRUD operations on queries.`, + GroupID: "sql", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The queries API can be used to perform CRUD operations on queries. A query is a Databricks SQL object that includes the target SQL warehouse, query text, name, description, tags, and parameters. Queries can be scheduled using the - sql_task type of the Jobs API, e.g. :method:jobs/create.`, - GroupID: "sql", - RunE: root.ReportUnknownSubcommand, - } + sql_task type of the Jobs API, e.g. :method:jobs/create.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -46,8 +51,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/query-history/query-history.go b/cmd/workspace/query-history/query-history.go index fc9b0a1aa6e..e80516d5d07 100644 --- a/cmd/workspace/query-history/query-history.go +++ b/cmd/workspace/query-history/query-history.go @@ -3,6 +3,8 @@ package query_history import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -14,19 +16,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "query-history", - Short: `A service responsible for storing and retrieving the list of queries run against SQL endpoints and serverless compute.`, - Long: `A service responsible for storing and retrieving the list of queries run - against SQL endpoints and serverless compute.`, - GroupID: "sql", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "query-history", + Short: `A service responsible for storing and retrieving the list of queries run against SQL endpoints and serverless compute.`, + GroupID: "sql", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A service responsible for storing and retrieving the list of queries run + against SQL endpoints and serverless compute.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newList()) @@ -35,8 +41,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start list command diff --git a/cmd/workspace/query-visualizations-legacy/query-visualizations-legacy.go b/cmd/workspace/query-visualizations-legacy/query-visualizations-legacy.go index 59a1594c7bf..070b32164e8 100644 --- a/cmd/workspace/query-visualizations-legacy/query-visualizations-legacy.go +++ b/cmd/workspace/query-visualizations-legacy/query-visualizations-legacy.go @@ -3,6 +3,7 @@ package query_visualizations_legacy import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,29 +18,33 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "query-visualizations-legacy", - Short: `This is an evolving API that facilitates the addition and removal of visualizations from existing queries within the Databricks Workspace.`, - Long: `This is an evolving API that facilitates the addition and removal of +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "query-visualizations-legacy", + Short: `This is an evolving API that facilitates the addition and removal of visualizations from existing queries within the Databricks Workspace.`, + GroupID: "sql", + + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This is an evolving API that facilitates the addition and removal of visualizations from existing queries within the Databricks Workspace. Data structures may change over time. **Warning**: This API is deprecated. Please see the latest version of the Databricks SQL API. [Learn more] - [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html`, - GroupID: "sql", + [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html` + cmd.RunE = root.ReportUnknownSubcommand - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", } - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" - // Add methods cmd.AddCommand(newCreate()) cmd.AddCommand(newDelete()) @@ -49,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/query-visualizations/query-visualizations.go b/cmd/workspace/query-visualizations/query-visualizations.go index 4e2b50c8687..3218092f4bd 100644 --- a/cmd/workspace/query-visualizations/query-visualizations.go +++ b/cmd/workspace/query-visualizations/query-visualizations.go @@ -3,6 +3,7 @@ package query_visualizations import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,24 +18,28 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "query-visualizations", - Short: `This is an evolving API that facilitates the addition and removal of visualizations from existing queries in the Databricks Workspace.`, - Long: `This is an evolving API that facilitates the addition and removal of +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "query-visualizations", + Short: `This is an evolving API that facilitates the addition and removal of visualizations from existing queries in the Databricks Workspace.`, + GroupID: "sql", + + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This is an evolving API that facilitates the addition and removal of visualizations from existing queries in the Databricks Workspace. Data - structures can change over time.`, - GroupID: "sql", + structures can change over time.` + cmd.RunE = root.ReportUnknownSubcommand - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", } - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" - // Add methods cmd.AddCommand(newCreate()) cmd.AddCommand(newDelete()) @@ -44,8 +49,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/recipient-activation/recipient-activation.go b/cmd/workspace/recipient-activation/recipient-activation.go index 0260cd5785f..06a0503af5e 100644 --- a/cmd/workspace/recipient-activation/recipient-activation.go +++ b/cmd/workspace/recipient-activation/recipient-activation.go @@ -3,6 +3,8 @@ package recipient_activation import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -14,11 +16,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "recipient-activation", - Short: `The Recipient Activation API is only applicable in the open sharing model where the recipient object has the authentication type of TOKEN.`, - Long: `The Recipient Activation API is only applicable in the open sharing model +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "recipient-activation", + Short: `The Recipient Activation API is only applicable in the open sharing model where the recipient object has the authentication type of TOKEN.`, + GroupID: "sharing", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Recipient Activation API is only applicable in the open sharing model where the recipient object has the authentication type of TOKEN. The data recipient follows the activation link shared by the data provider to download the credential file that includes the access token. The recipient will then @@ -27,14 +34,13 @@ func New() *cobra.Command { Note that you can download the credential file only once. Recipients should treat the downloaded credential as a secret and must not share it outside of - their organization.`, - GroupID: "sharing", - RunE: root.ReportUnknownSubcommand, - } + their organization.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGetActivationUrlInfo()) @@ -44,8 +50,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-activation-url-info command diff --git a/cmd/workspace/recipient-federation-policies/recipient-federation-policies.go b/cmd/workspace/recipient-federation-policies/recipient-federation-policies.go index 8da45672e62..78486e2f8df 100644 --- a/cmd/workspace/recipient-federation-policies/recipient-federation-policies.go +++ b/cmd/workspace/recipient-federation-policies/recipient-federation-policies.go @@ -3,6 +3,7 @@ package recipient_federation_policies import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "recipient-federation-policies", - Short: `*Public Preview* The Recipient Federation Policies APIs are only applicable in the open sharing model where the recipient object has the authentication type of OIDC_RECIPIENT, enabling data sharing from Databricks to non-Databricks recipients.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "recipient-federation-policies", + Short: `*Public Preview* The Recipient Federation Policies APIs are only applicable in the open sharing model where the recipient object has the authentication type of OIDC_RECIPIENT, enabling data sharing from Databricks to non-Databricks recipients.`, + GroupID: "sharing", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. The Recipient Federation Policies APIs are only applicable in the open sharing model where the recipient object has the authentication type of @@ -47,14 +53,13 @@ The Recipient Federation Policies APIs are only applicable in the open sharing For more information, see https://www.databricks.com/blog/announcing-oidc-token-federation-enhanced-delta-sharing-security - and https://docs.databricks.com/en/delta-sharing/create-recipient-oidc-fed`, - GroupID: "sharing", - RunE: root.ReportUnknownSubcommand, - } + and https://docs.databricks.com/en/delta-sharing/create-recipient-oidc-fed` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreate()) @@ -66,8 +71,6 @@ The Recipient Federation Policies APIs are only applicable in the open sharing for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/recipients/recipients.go b/cmd/workspace/recipients/recipients.go index ca02fb4d904..608d4093983 100644 --- a/cmd/workspace/recipients/recipients.go +++ b/cmd/workspace/recipients/recipients.go @@ -3,6 +3,7 @@ package recipients import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "recipients", - Short: `A recipient is an object you create using :method:recipients/create to represent an organization which you want to allow access shares.`, - Long: `A recipient is an object you create using :method:recipients/create to +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "recipients", + Short: `A recipient is an object you create using :method:recipients/create to represent an organization which you want to allow access shares.`, + GroupID: "sharing", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A recipient is an object you create using :method:recipients/create to represent an organization which you want to allow access shares. The way how sharing works differs depending on whether or not your recipient has access to a Databricks workspace that is enabled for Unity Catalog: @@ -38,14 +44,13 @@ func New() *cobra.Command { activation link you can send to the recipient. The recipient follows the activation link to download the credential file, and then uses the credential file to establish a secure connection to receive the shared data. This sharing - mode is called **open sharing**.`, - GroupID: "sharing", - RunE: root.ReportUnknownSubcommand, - } + mode is called **open sharing**.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -60,8 +65,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/redash-config/redash-config.go b/cmd/workspace/redash-config/redash-config.go index 5497537c8a7..7e85335e4c4 100644 --- a/cmd/workspace/redash-config/redash-config.go +++ b/cmd/workspace/redash-config/redash-config.go @@ -3,6 +3,8 @@ package redash_config import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -13,21 +15,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "redash-config", - Short: `Redash V2 service for workspace configurations (internal).`, - Long: `Redash V2 service for workspace configurations (internal)`, - GroupID: "sql", +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "redash-config", + Short: `Redash V2 service for workspace configurations (internal).`, + GroupID: "sql", - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Redash V2 service for workspace configurations (internal)` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newGetConfig()) @@ -36,8 +42,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-config command diff --git a/cmd/workspace/registered-models/registered-models.go b/cmd/workspace/registered-models/registered-models.go index 43e7acccda1..d56c0ecd54b 100644 --- a/cmd/workspace/registered-models/registered-models.go +++ b/cmd/workspace/registered-models/registered-models.go @@ -3,6 +3,7 @@ package registered_models import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "registered-models", - Short: `Databricks provides a hosted version of MLflow Model Registry in Unity Catalog.`, - Long: `Databricks provides a hosted version of MLflow Model Registry in Unity +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "registered-models", + Short: `Databricks provides a hosted version of MLflow Model Registry in Unity Catalog.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Databricks provides a hosted version of MLflow Model Registry in Unity Catalog. Models in Unity Catalog provide centralized access control, auditing, lineage, and discovery of ML models across Databricks workspaces. @@ -50,14 +56,13 @@ func New() *cobra.Command { Note: The securable type for models is FUNCTION. When using REST APIs (for example, tagging, grants) that specify a securable type, use FUNCTION as the - securable type.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + securable type.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -72,8 +77,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/repos/repos.go b/cmd/workspace/repos/repos.go index ba5d95363fe..a5337acb10f 100644 --- a/cmd/workspace/repos/repos.go +++ b/cmd/workspace/repos/repos.go @@ -3,6 +3,7 @@ package repos import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "repos", - Short: `The Repos API allows users to manage their git repos.`, - Long: `The Repos API allows users to manage their git repos. Users can use the API to +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "repos", + Short: `The Repos API allows users to manage their git repos.`, + GroupID: "workspace", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Repos API allows users to manage their git repos. Users can use the API to access all repos that they have manage permissions on. Databricks Repos is a visual Git client in Databricks. It supports common Git @@ -31,14 +37,13 @@ func New() *cobra.Command { Within Repos you can develop code in notebooks or other files and follow data science and engineering code development best practices using Git for version - control, collaboration, and CI/CD.`, - GroupID: "workspace", - RunE: root.ReportUnknownSubcommand, - } + control, collaboration, and CI/CD.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -55,8 +60,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/resource-quotas/resource-quotas.go b/cmd/workspace/resource-quotas/resource-quotas.go index b58233280e4..163662ae7f7 100644 --- a/cmd/workspace/resource-quotas/resource-quotas.go +++ b/cmd/workspace/resource-quotas/resource-quotas.go @@ -3,6 +3,7 @@ package resource_quotas import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -16,25 +17,29 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "resource-quotas", - Short: `Unity Catalog enforces resource quotas on all securable objects, which limits the number of resources that can be created.`, - Long: `Unity Catalog enforces resource quotas on all securable objects, which limits +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "resource-quotas", + Short: `Unity Catalog enforces resource quotas on all securable objects, which limits the number of resources that can be created.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Unity Catalog enforces resource quotas on all securable objects, which limits the number of resources that can be created. Quotas are expressed in terms of a resource type and a parent (for example, tables per metastore or schemas per catalog). The resource quota APIs enable you to monitor your current usage and limits. For more information on resource quotas see the [Unity Catalog documentation]. - [Unity Catalog documentation]: https://docs.databricks.com/en/data-governance/unity-catalog/index.html#resource-quotas`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + [Unity Catalog documentation]: https://docs.databricks.com/en/data-governance/unity-catalog/index.html#resource-quotas` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGetQuota()) @@ -44,8 +49,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-quota command diff --git a/cmd/workspace/restrict-workspace-admins/restrict-workspace-admins.go b/cmd/workspace/restrict-workspace-admins/restrict-workspace-admins.go index ca07a765514..8b7a602577c 100644 --- a/cmd/workspace/restrict-workspace-admins/restrict-workspace-admins.go +++ b/cmd/workspace/restrict-workspace-admins/restrict-workspace-admins.go @@ -3,6 +3,7 @@ package restrict_workspace_admins import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,15 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "restrict-workspace-admins", - Short: `*Public Preview* The Restrict Workspace Admins setting lets you control the capabilities of workspace admins.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "restrict-workspace-admins", + Short: `*Public Preview* The Restrict Workspace Admins setting lets you control the capabilities of workspace admins.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. The Restrict Workspace Admins setting lets you control the capabilities of workspace admins. With the setting status set to ALLOW_ALL, workspace admins @@ -34,13 +39,13 @@ The Restrict Workspace Admins setting lets you control the capabilities of access tokens on behalf of service principals they have the Service Principal User role on. They can also only change a job owner to themselves. And they can change the job run_as setting to themselves or to a service principal on - which they have the Service Principal User role.`, - RunE: root.ReportUnknownSubcommand, - } + which they have the Service Principal User role.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newDelete()) @@ -51,8 +56,6 @@ The Restrict Workspace Admins setting lets you control the capabilities of for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/rfa/rfa.go b/cmd/workspace/rfa/rfa.go index 75bfec74dd4..a37a4dd5f57 100644 --- a/cmd/workspace/rfa/rfa.go +++ b/cmd/workspace/rfa/rfa.go @@ -3,6 +3,7 @@ package rfa import ( + "context" "errors" "fmt" @@ -18,24 +19,28 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "rfa", - Short: `*Public Preview* Request for Access enables users to request access for Unity Catalog securables.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "rfa", + Short: `*Public Preview* Request for Access enables users to request access for Unity Catalog securables.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Request for Access enables users to request access for Unity Catalog securables. These APIs provide a standardized way for securable owners (or users with - MANAGE privileges) to manage access request destinations.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + MANAGE privileges) to manage access request destinations.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newBatchCreateAccessRequests()) @@ -46,8 +51,6 @@ Request for Access enables users to request access for Unity Catalog for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start batch-create-access-requests command diff --git a/cmd/workspace/sandbox/sandbox.go b/cmd/workspace/sandbox/sandbox.go index ba622937ff2..9c41c695843 100644 --- a/cmd/workspace/sandbox/sandbox.go +++ b/cmd/workspace/sandbox/sandbox.go @@ -3,6 +3,7 @@ package sandbox import ( + "context" "encoding/json" "errors" "fmt" @@ -22,21 +23,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "sandbox", - Short: `*Beta* Create, manage, and control the lifecycle of sandboxes -- isolated, pre-configured, low-latency Serverless compute environments for running code.`, - Long: `This command is in Beta and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "sandbox", + Short: `*Beta* Create, manage, and control the lifecycle of sandboxes -- isolated, pre-configured, low-latency Serverless compute environments for running code.`, + GroupID: "sandbox", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Beta and may change without notice. Create, manage, and control the lifecycle of sandboxes -- isolated, - pre-configured, low-latency Serverless compute environments for running code.`, - GroupID: "sandbox", - RunE: root.ReportUnknownSubcommand, - } + pre-configured, low-latency Serverless compute environments for running code.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_BETA" - cmd.Annotations["launch_stage_display"] = "Beta" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_BETA", + "launch_stage_display": "Beta", + } // Add methods cmd.AddCommand(newCreateDirectory()) @@ -59,8 +64,6 @@ Create, manage, and control the lifecycle of sandboxes -- isolated, for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-directory command diff --git a/cmd/workspace/schemas/schemas.go b/cmd/workspace/schemas/schemas.go index 709452cd3a9..c6aebf2c4ce 100644 --- a/cmd/workspace/schemas/schemas.go +++ b/cmd/workspace/schemas/schemas.go @@ -3,6 +3,7 @@ package schemas import ( + "context" "errors" "fmt" @@ -18,22 +19,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "schemas", - Short: `A schema (also called a database) is the second layer of Unity Catalog’s three-level namespace.`, - Long: `A schema (also called a database) is the second layer of Unity Catalog’s +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "schemas", + Short: `A schema (also called a database) is the second layer of Unity Catalog’s three-level namespace.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A schema (also called a database) is the second layer of Unity Catalog’s three-level namespace. A schema organizes tables, views, and functions. To access (or list) a table or view in a schema, users must have the USE_SCHEMA data permission on the schema and its parent catalog, and they must have the - SELECT permission on the table or view.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + SELECT permission on the table or view.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -46,8 +51,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/secrets-uc/secrets-uc.go b/cmd/workspace/secrets-uc/secrets-uc.go index d2609bc1d86..190cce23fd0 100644 --- a/cmd/workspace/secrets-uc/secrets-uc.go +++ b/cmd/workspace/secrets-uc/secrets-uc.go @@ -3,6 +3,7 @@ package secrets_uc import ( + "context" "encoding/json" "errors" "fmt" @@ -22,23 +23,27 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "secrets-uc", - Short: `A secret is a Unity Catalog securable object that stores sensitive credential data (such as passwords, tokens, and keys) within a three-level namespace (**catalog_name.schema_name.secret_name**).`, - Long: `A secret is a Unity Catalog securable object that stores sensitive credential +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "secrets-uc", + Short: `A secret is a Unity Catalog securable object that stores sensitive credential data (such as passwords, tokens, and keys) within a three-level namespace (**catalog_name.schema_name.secret_name**).`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A secret is a Unity Catalog securable object that stores sensitive credential data (such as passwords, tokens, and keys) within a three-level namespace (**catalog_name.schema_name.secret_name**). Secrets can be managed using standard Unity Catalog permissions and are scoped - to a schema within a catalog.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + to a schema within a catalog.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateSecret()) @@ -51,8 +56,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-secret command diff --git a/cmd/workspace/secrets/secrets.go b/cmd/workspace/secrets/secrets.go index e3268ccfe6e..6519d7d49b6 100644 --- a/cmd/workspace/secrets/secrets.go +++ b/cmd/workspace/secrets/secrets.go @@ -3,6 +3,7 @@ package secrets import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "secrets", - Short: `The Secrets API allows you to manage secrets, secret scopes, and access permissions.`, - Long: `The Secrets API allows you to manage secrets, secret scopes, and access +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "secrets", + Short: `The Secrets API allows you to manage secrets, secret scopes, and access permissions.`, + GroupID: "workspace", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Secrets API allows you to manage secrets, secret scopes, and access permissions. Sometimes accessing data requires that you authenticate to external data @@ -33,14 +39,13 @@ func New() *cobra.Command { Administrators, secret creators, and users granted permission can read Databricks secrets. While Databricks makes an effort to redact secret values that might be displayed in notebooks, it is not possible to prevent such users - from reading secrets.`, - GroupID: "workspace", - RunE: root.ReportUnknownSubcommand, - } + from reading secrets.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateScope()) @@ -58,8 +63,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-scope command diff --git a/cmd/workspace/serverless-compute-service/serverless-compute-service.go b/cmd/workspace/serverless-compute-service/serverless-compute-service.go index 09789adec60..f0a3cf26ed6 100644 --- a/cmd/workspace/serverless-compute-service/serverless-compute-service.go +++ b/cmd/workspace/serverless-compute-service/serverless-compute-service.go @@ -3,6 +3,7 @@ package serverless_compute_service import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -16,21 +17,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "serverless-compute-service", - Short: `ServerlessCompute Service API.`, - Long: `ServerlessCompute Service API.`, - GroupID: "compute", +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "serverless-compute-service", + Short: `ServerlessCompute Service API.`, + GroupID: "compute", - // This service is being previewed; hide from help output. - Hidden: true, - RunE: root.ReportUnknownSubcommand, - } + // This service is being previewed; hide from help output. + Hidden: true, + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Private Preview" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `ServerlessCompute Service API.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PRIVATE_PREVIEW", + "launch_stage_display": "Private Preview", + } // Add methods cmd.AddCommand(newList()) @@ -40,8 +45,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start list command diff --git a/cmd/workspace/service-principal-secrets-proxy/service-principal-secrets-proxy.go b/cmd/workspace/service-principal-secrets-proxy/service-principal-secrets-proxy.go index 38f75b98bef..80fc3461d95 100644 --- a/cmd/workspace/service-principal-secrets-proxy/service-principal-secrets-proxy.go +++ b/cmd/workspace/service-principal-secrets-proxy/service-principal-secrets-proxy.go @@ -3,6 +3,7 @@ package service_principal_secrets_proxy import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "service-principal-secrets-proxy", - Short: `These APIs enable administrators to manage service principal secrets at the workspace level.`, - Long: `These APIs enable administrators to manage service principal secrets at the +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "service-principal-secrets-proxy", + Short: `These APIs enable administrators to manage service principal secrets at the workspace level.`, + GroupID: "oauth2", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs enable administrators to manage service principal secrets at the workspace level. To use these APIs, the service principal must be first added to the current workspace. @@ -35,14 +41,13 @@ func New() *cobra.Command { information, see [Databricks Terraform Provider]. [Authentication using OAuth tokens for service principals]: https://docs.databricks.com/dev-tools/authentication-oauth.html - [Databricks Terraform Provider]: https://github.com/databricks/terraform-provider-databricks/blob/master/docs/index.md#authenticating-with-service-principal`, - GroupID: "oauth2", - RunE: root.ReportUnknownSubcommand, - } + [Databricks Terraform Provider]: https://github.com/databricks/terraform-provider-databricks/blob/master/docs/index.md#authenticating-with-service-principal` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -53,8 +58,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/service-principals-v2/service-principals-v2.go b/cmd/workspace/service-principals-v2/service-principals-v2.go index 2bce2b79cbf..a97ff2de012 100644 --- a/cmd/workspace/service-principals-v2/service-principals-v2.go +++ b/cmd/workspace/service-principals-v2/service-principals-v2.go @@ -3,6 +3,7 @@ package service_principals_v2 import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,25 +18,29 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "service-principals-v2", - Short: `*Public Preview* Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "service-principals-v2", + Short: `*Public Preview* Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms. Databricks recommends creating service principals to run production jobs or modify production data. If all processes that act on production data run with service principals, interactive users do not need any write, delete, or modify privileges in production. This eliminates the risk of - a user overwriting production data by accident.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } + a user overwriting production data by accident.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreate()) @@ -49,8 +54,6 @@ Identities for use with jobs, automated tools, and systems such as scripts, for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/service-principals/service-principals.go b/cmd/workspace/service-principals/service-principals.go index 76737b45176..7df528f70f9 100755 --- a/cmd/workspace/service-principals/service-principals.go +++ b/cmd/workspace/service-principals/service-principals.go @@ -6,6 +6,7 @@ package service_principals import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -20,22 +21,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "service-principals", - Short: `Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms.`, - Long: `Identities for use with jobs, automated tools, and systems such as scripts, +// Spec declares the service-principals command. +var Spec = root.CommandSpec{ + Use: "service-principals", + Short: `Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Annotations = map[string]string{ + "package": "iam", + } + cmd.Long = `Identities for use with jobs, automated tools, and systems such as scripts, apps, and CI/CD platforms. Databricks recommends creating service principals to run production jobs or modify production data. If all processes that act on production data run with service principals, interactive users do not need any write, delete, or modify privileges in production. This eliminates the risk of - a user overwriting production data by accident.`, - GroupID: "iam", - Annotations: map[string]string{ - "package": "iam", - }, - RunE: root.ReportUnknownSubcommand, - } + a user overwriting production data by accident.` + cmd.RunE = root.ReportUnknownSubcommand // Add methods cmd.AddCommand(newCreate()) @@ -49,8 +53,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/serving-endpoints/serving-endpoints.go b/cmd/workspace/serving-endpoints/serving-endpoints.go index 7c837c5d2dd..94eb6dfe2ee 100644 --- a/cmd/workspace/serving-endpoints/serving-endpoints.go +++ b/cmd/workspace/serving-endpoints/serving-endpoints.go @@ -3,6 +3,7 @@ package serving_endpoints import ( + "context" "errors" "fmt" "time" @@ -19,11 +20,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "serving-endpoints", - Short: `The Serving Endpoints API allows you to create, update, and delete model serving endpoints.`, - Long: `The Serving Endpoints API allows you to create, update, and delete model +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "serving-endpoints", + Short: `The Serving Endpoints API allows you to create, update, and delete model serving endpoints.`, + GroupID: "serving", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Serving Endpoints API allows you to create, update, and delete model serving endpoints. You can use a serving endpoint to serve models from the Databricks Model @@ -35,14 +41,13 @@ func New() *cobra.Command { serving endpoint can have at most ten served entities. You can configure traffic settings to define how requests should be routed to your served entities behind an endpoint. Additionally, you can configure the scale of - resources that should be applied to each served entity.`, - GroupID: "serving", - RunE: root.ReportUnknownSubcommand, - } + resources that should be applied to each served entity.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newBuildLogs()) @@ -72,8 +77,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start build-logs command diff --git a/cmd/workspace/settings/settings.go b/cmd/workspace/settings/settings.go index 8518f522dd8..2110242ed0a 100644 --- a/cmd/workspace/settings/settings.go +++ b/cmd/workspace/settings/settings.go @@ -3,6 +3,8 @@ package settings import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/spf13/cobra" @@ -28,43 +30,45 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "settings", - Short: `Workspace Settings API allows users to manage settings at the workspace level.`, - Long: `Workspace Settings API allows users to manage settings at the workspace level.`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "settings", + Short: `Workspace Settings API allows users to manage settings at the workspace level.`, + GroupID: "settings", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Workspace Settings API allows users to manage settings at the workspace level.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add subservices - cmd.AddCommand(aibi_dashboard_embedding_access_policy.New()) - cmd.AddCommand(aibi_dashboard_embedding_approved_domains.New()) - cmd.AddCommand(automatic_cluster_update.New()) - cmd.AddCommand(compliance_security_profile.New()) - cmd.AddCommand(dashboard_email_subscriptions.New()) - cmd.AddCommand(default_namespace.New()) - cmd.AddCommand(default_warehouse_id.New()) - cmd.AddCommand(disable_legacy_access.New()) - cmd.AddCommand(disable_legacy_dbfs.New()) - cmd.AddCommand(enable_export_notebook.New()) - cmd.AddCommand(enable_notebook_table_clipboard.New()) - cmd.AddCommand(enable_results_downloading.New()) - cmd.AddCommand(enhanced_security_monitoring.New()) - cmd.AddCommand(llm_proxy_partner_powered_workspace.New()) - cmd.AddCommand(restrict_workspace_admins.New()) - cmd.AddCommand(sql_results_download.New()) + cmd.AddCommand(root.NewCommand(ctx, aibi_dashboard_embedding_access_policy.Spec)) + cmd.AddCommand(root.NewCommand(ctx, aibi_dashboard_embedding_approved_domains.Spec)) + cmd.AddCommand(root.NewCommand(ctx, automatic_cluster_update.Spec)) + cmd.AddCommand(root.NewCommand(ctx, compliance_security_profile.Spec)) + cmd.AddCommand(root.NewCommand(ctx, dashboard_email_subscriptions.Spec)) + cmd.AddCommand(root.NewCommand(ctx, default_namespace.Spec)) + cmd.AddCommand(root.NewCommand(ctx, default_warehouse_id.Spec)) + cmd.AddCommand(root.NewCommand(ctx, disable_legacy_access.Spec)) + cmd.AddCommand(root.NewCommand(ctx, disable_legacy_dbfs.Spec)) + cmd.AddCommand(root.NewCommand(ctx, enable_export_notebook.Spec)) + cmd.AddCommand(root.NewCommand(ctx, enable_notebook_table_clipboard.Spec)) + cmd.AddCommand(root.NewCommand(ctx, enable_results_downloading.Spec)) + cmd.AddCommand(root.NewCommand(ctx, enhanced_security_monitoring.Spec)) + cmd.AddCommand(root.NewCommand(ctx, llm_proxy_partner_powered_workspace.Spec)) + cmd.AddCommand(root.NewCommand(ctx, restrict_workspace_admins.Spec)) + cmd.AddCommand(root.NewCommand(ctx, sql_results_download.Spec)) // Apply optional overrides to this command. for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // end service Settings diff --git a/cmd/workspace/shares/shares.go b/cmd/workspace/shares/shares.go index 4f3869ae300..2499d16febb 100644 --- a/cmd/workspace/shares/shares.go +++ b/cmd/workspace/shares/shares.go @@ -3,6 +3,7 @@ package shares import ( + "context" "errors" "fmt" @@ -18,22 +19,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "shares", - Short: `A share is a container instantiated with :method:shares/create.`, - Long: `A share is a container instantiated with :method:shares/create. Once created +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "shares", + Short: `A share is a container instantiated with :method:shares/create.`, + GroupID: "sharing", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A share is a container instantiated with :method:shares/create. Once created you can iteratively register a collection of existing data assets defined within the metastore using :method:shares/update. You can register data assets under their original name, qualified by their original schema, or provide - alternate exposed names.`, - GroupID: "sharing", - RunE: root.ReportUnknownSubcommand, - } + alternate exposed names.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -48,8 +53,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/software-artifacts/software-artifacts.go b/cmd/workspace/software-artifacts/software-artifacts.go index 9ec65dac88c..f5fd0c000e9 100644 --- a/cmd/workspace/software-artifacts/software-artifacts.go +++ b/cmd/workspace/software-artifacts/software-artifacts.go @@ -3,6 +3,7 @@ package software_artifacts import ( + "context" "errors" "fmt" "strings" @@ -20,20 +21,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "software-artifacts", - Short: `*Beta* Manage software artifacts and their versions in Unity Catalog.`, - Long: `This command is in Beta and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "software-artifacts", + Short: `*Beta* Manage software artifacts and their versions in Unity Catalog.`, + GroupID: "catalog", + Build: buildCommand, +} -Manage software artifacts and their versions in Unity Catalog.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Beta and may change without notice. - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_BETA" - cmd.Annotations["launch_stage_display"] = "Beta" +Manage software artifacts and their versions in Unity Catalog.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_BETA", + "launch_stage_display": "Beta", + } // Add methods cmd.AddCommand(newGetSoftwareArtifact()) @@ -47,8 +52,6 @@ Manage software artifacts and their versions in Unity Catalog.`, for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-software-artifact command diff --git a/cmd/workspace/sql-results-download/sql-results-download.go b/cmd/workspace/sql-results-download/sql-results-download.go index 84e177a4b8b..0f18de696e4 100644 --- a/cmd/workspace/sql-results-download/sql-results-download.go +++ b/cmd/workspace/sql-results-download/sql-results-download.go @@ -3,6 +3,7 @@ package sql_results_download import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,21 +18,25 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "sql-results-download", - Short: `*Public Preview* Controls whether users within the workspace are allowed to download results from the SQL Editor and AI/BI Dashboards UIs.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "sql-results-download", + Short: `*Public Preview* Controls whether users within the workspace are allowed to download results from the SQL Editor and AI/BI Dashboards UIs.`, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Controls whether users within the workspace are allowed to download results from the SQL Editor and AI/BI Dashboards UIs. By default, this setting is - enabled (set to true)`, - RunE: root.ReportUnknownSubcommand, - } + enabled (set to true)` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newDelete()) @@ -42,8 +47,6 @@ Controls whether users within the workspace are allowed to download results for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/cmd/workspace/storage-credentials/storage-credentials.go b/cmd/workspace/storage-credentials/storage-credentials.go index 0a6133b1afd..5024e0c24ba 100644 --- a/cmd/workspace/storage-credentials/storage-credentials.go +++ b/cmd/workspace/storage-credentials/storage-credentials.go @@ -3,6 +3,7 @@ package storage_credentials import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "storage-credentials", - Short: `A storage credential represents an authentication and authorization mechanism for accessing data stored on your cloud tenant.`, - Long: `A storage credential represents an authentication and authorization mechanism +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "storage-credentials", + Short: `A storage credential represents an authentication and authorization mechanism for accessing data stored on your cloud tenant.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A storage credential represents an authentication and authorization mechanism for accessing data stored on your cloud tenant. Each storage credential is subject to Unity Catalog access-control policies that control which users and groups can access the credential. If a user does not have access to a storage @@ -34,14 +40,13 @@ func New() *cobra.Command { To create storage credentials, you must be a Databricks account admin. The account admin who creates the storage credential can delegate ownership to - another user or group to manage permissions on it.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + another user or group to manage permissions on it.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -55,8 +60,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/supervisor-agents/supervisor-agents.go b/cmd/workspace/supervisor-agents/supervisor-agents.go index 491beca6b78..1adc62f73d3 100644 --- a/cmd/workspace/supervisor-agents/supervisor-agents.go +++ b/cmd/workspace/supervisor-agents/supervisor-agents.go @@ -3,6 +3,7 @@ package supervisor_agents import ( + "context" "errors" "fmt" "strings" @@ -20,20 +21,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "supervisor-agents", - Short: `*Beta* Manage legacy Supervisor Agents and related resources.`, - Long: `This command is in Beta and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "supervisor-agents", + Short: `*Beta* Manage legacy Supervisor Agents and related resources.`, + GroupID: "agentbricks", + Build: buildCommand, +} -Manage legacy Supervisor Agents and related resources.`, - GroupID: "agentbricks", - RunE: root.ReportUnknownSubcommand, - } +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Beta and may change without notice. - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_BETA" - cmd.Annotations["launch_stage_display"] = "Beta" +Manage legacy Supervisor Agents and related resources.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_BETA", + "launch_stage_display": "Beta", + } // Add methods cmd.AddCommand(newCreateExample()) @@ -60,8 +65,6 @@ Manage legacy Supervisor Agents and related resources.`, for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-example command diff --git a/cmd/workspace/system-schemas/system-schemas.go b/cmd/workspace/system-schemas/system-schemas.go index f29cd30a16d..438587a6740 100644 --- a/cmd/workspace/system-schemas/system-schemas.go +++ b/cmd/workspace/system-schemas/system-schemas.go @@ -3,6 +3,7 @@ package system_schemas import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,22 +18,26 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "system-schemas", - Short: `*Public Preview* A system schema is a schema that lives within the system catalog.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "system-schemas", + Short: `*Public Preview* A system schema is a schema that lives within the system catalog.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. A system schema is a schema that lives within the system catalog. A system schema may contain information about customer usage of Unity Catalog such as - audit logs, billing logs, and lineage information.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + audit logs, billing logs, and lineage information.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newDisable()) @@ -43,8 +48,6 @@ A system schema is a schema that lives within the system catalog. A system for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start disable command diff --git a/cmd/workspace/table-constraints/table-constraints.go b/cmd/workspace/table-constraints/table-constraints.go index 021cd317763..43b381b7153 100644 --- a/cmd/workspace/table-constraints/table-constraints.go +++ b/cmd/workspace/table-constraints/table-constraints.go @@ -3,6 +3,7 @@ package table_constraints import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "table-constraints", - Short: `Primary key and foreign key constraints encode relationships between fields in tables.`, - Long: `Primary key and foreign key constraints encode relationships between fields in +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "table-constraints", + Short: `Primary key and foreign key constraints encode relationships between fields in tables.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Primary key and foreign key constraints encode relationships between fields in tables. Primary and foreign keys are informational only and are not enforced. Foreign @@ -34,14 +40,13 @@ func New() *cobra.Command { You can declare primary keys and foreign keys as part of the table specification during table creation. You can also add or drop constraints on - existing tables.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + existing tables.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -51,8 +56,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/tables/tables.go b/cmd/workspace/tables/tables.go index 38a13f87171..60445f0bbe1 100644 --- a/cmd/workspace/tables/tables.go +++ b/cmd/workspace/tables/tables.go @@ -3,6 +3,7 @@ package tables import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "tables", - Short: `A table resides in the third layer of Unity Catalog’s three-level namespace.`, - Long: `A table resides in the third layer of Unity Catalog’s three-level namespace. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "tables", + Short: `A table resides in the third layer of Unity Catalog’s three-level namespace.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A table resides in the third layer of Unity Catalog’s three-level namespace. It contains rows of data. To create a table, users must have CREATE_TABLE and USE_SCHEMA permissions on the schema, and they must have the USE_CATALOG permission on its parent catalog. To query a table, users must have the SELECT @@ -30,14 +36,13 @@ func New() *cobra.Command { parent catalog and the USE_SCHEMA permission on its parent schema. A table can be managed or external. From an API perspective, a __VIEW__ is a - particular kind of table (rather than a managed or external table).`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + particular kind of table (rather than a managed or external table).` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -52,8 +57,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/tag-policies/tag-policies.go b/cmd/workspace/tag-policies/tag-policies.go index 82c31bd1fb4..92e2371dbbf 100644 --- a/cmd/workspace/tag-policies/tag-policies.go +++ b/cmd/workspace/tag-policies/tag-policies.go @@ -3,6 +3,7 @@ package tag_policies import ( + "context" "errors" "fmt" @@ -18,24 +19,28 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "tag-policies", - Short: `The Tag Policy API allows you to manage policies for governed tags in Databricks.`, - Long: `The Tag Policy API allows you to manage policies for governed tags in +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "tag-policies", + Short: `The Tag Policy API allows you to manage policies for governed tags in Databricks.`, + GroupID: "tags", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Tag Policy API allows you to manage policies for governed tags in Databricks. For Terraform usage, see the [Tag Policy Terraform documentation]. Permissions for tag policies can be managed using the [Account Access Control Proxy API]. [Account Access Control Proxy API]: https://docs.databricks.com/api/workspace/accountaccesscontrolproxy - [Tag Policy Terraform documentation]: https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/tag_policy`, - GroupID: "tags", - RunE: root.ReportUnknownSubcommand, - } + [Tag Policy Terraform documentation]: https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/tag_policy` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateTagPolicy()) @@ -48,8 +53,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-tag-policy command diff --git a/cmd/workspace/temporary-path-credentials/temporary-path-credentials.go b/cmd/workspace/temporary-path-credentials/temporary-path-credentials.go index aae3cdd0d0d..61eea6fe2e1 100644 --- a/cmd/workspace/temporary-path-credentials/temporary-path-credentials.go +++ b/cmd/workspace/temporary-path-credentials/temporary-path-credentials.go @@ -3,6 +3,7 @@ package temporary_path_credentials import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "temporary-path-credentials", - Short: `Temporary Path Credentials are short-lived, downscoped credentials used to access external cloud storage locations registered in Databricks.`, - Long: `Temporary Path Credentials are short-lived, downscoped credentials used to +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "temporary-path-credentials", + Short: `Temporary Path Credentials are short-lived, downscoped credentials used to access external cloud storage locations registered in Databricks.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Temporary Path Credentials are short-lived, downscoped credentials used to access external cloud storage locations registered in Databricks. These credentials provide secure and time-limited access to data in cloud environments such as AWS, Azure, and Google Cloud. Each cloud provider has its @@ -46,14 +52,13 @@ func New() *cobra.Command { EXTERNAL USE LOCATION is an external location level permission that can only be granted by the external location owner explicitly and is not included in external location ownership or ALL PRIVILEGES on the external location for - security reasons.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + security reasons.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGenerateTemporaryPathCredentials()) @@ -62,8 +67,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start generate-temporary-path-credentials command diff --git a/cmd/workspace/temporary-table-credentials/temporary-table-credentials.go b/cmd/workspace/temporary-table-credentials/temporary-table-credentials.go index 7ec127cbb05..6a82d2b91b3 100644 --- a/cmd/workspace/temporary-table-credentials/temporary-table-credentials.go +++ b/cmd/workspace/temporary-table-credentials/temporary-table-credentials.go @@ -3,6 +3,8 @@ package temporary_table_credentials import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -15,11 +17,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "temporary-table-credentials", - Short: `Temporary Table Credentials are short-lived, downscoped credentials used to access cloud storage locations where table data is stored in Databricks.`, - Long: `Temporary Table Credentials are short-lived, downscoped credentials used to +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "temporary-table-credentials", + Short: `Temporary Table Credentials are short-lived, downscoped credentials used to access cloud storage locations where table data is stored in Databricks.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Temporary Table Credentials are short-lived, downscoped credentials used to access cloud storage locations where table data is stored in Databricks. These credentials provide secure and time-limited access to data in cloud environments such as AWS, Azure, and Google Cloud. Each cloud provider has its @@ -35,14 +42,13 @@ func New() *cobra.Command { user must be granted the EXTERNAL USE SCHEMA permission at the schema level by the catalog owner. Note that EXTERNAL USE SCHEMA is a schema level permission that can only be granted by the catalog owner explicitly and is not included - in schema ownership or ALL PRIVILEGES on the schema for security reasons.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + in schema ownership or ALL PRIVILEGES on the schema for security reasons.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGenerateTemporaryTableCredentials()) @@ -51,8 +57,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start generate-temporary-table-credentials command diff --git a/cmd/workspace/temporary-volume-credentials/temporary-volume-credentials.go b/cmd/workspace/temporary-volume-credentials/temporary-volume-credentials.go index d503dba3a08..04ffbb12d77 100644 --- a/cmd/workspace/temporary-volume-credentials/temporary-volume-credentials.go +++ b/cmd/workspace/temporary-volume-credentials/temporary-volume-credentials.go @@ -3,6 +3,8 @@ package temporary_volume_credentials import ( + "context" + "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -15,11 +17,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "temporary-volume-credentials", - Short: `*Public Preview* Temporary Volume Credentials are short-lived, downscoped credentials used to access cloud storage locations where volume data is stored in Databricks.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "temporary-volume-credentials", + Short: `*Public Preview* Temporary Volume Credentials are short-lived, downscoped credentials used to access cloud storage locations where volume data is stored in Databricks.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. Temporary Volume Credentials are short-lived, downscoped credentials used to access cloud storage locations where volume data is stored in Databricks. @@ -37,14 +44,13 @@ Temporary Volume Credentials are short-lived, downscoped credentials used to user must be granted the EXTERNAL USE SCHEMA permission at the schema level by the catalog owner. Note that EXTERNAL USE SCHEMA is a schema level permission that can only be granted by the catalog owner explicitly and is not included - in schema ownership or ALL PRIVILEGES on the schema for security reasons.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + in schema ownership or ALL PRIVILEGES on the schema for security reasons.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newGenerateTemporaryVolumeCredentials()) @@ -53,8 +59,6 @@ Temporary Volume Credentials are short-lived, downscoped credentials used to for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start generate-temporary-volume-credentials command diff --git a/cmd/workspace/token-management/token-management.go b/cmd/workspace/token-management/token-management.go index ebbcdd9d8dd..ab1ba25f612 100644 --- a/cmd/workspace/token-management/token-management.go +++ b/cmd/workspace/token-management/token-management.go @@ -3,6 +3,7 @@ package token_management import ( + "context" "errors" "fmt" @@ -18,20 +19,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "token-management", - Short: `Enables administrators to get all tokens and delete tokens for other users.`, - Long: `Enables administrators to get all tokens and delete tokens for other users. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "token-management", + Short: `Enables administrators to get all tokens and delete tokens for other users.`, + GroupID: "settings", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Enables administrators to get all tokens and delete tokens for other users. Admins can either get every token, get a specific token by ID, or get all - tokens for a particular user.`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } + tokens for a particular user.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateOboToken()) @@ -48,8 +53,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-obo-token command diff --git a/cmd/workspace/tokens/tokens.go b/cmd/workspace/tokens/tokens.go index 40ca4b786e9..f0195ce914e 100644 --- a/cmd/workspace/tokens/tokens.go +++ b/cmd/workspace/tokens/tokens.go @@ -3,6 +3,7 @@ package tokens import ( + "context" "errors" "fmt" @@ -18,19 +19,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "tokens", - Short: `The Token API allows you to create, list, and revoke tokens that can be used to authenticate and access Databricks REST APIs.`, - Long: `The Token API allows you to create, list, and revoke tokens that can be used - to authenticate and access Databricks REST APIs.`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "tokens", + Short: `The Token API allows you to create, list, and revoke tokens that can be used to authenticate and access Databricks REST APIs.`, + GroupID: "settings", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Token API allows you to create, list, and revoke tokens that can be used + to authenticate and access Databricks REST APIs.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/users-v2/users-v2.go b/cmd/workspace/users-v2/users-v2.go index b3c3b08b6b5..a3c9d677bc5 100644 --- a/cmd/workspace/users-v2/users-v2.go +++ b/cmd/workspace/users-v2/users-v2.go @@ -3,6 +3,7 @@ package users_v2 import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "users-v2", - Short: `*Public Preview* User identities recognized by Databricks and represented by email addresses.`, - Long: `This command is in Public Preview and may change without notice. +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "users-v2", + Short: `*Public Preview* User identities recognized by Databricks and represented by email addresses.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This command is in Public Preview and may change without notice. User identities recognized by Databricks and represented by email addresses. @@ -33,14 +39,13 @@ User identities recognized by Databricks and represented by email addresses. access to Databricks workspace, admins can terminate the user in your identity provider and that user’s account will also be removed from Databricks workspace. This ensures a consistent offboarding process and prevents - unauthorized users from accessing sensitive data.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } + unauthorized users from accessing sensitive data.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW" - cmd.Annotations["launch_stage_display"] = "Public Preview" + cmd.Annotations = map[string]string{ + "launch_stage": "PUBLIC_PREVIEW", + "launch_stage_display": "Public Preview", + } // Add methods cmd.AddCommand(newCreate()) @@ -58,8 +63,6 @@ User identities recognized by Databricks and represented by email addresses. for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/users/users.go b/cmd/workspace/users/users.go index c9ea8059428..17bf5e2fc1e 100755 --- a/cmd/workspace/users/users.go +++ b/cmd/workspace/users/users.go @@ -6,6 +6,7 @@ package users import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -20,11 +21,19 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "users", - Short: `User identities recognized by Databricks and represented by email addresses.`, - Long: `User identities recognized by Databricks and represented by email addresses. +// Spec declares the users command. +var Spec = root.CommandSpec{ + Use: "users", + Short: `User identities recognized by Databricks and represented by email addresses.`, + GroupID: "iam", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Annotations = map[string]string{ + "package": "iam", + } + cmd.Long = `User identities recognized by Databricks and represented by email addresses. Databricks recommends using SCIM provisioning to sync users and groups automatically from your identity provider to your Databricks workspace. SCIM @@ -34,13 +43,8 @@ func New() *cobra.Command { access to Databricks workspace, admins can terminate the user in your identity provider and that user’s account will also be removed from Databricks workspace. This ensures a consistent offboarding process and prevents - unauthorized users from accessing sensitive data.`, - GroupID: "iam", - Annotations: map[string]string{ - "package": "iam", - }, - RunE: root.ReportUnknownSubcommand, - } + unauthorized users from accessing sensitive data.` + cmd.RunE = root.ReportUnknownSubcommand // Add methods cmd.AddCommand(newCreate()) @@ -58,8 +62,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/vector-search-endpoints/vector-search-endpoints.go b/cmd/workspace/vector-search-endpoints/vector-search-endpoints.go index 41a834fa8c2..eb4ab21b299 100644 --- a/cmd/workspace/vector-search-endpoints/vector-search-endpoints.go +++ b/cmd/workspace/vector-search-endpoints/vector-search-endpoints.go @@ -3,6 +3,7 @@ package vector_search_endpoints import ( + "context" "errors" "fmt" "time" @@ -19,18 +20,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "vector-search-endpoints", - Short: `**Endpoint**: Represents the compute resources to host AI Search indexes.`, - Long: `**Endpoint**: Represents the compute resources to host AI Search indexes.`, - GroupID: "vectorsearch", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "vector-search-endpoints", + Short: `**Endpoint**: Represents the compute resources to host AI Search indexes.`, + GroupID: "vectorsearch", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `**Endpoint**: Represents the compute resources to host AI Search indexes.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateEndpoint()) @@ -52,8 +57,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-endpoint command diff --git a/cmd/workspace/vector-search-indexes/vector-search-indexes.go b/cmd/workspace/vector-search-indexes/vector-search-indexes.go index a1b9bddfcfa..818b510e50c 100644 --- a/cmd/workspace/vector-search-indexes/vector-search-indexes.go +++ b/cmd/workspace/vector-search-indexes/vector-search-indexes.go @@ -3,6 +3,7 @@ package vector_search_indexes import ( + "context" "errors" "fmt" @@ -18,11 +19,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "vector-search-indexes", - Short: `**Index**: An efficient representation of your embedding vectors that supports real-time and efficient approximate nearest neighbor (ANN) search queries.`, - Long: `**Index**: An efficient representation of your embedding vectors that supports +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "vector-search-indexes", + Short: `**Index**: An efficient representation of your embedding vectors that supports real-time and efficient approximate nearest neighbor (ANN) search queries.`, + GroupID: "vectorsearch", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `**Index**: An efficient representation of your embedding vectors that supports real-time and efficient approximate nearest neighbor (ANN) search queries. There are 2 types of AI Search indexes: - **Delta Sync Index**: An index that @@ -30,14 +36,13 @@ func New() *cobra.Command { updating the index as the underlying data in the Delta Table changes. - **Direct Vector Access Index**: An index that supports direct read and write of vectors and metadata through our REST and SDK APIs. With this model, the - user manages index updates.`, - GroupID: "vectorsearch", - RunE: root.ReportUnknownSubcommand, - } + user manages index updates.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateIndex()) @@ -55,8 +60,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-index command diff --git a/cmd/workspace/volumes/volumes.go b/cmd/workspace/volumes/volumes.go index 3c7ac850ed0..f6803989bc7 100644 --- a/cmd/workspace/volumes/volumes.go +++ b/cmd/workspace/volumes/volumes.go @@ -3,6 +3,7 @@ package volumes import ( + "context" "errors" "fmt" @@ -18,25 +19,29 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "volumes", - Short: `Volumes are a Unity Catalog (UC) capability for accessing, storing, governing, organizing, and processing files.`, - Long: `Volumes are a Unity Catalog (UC) capability for accessing, storing, governing, +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "volumes", + Short: `Volumes are a Unity Catalog (UC) capability for accessing, storing, governing, organizing, and processing files.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Volumes are a Unity Catalog (UC) capability for accessing, storing, governing, organizing, and processing files. Use cases include running machine learning on unstructured data such as image, audio, video, or PDF files, organizing data sets during the data exploration stages in data science, working with libraries that require access to the local file system on cluster machines, storing library and config files of arbitrary formats such as .whl or .txt centrally and providing secure access to those files across workspaces, or - transforming and querying non-tabular data files in ETL.`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + transforming and querying non-tabular data files in ETL.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -49,8 +54,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/warehouses/warehouses.go b/cmd/workspace/warehouses/warehouses.go index 8995fadc49b..df8e63a9628 100644 --- a/cmd/workspace/warehouses/warehouses.go +++ b/cmd/workspace/warehouses/warehouses.go @@ -3,6 +3,7 @@ package warehouses import ( + "context" "errors" "fmt" "strings" @@ -21,20 +22,24 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "warehouses", - Short: `A SQL warehouse is a compute resource that lets you run SQL commands on data objects within Databricks SQL.`, - Long: `A SQL warehouse is a compute resource that lets you run SQL commands on data +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "warehouses", + Short: `A SQL warehouse is a compute resource that lets you run SQL commands on data objects within Databricks SQL.`, + GroupID: "sql", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A SQL warehouse is a compute resource that lets you run SQL commands on data objects within Databricks SQL. Compute resources are infrastructure resources - that provide processing capabilities in the cloud.`, - GroupID: "sql", - RunE: root.ReportUnknownSubcommand, - } + that provide processing capabilities in the cloud.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreate()) @@ -60,8 +65,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create command diff --git a/cmd/workspace/workspace-bindings/workspace-bindings.go b/cmd/workspace/workspace-bindings/workspace-bindings.go index eac23b59514..9af68392125 100644 --- a/cmd/workspace/workspace-bindings/workspace-bindings.go +++ b/cmd/workspace/workspace-bindings/workspace-bindings.go @@ -3,6 +3,7 @@ package workspace_bindings import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,11 +18,16 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "workspace-bindings", - Short: `A securable in Databricks can be configured as __OPEN__ or __ISOLATED__.`, - Long: `A securable in Databricks can be configured as __OPEN__ or __ISOLATED__. An +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "workspace-bindings", + Short: `A securable in Databricks can be configured as __OPEN__ or __ISOLATED__.`, + GroupID: "catalog", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `A securable in Databricks can be configured as __OPEN__ or __ISOLATED__. An __OPEN__ securable can be accessed from any workspace, while an __ISOLATED__ securable can only be accessed from a configured list of workspaces. This API allows you to configure (bind) securables to workspaces. @@ -39,14 +45,13 @@ func New() *cobra.Command { introduces the ability to bind a securable in READ_ONLY mode (catalogs only). Securable types that support binding: - catalog - storage_credential - - credential - external_location`, - GroupID: "catalog", - RunE: root.ReportUnknownSubcommand, - } + credential - external_location` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGet()) @@ -58,8 +63,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get command diff --git a/cmd/workspace/workspace-conf/workspace-conf.go b/cmd/workspace/workspace-conf/workspace-conf.go index 8da40a559d7..299f3b83f63 100644 --- a/cmd/workspace/workspace-conf/workspace-conf.go +++ b/cmd/workspace/workspace-conf/workspace-conf.go @@ -3,6 +3,7 @@ package workspace_conf import ( + "context" "errors" "github.com/databricks/cli/cmd/root" @@ -17,18 +18,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "workspace-conf", - Short: `This API allows updating known workspace settings for advanced users.`, - Long: `This API allows updating known workspace settings for advanced users.`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "workspace-conf", + Short: `This API allows updating known workspace settings for advanced users.`, + GroupID: "settings", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `This API allows updating known workspace settings for advanced users.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGetStatus()) @@ -38,8 +43,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-status command diff --git a/cmd/workspace/workspace-entity-tag-assignments/workspace-entity-tag-assignments.go b/cmd/workspace/workspace-entity-tag-assignments/workspace-entity-tag-assignments.go index 794ab2066f9..e6a73b6e747 100644 --- a/cmd/workspace/workspace-entity-tag-assignments/workspace-entity-tag-assignments.go +++ b/cmd/workspace/workspace-entity-tag-assignments/workspace-entity-tag-assignments.go @@ -3,6 +3,7 @@ package workspace_entity_tag_assignments import ( + "context" "errors" "fmt" @@ -18,18 +19,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "workspace-entity-tag-assignments", - Short: `Manage tag assignments on workspace-scoped objects.`, - Long: `Manage tag assignments on workspace-scoped objects.`, - GroupID: "tags", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "workspace-entity-tag-assignments", + Short: `Manage tag assignments on workspace-scoped objects.`, + GroupID: "tags", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Manage tag assignments on workspace-scoped objects.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateTagAssignment()) @@ -42,8 +47,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-tag-assignment command diff --git a/cmd/workspace/workspace-iam-v2/workspace-iam-v2.go b/cmd/workspace/workspace-iam-v2/workspace-iam-v2.go index b6f841ca75b..cbee25a2def 100644 --- a/cmd/workspace/workspace-iam-v2/workspace-iam-v2.go +++ b/cmd/workspace/workspace-iam-v2/workspace-iam-v2.go @@ -3,6 +3,7 @@ package workspace_iam_v2 import ( + "context" "errors" "fmt" "strings" @@ -20,19 +21,23 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "workspace-iam-v2", - Short: `These APIs are used to manage identities and the workspace access of these identities in Databricks.`, - Long: `These APIs are used to manage identities and the workspace access of these - identities in Databricks.`, - GroupID: "iam", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "workspace-iam-v2", + Short: `These APIs are used to manage identities and the workspace access of these identities in Databricks.`, + GroupID: "iam", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `These APIs are used to manage identities and the workspace access of these + identities in Databricks.` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newCreateDirectGroupMemberProxy()) @@ -79,8 +84,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start create-direct-group-member-proxy command diff --git a/cmd/workspace/workspace-settings-v2/workspace-settings-v2.go b/cmd/workspace/workspace-settings-v2/workspace-settings-v2.go index 124eddcbaea..c52a23dc6ea 100644 --- a/cmd/workspace/workspace-settings-v2/workspace-settings-v2.go +++ b/cmd/workspace/workspace-settings-v2/workspace-settings-v2.go @@ -3,6 +3,7 @@ package workspace_settings_v2 import ( + "context" "fmt" "github.com/databricks/cli/cmd/root" @@ -17,18 +18,22 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "workspace-settings-v2", - Short: `APIs to manage workspace level settings.`, - Long: `APIs to manage workspace level settings`, - GroupID: "settings", - RunE: root.ReportUnknownSubcommand, - } +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "workspace-settings-v2", + Short: `APIs to manage workspace level settings.`, + GroupID: "settings", + Build: buildCommand, +} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `APIs to manage workspace level settings` + cmd.RunE = root.ReportUnknownSubcommand + + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newGetPublicWorkspaceSetting()) @@ -39,8 +44,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start get-public-workspace-setting command diff --git a/cmd/workspace/workspace/workspace.go b/cmd/workspace/workspace/workspace.go index 97c47f80ac0..640109177d3 100644 --- a/cmd/workspace/workspace/workspace.go +++ b/cmd/workspace/workspace/workspace.go @@ -3,6 +3,7 @@ package workspace import ( + "context" "errors" "fmt" @@ -18,23 +19,27 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "workspace", - Short: `The Workspace API allows you to list, import, export, and delete workspace objects such as notebooks, files, folders, and dashboards.`, - Long: `The Workspace API allows you to list, import, export, and delete workspace +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "workspace", + Short: `The Workspace API allows you to list, import, export, and delete workspace objects such as notebooks, files, folders, and dashboards.`, + GroupID: "workspace", + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `The Workspace API allows you to list, import, export, and delete workspace objects such as notebooks, files, folders, and dashboards. Additionally, it provides endpoints to manage permissions for any workspace object. A notebook is a web-based interface to a document that contains runnable code, - visualizations, and explanatory text.`, - GroupID: "workspace", - RunE: root.ReportUnknownSubcommand, - } + visualizations, and explanatory text.` + cmd.RunE = root.ReportUnknownSubcommand - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "GA" - cmd.Annotations["launch_stage_display"] = "GA" + cmd.Annotations = map[string]string{ + "launch_stage": "GA", + "launch_stage_display": "GA", + } // Add methods cmd.AddCommand(newDelete()) @@ -52,8 +57,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } // start delete command diff --git a/experimental/ssh/cmd/ssh.go b/experimental/ssh/cmd/ssh.go index 19517cd6204..983c85ab8b0 100644 --- a/experimental/ssh/cmd/ssh.go +++ b/experimental/ssh/cmd/ssh.go @@ -1,28 +1,32 @@ package ssh import ( + "context" + + "github.com/databricks/cli/cmd/root" "github.com/spf13/cobra" ) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "ssh", - Short: "Connect to your Databricks compute and workspace via SSH", - Hidden: true, - Long: `Connect to your Databricks compute and workspace via SSH. +// Spec declares the ssh command. +var Spec = root.CommandSpec{ + Use: "ssh", + Short: "Connect to your Databricks compute and workspace via SSH", + Hidden: true, + Build: buildCommand, +} + +func buildCommand(ctx context.Context, cmd *cobra.Command) { + cmd.Long = `Connect to your Databricks compute and workspace via SSH. Common workflows: databricks ssh connect --ide=cursor # connect to serverless through Cursor databricks ssh setup --name= --cluster= # update ~/.ssh/config so you can reconnect to a dedicated cluster ssh # connect to dedicated cluster after setup -Use ` + "`databricks ssh connect --help`" + ` to see all available flags.`, - } +Use ` + "`databricks ssh connect --help`" + ` to see all available flags.` cmd.AddCommand(newSetupCommand()) cmd.AddCommand(newConnectCommand()) cmd.AddCommand(newServerCommand()) cmd.AddCommand(newAgentShimCommand()) - - return cmd } diff --git a/internal/cligen/templates/cmds-account.go.tmpl b/internal/cligen/templates/cmds-account.go.tmpl index b368d3218bf..e30f988b24c 100644 --- a/internal/cligen/templates/cmds-account.go.tmpl +++ b/internal/cligen/templates/cmds-account.go.tmpl @@ -5,6 +5,9 @@ package account {{$excludes := list}} import ( + "context" + + "github.com/databricks/cli/cmd/root" "github.com/spf13/cobra" {{range .Services}}{{if and .IsAccounts (not .HasParent) (not .IsDataPlane)}}{{if not (in $excludes .KebabName) }} {{.SnakeName}} "github.com/databricks/cli/cmd/account/{{(.TrimPrefix "account").KebabName}}"{{end}}{{end}}{{end}} @@ -14,18 +17,18 @@ import ( account_users "github.com/databricks/cli/cmd/account/users" ) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "account", - Short: `Databricks Account Commands`, - } +// Spec declares the account command. +var Spec = root.CommandSpec{ + Use: "account", + Short: `Databricks Account Commands`, + Build: buildCommand, +} +func buildCommand(ctx context.Context, cmd *cobra.Command) { {{range .Services}}{{if and .IsAccounts (not .HasParent) (not .IsDataPlane)}}{{if not (in $excludes .KebabName) -}} - cmd.AddCommand({{.SnakeName}}.New()) + cmd.AddCommand(root.NewCommand(ctx, {{.SnakeName}}.Spec)) {{end}}{{end}}{{end}} - cmd.AddCommand(account_groups.New()) - cmd.AddCommand(account_service_principals.New()) - cmd.AddCommand(account_users.New()) - - return cmd + cmd.AddCommand(root.NewCommand(ctx, account_groups.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_service_principals.Spec)) + cmd.AddCommand(root.NewCommand(ctx, account_users.Spec)) } diff --git a/internal/cligen/templates/cmds-workspace.go.tmpl b/internal/cligen/templates/cmds-workspace.go.tmpl index 6e748488893..efc0f0ace4e 100644 --- a/internal/cligen/templates/cmds-workspace.go.tmpl +++ b/internal/cligen/templates/cmds-workspace.go.tmpl @@ -15,22 +15,23 @@ package workspace import ( {{- range .Services}}{{if and (not .IsAccounts) (not .HasParent) (not .IsDataPlane)}}{{if not (in $excludes .KebabName) }} {{.SnakeName}} "github.com/databricks/cli/cmd/workspace/{{.KebabName}}"{{end}}{{end}}{{end}} - "github.com/spf13/cobra" + "github.com/databricks/cli/cmd/root" groups "github.com/databricks/cli/cmd/workspace/groups" service_principals "github.com/databricks/cli/cmd/workspace/service-principals" users "github.com/databricks/cli/cmd/workspace/users" ) -func All() []*cobra.Command { - var out []*cobra.Command +// All returns the specs of the workspace commands. +func All() []root.CommandSpec { + var out []root.CommandSpec {{range .Services}}{{if and (not .IsAccounts) (not .HasParent) (not .IsDataPlane)}}{{if not (in $excludes .KebabName) -}} - out = append(out, {{.SnakeName}}.New()) + out = append(out, {{.SnakeName}}.Spec) {{end}}{{end}}{{end}} - out = append(out, groups.New()) - out = append(out, service_principals.New()) - out = append(out, users.New()) + out = append(out, groups.Spec) + out = append(out, service_principals.Spec) + out = append(out, users.Spec) return out } diff --git a/internal/cligen/templates/service.go.tmpl b/internal/cligen/templates/service.go.tmpl index a13724dca2b..ec725df33f2 100644 --- a/internal/cligen/templates/service.go.tmpl +++ b/internal/cligen/templates/service.go.tmpl @@ -3,6 +3,7 @@ package {{(.TrimPrefix "account").SnakeName}} import ( + "context" "encoding/json" "errors" "fmt" @@ -64,34 +65,40 @@ import ( // Functions can be added from the `init()` function in manually curated files in this directory. var cmdOverrides []func(*cobra.Command) -func New() *cobra.Command { - cmd := &cobra.Command{ - Use: "{{(.TrimPrefix "account").KebabName}}", - {{- if .Description }} - Short: `{{with .CLILaunchStageLabel}}{{.}} {{end}}{{.Summary | without "`"}}`, - Long: `{{with .CLILaunchStageBanner}}{{.}} +// Spec declares the command for this service. +var Spec = root.CommandSpec{ + Use: "{{(.TrimPrefix "account").KebabName}}", + {{- if .Description }} + Short: `{{with .CLILaunchStageLabel}}{{.}} {{end}}{{.Summary | without "`"}}`, + {{- end }} + {{- if not .HasParent }} + {{- if .DocsGroup }} + GroupID: "{{ .DocsGroup }}", + {{- else }} + GroupID: "{{ .Package.Name }}", + {{- end }} + {{- end }} + {{- if $hideService }} -{{end}}{{.Comment " " 80 | without "`"}}`, - {{- end }} - {{- if not .HasParent }} - {{- if .DocsGroup }} - GroupID: "{{ .DocsGroup }}", - {{- else }} - GroupID: "{{ .Package.Name }}", - {{- end }} - {{- end }} - {{- if $hideService }} + // This service is being previewed; hide from help output. + Hidden: true, + {{- end }} + Build: buildCommand, +} - // This service is being previewed; hide from help output. - Hidden: true, - {{- end }} - RunE: root.ReportUnknownSubcommand, - } +func buildCommand(ctx context.Context, cmd *cobra.Command) { + {{- if .Description }} + cmd.Long = `{{with .CLILaunchStageBanner}}{{.}} + +{{end}}{{.Comment " " 80 | without "`"}}` + {{- end }} + cmd.RunE = root.ReportUnknownSubcommand {{- if .LaunchStage }} - cmd.Annotations = make(map[string]string) - cmd.Annotations["launch_stage"] = "{{.LaunchStage}}" - cmd.Annotations["launch_stage_display"] = "{{.CLILaunchStageDisplay}}" + cmd.Annotations = map[string]string{ + "launch_stage": "{{.LaunchStage}}", + "launch_stage_display": "{{.CLILaunchStageDisplay}}", + } {{- end }} {{ if gt (len .Methods) 0 -}} @@ -107,7 +114,7 @@ func New() *cobra.Command { {{ if .HasSubservices }} // Add subservices {{- range .Subservices}} - cmd.AddCommand({{.SnakeName}}.New()) + cmd.AddCommand(root.NewCommand(ctx, {{.SnakeName}}.Spec)) {{- end}} {{- end}} @@ -115,8 +122,6 @@ func New() *cobra.Command { for _, fn := range cmdOverrides { fn(cmd) } - - return cmd } {{- $serviceName := .KebabName -}} diff --git a/internal/testcli/runner.go b/internal/testcli/runner.go index efd4dfecaaf..8ca8ec07ac1 100644 --- a/internal/testcli/runner.go +++ b/internal/testcli/runner.go @@ -13,7 +13,6 @@ import ( "github.com/stretchr/testify/require" "github.com/databricks/cli/cmd" - "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/internal/testutil" "github.com/databricks/cli/libs/cmdio" ) @@ -122,7 +121,7 @@ func (r *Runner) RunBackground() { // Run command in background. go func() { - err := root.Execute(ctx, cli, r.args) + err := cli.Execute(ctx, r.args) if err != nil { if r.Verbose { r.Logf("Error running command: %s", err) @@ -185,7 +184,7 @@ func (r *Runner) Run() (bytes.Buffer, bytes.Buffer, error) { r.Logf(" args: %s", strings.Join(r.args, ", ")) } - err := root.Execute(r.ctx, cli, r.args) + err := cli.Execute(r.ctx, r.args) if err != nil { if r.Verbose { r.Logf(" error: %s", err) diff --git a/libs/cmdgroup/command.go b/libs/cmdgroup/command.go index c64bac9c359..8af25381f35 100644 --- a/libs/cmdgroup/command.go +++ b/libs/cmdgroup/command.go @@ -141,3 +141,20 @@ func FilterGroups(groups []cobra.Group, allCommands []*cobra.Command) []cobra.Gr return filteredGroups } + +// Configure adds the groups that have at least one available command among +// cmd's subcommands. When at most one group remains, the subcommands are +// ungrouped so that cobra's default "Available Commands" heading is used, as +// for commands that don't define groups at all. +func Configure(cmd *cobra.Command, groups []cobra.Group) { + filtered := FilterGroups(groups, cmd.Commands()) + if len(filtered) <= 1 { + for _, sub := range cmd.Commands() { + sub.GroupID = "" + } + return + } + for i := range filtered { + cmd.AddGroup(&filtered[i]) + } +} diff --git a/main.go b/main.go index 0eb99617b78..10c3686a223 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "path/filepath" "github.com/databricks/cli/cmd" - "github.com/databricks/cli/cmd/root" // Registers a disk-cached HostMetadataResolver factory on the SDK so every // *config.Config the CLI constructs reuses the cached /.well-known lookup. @@ -25,7 +24,7 @@ func main() { } ctx := context.Background() - err := root.Execute(ctx, cmd.New(ctx), os.Args[1:]) + err := cmd.New(ctx).Execute(ctx, os.Args[1:]) if err != nil { os.Exit(1) } diff --git a/main_test.go b/main_test.go index 0f93f0236bd..375715de7ad 100644 --- a/main_test.go +++ b/main_test.go @@ -6,28 +6,11 @@ import ( "path/filepath" "testing" - "github.com/databricks/cli/cmd" - "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/mod/module" ) -func TestCommandsDontUseUnderscoreInName(t *testing.T) { - // We use underscore as separator between commands in logs - // so need to enforce that no command uses it in its name. - // - // This test lives in the main package because this is where - // all commands are imported. - // - queue := []*cobra.Command{cmd.New(t.Context())} - for len(queue) > 0 { - cmd := queue[0] - assert.NotContains(t, cmd.Name(), "_") - queue = append(queue[1:], cmd.Commands()...) - } -} - func TestImportDoesNotSetCliPathEnv(t *testing.T) { // Test binaries run by their absolute path, which is exactly the condition // under which main exports DATABRICKS_CLI_PATH; an import-time export would