From 4ef46cf91b752e0a0e21b47877b342a4000e8858 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Thu, 29 Jun 2023 15:38:15 +0200 Subject: [PATCH 1/5] Fixed ignoring required positional parameters when --json flag is provided --- .codegen/service.go.tmpl | 8 +- .gitattributes | 1 + cmd/account/access-control/access-control.go | 14 +- cmd/account/billable-usage/billable-usage.go | 8 +- cmd/account/budgets/budgets.go | 66 +++-- cmd/account/credentials/credentials.go | 66 +++-- .../custom-app-integration.go | 18 +- .../encryption-keys/encryption-keys.go | 12 +- cmd/account/groups/groups.go | 99 ++++---- .../ip-access-lists/ip-access-lists.go | 66 +++-- cmd/account/log-delivery/log-delivery.go | 47 ++-- .../metastore-assignments.go | 60 ++--- cmd/account/metastores/metastores.go | 18 +- cmd/account/networks/networks.go | 66 +++-- cmd/account/private-access/private-access.go | 76 +++--- .../published-app-integration.go | 18 +- .../service-principal-secrets.go | 38 +-- .../service-principals/service-principals.go | 99 ++++---- .../storage-credentials.go | 36 +-- cmd/account/storage/storage.go | 66 +++-- cmd/account/users/users.go | 99 ++++---- cmd/account/vpc-endpoints/vpc-endpoints.go | 66 +++-- .../workspace-assignment.go | 44 ++-- cmd/account/workspaces/workspaces.go | 111 ++++---- .../access-control-proxy.go | 172 +++++++++++++ cmd/workspace/alerts/alerts.go | 66 +++-- cmd/workspace/catalogs/catalogs.go | 12 +- .../cluster-policies/cluster-policies.go | 33 ++- cmd/workspace/clusters/clusters.go | 89 ++++--- cmd/workspace/connections/connections.go | 66 +++-- cmd/workspace/dashboards/dashboards.go | 99 ++++---- cmd/workspace/experiments/experiments.go | 24 +- .../external-locations/external-locations.go | 12 +- cmd/workspace/functions/functions.go | 107 ++++---- .../git-credentials/git-credentials.go | 111 ++++---- .../global-init-scripts.go | 76 +++--- cmd/workspace/grants/grants.go | 42 ++- cmd/workspace/groups/groups.go | 99 ++++---- .../instance-pools/instance-pools.go | 33 ++- .../ip-access-lists/ip-access-lists.go | 66 +++-- cmd/workspace/jobs/jobs.go | 148 ++++++----- cmd/workspace/libraries/libraries.go | 6 +- cmd/workspace/metastores/metastores.go | 166 ++++++------ .../model-registry/model-registry.go | 86 ++----- cmd/workspace/permissions/permissions.go | 32 +-- cmd/workspace/pipelines/pipelines.go | 239 +++++++++--------- .../policy-families/policy-families.go | 6 +- cmd/workspace/providers/providers.go | 99 ++++---- cmd/workspace/queries/queries.go | 132 +++++----- .../recipient-activation.go | 12 +- cmd/workspace/recipients/recipients.go | 113 ++++----- cmd/workspace/repos/repos.go | 111 ++++---- cmd/workspace/schemas/schemas.go | 105 ++++---- cmd/workspace/secrets/secrets.go | 20 +- .../service-principals/service-principals.go | 99 ++++---- .../serving-endpoints/serving-endpoints.go | 40 +-- cmd/workspace/shares/shares.go | 24 +- .../storage-credentials.go | 66 +++-- .../system-schemas/system-schemas.go | 40 +-- .../table-constraints/table-constraints.go | 16 +- cmd/workspace/tables/tables.go | 107 ++++---- .../token-management/token-management.go | 66 +++-- cmd/workspace/users/users.go | 99 ++++---- cmd/workspace/volumes/volumes.go | 107 ++++---- cmd/workspace/warehouses/warehouses.go | 165 ++++++------ .../workspace-bindings/workspace-bindings.go | 12 +- .../workspace-conf/workspace-conf.go | 6 +- cmd/workspace/workspace/workspace.go | 45 ++-- go.mod | 2 +- go.sum | 4 +- 70 files changed, 2095 insertions(+), 2387 deletions(-) create mode 100755 cmd/workspace/access-control-proxy/access-control-proxy.go diff --git a/.codegen/service.go.tmpl b/.codegen/service.go.tmpl index bc69ce81e4..46ff4c90ef 100644 --- a/.codegen/service.go.tmpl +++ b/.codegen/service.go.tmpl @@ -85,6 +85,7 @@ func init() { {{- $hasIdPrompt := and (not $noPrompt) (and $hasSinglePosArg $serviceHasNamedIdMap) -}} {{- $wait := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}} {{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}} +{{- $useJsonForAllFields := or .IsJsonOnly (and .Request (or (not .Request.IsAllRequiredFieldsPrimitive) .Request.IsAllRequiredFieldsJsonUnserialisable)) -}} var {{.CamelName}}Cmd = &cobra.Command{ Use: "{{.KebabName}}{{if $hasPosArgs}}{{range .Request.RequiredFields}} {{.ConstantName}}{{end}}{{end}}", {{- if .Description }} @@ -100,9 +101,11 @@ var {{.CamelName}}Cmd = &cobra.Command{ Annotations: map[string]string{},{{if $hasRequiredArgs }} Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs({{len .Request.RequiredFields}}) + {{- if $useJsonForAllFields }} if cmd.Flags().Changed("json") { check = cobra.ExactArgs(0) } + {{- end }} return check(cmd, args) },{{end}} PreRunE: root.Must{{if .Service.IsAccounts}}Account{{else}}Workspace{{end}}Client, @@ -115,7 +118,8 @@ var {{.CamelName}}Cmd = &cobra.Command{ if err != nil { return err } - } else { + }{{if $useJsonForAllFields }} else { + {{- end }} {{- if $hasIdPrompt}} if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) @@ -148,7 +152,9 @@ var {{.CamelName}}Cmd = &cobra.Command{ {{- else -}} return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") {{- end -}} + {{if $useJsonForAllFields }} } + {{end }} {{end}} {{if $wait -}} wait, err := {{if .Service.IsAccounts}}a{{else}}w{{end}}.{{.Service.PascalName}}.{{.PascalName}}(ctx{{if .Request}}, {{.CamelName}}Req{{end}}) diff --git a/.gitattributes b/.gitattributes index 8b95da2070..db7560e293 100755 --- a/.gitattributes +++ b/.gitattributes @@ -23,6 +23,7 @@ cmd/account/users/users.go linguist-generated=true cmd/account/vpc-endpoints/vpc-endpoints.go linguist-generated=true cmd/account/workspace-assignment/workspace-assignment.go linguist-generated=true cmd/account/workspaces/workspaces.go linguist-generated=true +cmd/workspace/access-control-proxy/access-control-proxy.go linguist-generated=true cmd/workspace/alerts/alerts.go linguist-generated=true cmd/workspace/catalogs/catalogs.go linguist-generated=true cmd/workspace/cluster-policies/cluster-policies.go linguist-generated=true diff --git a/cmd/account/access-control/access-control.go b/cmd/account/access-control/access-control.go index 72be53c3fa..216f49b698 100755 --- a/cmd/account/access-control/access-control.go +++ b/cmd/account/access-control/access-control.go @@ -47,9 +47,6 @@ var getAssignableRolesForResourceCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -61,9 +58,8 @@ var getAssignableRolesForResourceCmd = &cobra.Command{ if err != nil { return err } - } else { - getAssignableRolesForResourceReq.Resource = args[0] } + getAssignableRolesForResourceReq.Resource = args[0] response, err := a.AccessControl.GetAssignableRolesForResource(ctx, getAssignableRolesForResourceReq) if err != nil { @@ -100,9 +96,6 @@ var getRuleSetCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -114,10 +107,9 @@ var getRuleSetCmd = &cobra.Command{ if err != nil { return err } - } else { - getRuleSetReq.Name = args[0] - getRuleSetReq.Etag = args[1] } + getRuleSetReq.Name = args[0] + getRuleSetReq.Etag = args[1] response, err := a.AccessControl.GetRuleSet(ctx, getRuleSetReq) if err != nil { diff --git a/cmd/account/billable-usage/billable-usage.go b/cmd/account/billable-usage/billable-usage.go index c462677361..20b4cb2a21 100755 --- a/cmd/account/billable-usage/billable-usage.go +++ b/cmd/account/billable-usage/billable-usage.go @@ -52,9 +52,6 @@ var downloadCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -66,10 +63,9 @@ var downloadCmd = &cobra.Command{ if err != nil { return err } - } else { - downloadReq.StartMonth = args[0] - downloadReq.EndMonth = args[1] } + downloadReq.StartMonth = args[0] + downloadReq.EndMonth = args[1] err = a.BillableUsage.Download(ctx, downloadReq) if err != nil { diff --git a/cmd/account/budgets/budgets.go b/cmd/account/budgets/budgets.go index e48952dee1..a5831198a1 100755 --- a/cmd/account/budgets/budgets.go +++ b/cmd/account/budgets/budgets.go @@ -98,26 +98,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No BUDGET_ID argument specified. Loading names for Budgets drop-down." - names, err := a.Budgets.BudgetWithStatusNameToBudgetIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Budgets drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Budget ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No BUDGET_ID argument specified. Loading names for Budgets drop-down." + names, err := a.Budgets.BudgetWithStatusNameToBudgetIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Budgets drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have budget id") + id, err := cmdio.Select(ctx, names, "Budget ID") + if err != nil { + return err } - deleteReq.BudgetId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have budget id") } + deleteReq.BudgetId = args[0] err = a.Budgets.Delete(ctx, deleteReq) if err != nil { @@ -160,26 +159,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No BUDGET_ID argument specified. Loading names for Budgets drop-down." - names, err := a.Budgets.BudgetWithStatusNameToBudgetIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Budgets drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Budget ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No BUDGET_ID argument specified. Loading names for Budgets drop-down." + names, err := a.Budgets.BudgetWithStatusNameToBudgetIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Budgets drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have budget id") + id, err := cmdio.Select(ctx, names, "Budget ID") + if err != nil { + return err } - getReq.BudgetId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have budget id") } + getReq.BudgetId = args[0] response, err := a.Budgets.Get(ctx, getReq) if err != nil { diff --git a/cmd/account/credentials/credentials.go b/cmd/account/credentials/credentials.go index c46595d5c8..b1ec7e1763 100755 --- a/cmd/account/credentials/credentials.go +++ b/cmd/account/credentials/credentials.go @@ -113,26 +113,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No CREDENTIALS_ID argument specified. Loading names for Credentials drop-down." - names, err := a.Credentials.CredentialCredentialsNameToCredentialsIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Credentials drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks Account API credential configuration ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No CREDENTIALS_ID argument specified. Loading names for Credentials drop-down." + names, err := a.Credentials.CredentialCredentialsNameToCredentialsIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Credentials drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks account api credential configuration id") + id, err := cmdio.Select(ctx, names, "Databricks Account API credential configuration ID") + if err != nil { + return err } - deleteReq.CredentialsId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks account api credential configuration id") } + deleteReq.CredentialsId = args[0] err = a.Credentials.Delete(ctx, deleteReq) if err != nil { @@ -175,26 +174,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No CREDENTIALS_ID argument specified. Loading names for Credentials drop-down." - names, err := a.Credentials.CredentialCredentialsNameToCredentialsIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Credentials drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks Account API credential configuration ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No CREDENTIALS_ID argument specified. Loading names for Credentials drop-down." + names, err := a.Credentials.CredentialCredentialsNameToCredentialsIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Credentials drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks account api credential configuration id") + id, err := cmdio.Select(ctx, names, "Databricks Account API credential configuration ID") + if err != nil { + return err } - getReq.CredentialsId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks account api credential configuration id") } + getReq.CredentialsId = args[0] response, err := a.Credentials.Get(ctx, getReq) if err != nil { diff --git a/cmd/account/custom-app-integration/custom-app-integration.go b/cmd/account/custom-app-integration/custom-app-integration.go index 4c836a5f91..6e4a496085 100755 --- a/cmd/account/custom-app-integration/custom-app-integration.go +++ b/cmd/account/custom-app-integration/custom-app-integration.go @@ -100,9 +100,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -114,9 +111,8 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteReq.IntegrationId = args[0] } + deleteReq.IntegrationId = args[0] err = a.CustomAppIntegration.Delete(ctx, deleteReq) if err != nil { @@ -151,9 +147,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -165,9 +158,8 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.IntegrationId = args[0] } + getReq.IntegrationId = args[0] response, err := a.CustomAppIntegration.Get(ctx, getReq) if err != nil { @@ -237,9 +229,6 @@ var updateCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -251,9 +240,8 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - updateReq.IntegrationId = args[0] } + updateReq.IntegrationId = args[0] err = a.CustomAppIntegration.Update(ctx, updateReq) if err != nil { diff --git a/cmd/account/encryption-keys/encryption-keys.go b/cmd/account/encryption-keys/encryption-keys.go index 0e8085f39b..aea1826773 100755 --- a/cmd/account/encryption-keys/encryption-keys.go +++ b/cmd/account/encryption-keys/encryption-keys.go @@ -122,9 +122,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -136,9 +133,8 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteReq.CustomerManagedKeyId = args[0] } + deleteReq.CustomerManagedKeyId = args[0] err = a.EncryptionKeys.Delete(ctx, deleteReq) if err != nil { @@ -187,9 +183,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -201,9 +194,8 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.CustomerManagedKeyId = args[0] } + getReq.CustomerManagedKeyId = args[0] response, err := a.EncryptionKeys.Get(ctx, getReq) if err != nil { diff --git a/cmd/account/groups/groups.go b/cmd/account/groups/groups.go index 1d5073f453..6174249797 100755 --- a/cmd/account/groups/groups.go +++ b/cmd/account/groups/groups.go @@ -116,26 +116,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Account Groups drop-down." - names, err := a.Groups.GroupDisplayNameToIdMap(ctx, iam.ListAccountGroupsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Groups drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks account") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Account Groups drop-down." + names, err := a.Groups.GroupDisplayNameToIdMap(ctx, iam.ListAccountGroupsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Groups drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks account") + id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks account") + if err != nil { + return err } - deleteReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a group in the databricks account") } + deleteReq.Id = args[0] err = a.Groups.Delete(ctx, deleteReq) if err != nil { @@ -177,26 +176,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Account Groups drop-down." - names, err := a.Groups.GroupDisplayNameToIdMap(ctx, iam.ListAccountGroupsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Groups drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks account") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Account Groups drop-down." + names, err := a.Groups.GroupDisplayNameToIdMap(ctx, iam.ListAccountGroupsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Groups drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks account") + id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks account") + if err != nil { + return err } - getReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a group in the databricks account") } + getReq.Id = args[0] response, err := a.Groups.Get(ctx, getReq) if err != nil { @@ -298,26 +296,25 @@ var patchCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Account Groups drop-down." - names, err := a.Groups.GroupDisplayNameToIdMap(ctx, iam.ListAccountGroupsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Groups drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks account") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Account Groups drop-down." + names, err := a.Groups.GroupDisplayNameToIdMap(ctx, iam.ListAccountGroupsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Groups drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks account") + id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks account") + if err != nil { + return err } - patchReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a group in the databricks account") } + patchReq.Id = args[0] err = a.Groups.Patch(ctx, patchReq) if err != nil { diff --git a/cmd/account/ip-access-lists/ip-access-lists.go b/cmd/account/ip-access-lists/ip-access-lists.go index 8eeacbbafd..8d0d4b7dcf 100755 --- a/cmd/account/ip-access-lists/ip-access-lists.go +++ b/cmd/account/ip-access-lists/ip-access-lists.go @@ -128,26 +128,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Account Ip Access Lists drop-down." - names, err := a.IpAccessLists.IpAccessListInfoLabelToListIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Ip Access Lists drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID for the corresponding IP access list") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Account Ip Access Lists drop-down." + names, err := a.IpAccessLists.IpAccessListInfoLabelToListIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Ip Access Lists drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the id for the corresponding ip access list") + id, err := cmdio.Select(ctx, names, "The ID for the corresponding IP access list") + if err != nil { + return err } - deleteReq.IpAccessListId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id for the corresponding ip access list") } + deleteReq.IpAccessListId = args[0] err = a.IpAccessLists.Delete(ctx, deleteReq) if err != nil { @@ -189,26 +188,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Account Ip Access Lists drop-down." - names, err := a.IpAccessLists.IpAccessListInfoLabelToListIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Ip Access Lists drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID for the corresponding IP access list") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Account Ip Access Lists drop-down." + names, err := a.IpAccessLists.IpAccessListInfoLabelToListIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Ip Access Lists drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the id for the corresponding ip access list") + id, err := cmdio.Select(ctx, names, "The ID for the corresponding IP access list") + if err != nil { + return err } - getReq.IpAccessListId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id for the corresponding ip access list") } + getReq.IpAccessListId = args[0] response, err := a.IpAccessLists.Get(ctx, getReq) if err != nil { diff --git a/cmd/account/log-delivery/log-delivery.go b/cmd/account/log-delivery/log-delivery.go index 0429127b08..c8472b0176 100755 --- a/cmd/account/log-delivery/log-delivery.go +++ b/cmd/account/log-delivery/log-delivery.go @@ -187,26 +187,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No LOG_DELIVERY_CONFIGURATION_ID argument specified. Loading names for Log Delivery drop-down." - names, err := a.LogDelivery.LogDeliveryConfigurationConfigNameToConfigIdMap(ctx, billing.ListLogDeliveryRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Log Delivery drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks log delivery configuration ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No LOG_DELIVERY_CONFIGURATION_ID argument specified. Loading names for Log Delivery drop-down." + names, err := a.LogDelivery.LogDeliveryConfigurationConfigNameToConfigIdMap(ctx, billing.ListLogDeliveryRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Log Delivery drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks log delivery configuration id") + id, err := cmdio.Select(ctx, names, "Databricks log delivery configuration ID") + if err != nil { + return err } - getReq.LogDeliveryConfigurationId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks log delivery configuration id") } + getReq.LogDeliveryConfigurationId = args[0] response, err := a.LogDelivery.Get(ctx, getReq) if err != nil { @@ -300,9 +299,6 @@ var patchStatusCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -314,13 +310,12 @@ var patchStatusCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &patchStatusReq.Status) - if err != nil { - return fmt.Errorf("invalid STATUS: %s", args[0]) - } - patchStatusReq.LogDeliveryConfigurationId = args[1] } + _, err = fmt.Sscan(args[0], &patchStatusReq.Status) + if err != nil { + return fmt.Errorf("invalid STATUS: %s", args[0]) + } + patchStatusReq.LogDeliveryConfigurationId = args[1] err = a.LogDelivery.PatchStatus(ctx, patchStatusReq) if err != nil { diff --git a/cmd/account/metastore-assignments/metastore-assignments.go b/cmd/account/metastore-assignments/metastore-assignments.go index 63b21893af..9e10bc214a 100755 --- a/cmd/account/metastore-assignments/metastore-assignments.go +++ b/cmd/account/metastore-assignments/metastore-assignments.go @@ -46,9 +46,6 @@ var createCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -60,13 +57,12 @@ var createCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &createReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } - createReq.MetastoreId = args[1] } + _, err = fmt.Sscan(args[0], &createReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) + } + createReq.MetastoreId = args[1] response, err := a.MetastoreAssignments.Create(ctx, createReq) if err != nil { @@ -103,9 +99,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -117,13 +110,12 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &deleteReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } - deleteReq.MetastoreId = args[1] } + _, err = fmt.Sscan(args[0], &deleteReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) + } + deleteReq.MetastoreId = args[1] err = a.MetastoreAssignments.Delete(ctx, deleteReq) if err != nil { @@ -162,9 +154,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -176,11 +165,10 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &getReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } + } + _, err = fmt.Sscan(args[0], &getReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) } response, err := a.MetastoreAssignments.Get(ctx, getReq) @@ -218,9 +206,6 @@ var listCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -232,9 +217,8 @@ var listCmd = &cobra.Command{ if err != nil { return err } - } else { - listReq.MetastoreId = args[0] } + listReq.MetastoreId = args[0] response, err := a.MetastoreAssignments.List(ctx, listReq) if err != nil { @@ -273,9 +257,6 @@ var updateCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -287,13 +268,12 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &updateReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } - updateReq.MetastoreId = args[1] } + _, err = fmt.Sscan(args[0], &updateReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) + } + updateReq.MetastoreId = args[1] err = a.MetastoreAssignments.Update(ctx, updateReq) if err != nil { diff --git a/cmd/account/metastores/metastores.go b/cmd/account/metastores/metastores.go index e270b946f3..ad8a4be7b7 100755 --- a/cmd/account/metastores/metastores.go +++ b/cmd/account/metastores/metastores.go @@ -96,9 +96,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -110,9 +107,8 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteReq.MetastoreId = args[0] } + deleteReq.MetastoreId = args[0] err = a.Metastores.Delete(ctx, deleteReq) if err != nil { @@ -148,9 +144,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -162,9 +155,8 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.MetastoreId = args[0] } + getReq.MetastoreId = args[0] response, err := a.Metastores.Get(ctx, getReq) if err != nil { @@ -234,9 +226,6 @@ var updateCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -248,9 +237,8 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - updateReq.MetastoreId = args[0] } + updateReq.MetastoreId = args[0] response, err := a.Metastores.Update(ctx, updateReq) if err != nil { diff --git a/cmd/account/networks/networks.go b/cmd/account/networks/networks.go index b0214146dc..a12b27f7e0 100755 --- a/cmd/account/networks/networks.go +++ b/cmd/account/networks/networks.go @@ -115,26 +115,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NETWORK_ID argument specified. Loading names for Networks drop-down." - names, err := a.Networks.NetworkNetworkNameToNetworkIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Networks drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks Account API network configuration ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NETWORK_ID argument specified. Loading names for Networks drop-down." + names, err := a.Networks.NetworkNetworkNameToNetworkIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Networks drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks account api network configuration id") + id, err := cmdio.Select(ctx, names, "Databricks Account API network configuration ID") + if err != nil { + return err } - deleteReq.NetworkId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks account api network configuration id") } + deleteReq.NetworkId = args[0] err = a.Networks.Delete(ctx, deleteReq) if err != nil { @@ -177,26 +176,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NETWORK_ID argument specified. Loading names for Networks drop-down." - names, err := a.Networks.NetworkNetworkNameToNetworkIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Networks drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks Account API network configuration ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NETWORK_ID argument specified. Loading names for Networks drop-down." + names, err := a.Networks.NetworkNetworkNameToNetworkIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Networks drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks account api network configuration id") + id, err := cmdio.Select(ctx, names, "Databricks Account API network configuration ID") + if err != nil { + return err } - getReq.NetworkId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks account api network configuration id") } + getReq.NetworkId = args[0] response, err := a.Networks.Get(ctx, getReq) if err != nil { diff --git a/cmd/account/private-access/private-access.go b/cmd/account/private-access/private-access.go index 6c35354f03..f9e3bd1480 100755 --- a/cmd/account/private-access/private-access.go +++ b/cmd/account/private-access/private-access.go @@ -127,26 +127,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No PRIVATE_ACCESS_SETTINGS_ID argument specified. Loading names for Private Access drop-down." - names, err := a.PrivateAccess.PrivateAccessSettingsPrivateAccessSettingsNameToPrivateAccessSettingsIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Private Access drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks Account API private access settings ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No PRIVATE_ACCESS_SETTINGS_ID argument specified. Loading names for Private Access drop-down." + names, err := a.PrivateAccess.PrivateAccessSettingsPrivateAccessSettingsNameToPrivateAccessSettingsIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Private Access drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks account api private access settings id") + id, err := cmdio.Select(ctx, names, "Databricks Account API private access settings ID") + if err != nil { + return err } - deleteReq.PrivateAccessSettingsId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks account api private access settings id") } + deleteReq.PrivateAccessSettingsId = args[0] err = a.PrivateAccess.Delete(ctx, deleteReq) if err != nil { @@ -195,26 +194,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No PRIVATE_ACCESS_SETTINGS_ID argument specified. Loading names for Private Access drop-down." - names, err := a.PrivateAccess.PrivateAccessSettingsPrivateAccessSettingsNameToPrivateAccessSettingsIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Private Access drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks Account API private access settings ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No PRIVATE_ACCESS_SETTINGS_ID argument specified. Loading names for Private Access drop-down." + names, err := a.PrivateAccess.PrivateAccessSettingsPrivateAccessSettingsNameToPrivateAccessSettingsIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Private Access drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks account api private access settings id") + id, err := cmdio.Select(ctx, names, "Databricks Account API private access settings ID") + if err != nil { + return err } - getReq.PrivateAccessSettingsId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks account api private access settings id") } + getReq.PrivateAccessSettingsId = args[0] response, err := a.PrivateAccess.Get(ctx, getReq) if err != nil { @@ -304,9 +302,6 @@ var replaceCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(3) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -318,11 +313,10 @@ var replaceCmd = &cobra.Command{ if err != nil { return err } - } else { - replaceReq.PrivateAccessSettingsName = args[0] - replaceReq.Region = args[1] - replaceReq.PrivateAccessSettingsId = args[2] } + replaceReq.PrivateAccessSettingsName = args[0] + replaceReq.Region = args[1] + replaceReq.PrivateAccessSettingsId = args[2] err = a.PrivateAccess.Replace(ctx, replaceReq) if err != nil { diff --git a/cmd/account/published-app-integration/published-app-integration.go b/cmd/account/published-app-integration/published-app-integration.go index 6280f5ccf5..f0a02b6cfe 100755 --- a/cmd/account/published-app-integration/published-app-integration.go +++ b/cmd/account/published-app-integration/published-app-integration.go @@ -104,9 +104,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -118,9 +115,8 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteReq.IntegrationId = args[0] } + deleteReq.IntegrationId = args[0] err = a.PublishedAppIntegration.Delete(ctx, deleteReq) if err != nil { @@ -155,9 +151,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -169,9 +162,8 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.IntegrationId = args[0] } + getReq.IntegrationId = args[0] response, err := a.PublishedAppIntegration.Get(ctx, getReq) if err != nil { @@ -240,9 +232,6 @@ var updateCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -254,9 +243,8 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - updateReq.IntegrationId = args[0] } + updateReq.IntegrationId = args[0] err = a.PublishedAppIntegration.Update(ctx, updateReq) if err != nil { diff --git a/cmd/account/service-principal-secrets/service-principal-secrets.go b/cmd/account/service-principal-secrets/service-principal-secrets.go index 5cf5d4535e..8cae113e31 100755 --- a/cmd/account/service-principal-secrets/service-principal-secrets.go +++ b/cmd/account/service-principal-secrets/service-principal-secrets.go @@ -55,9 +55,6 @@ var createCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -69,11 +66,10 @@ var createCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &createReq.ServicePrincipalId) - if err != nil { - return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0]) - } + } + _, err = fmt.Sscan(args[0], &createReq.ServicePrincipalId) + if err != nil { + return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0]) } response, err := a.ServicePrincipalSecrets.Create(ctx, createReq) @@ -109,9 +105,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -123,13 +116,12 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &deleteReq.ServicePrincipalId) - if err != nil { - return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0]) - } - deleteReq.SecretId = args[1] } + _, err = fmt.Sscan(args[0], &deleteReq.ServicePrincipalId) + if err != nil { + return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0]) + } + deleteReq.SecretId = args[1] err = a.ServicePrincipalSecrets.Delete(ctx, deleteReq) if err != nil { @@ -166,9 +158,6 @@ var listCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -180,11 +169,10 @@ var listCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &listReq.ServicePrincipalId) - if err != nil { - return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0]) - } + } + _, err = fmt.Sscan(args[0], &listReq.ServicePrincipalId) + if err != nil { + return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0]) } response, err := a.ServicePrincipalSecrets.ListAll(ctx, listReq) diff --git a/cmd/account/service-principals/service-principals.go b/cmd/account/service-principals/service-principals.go index df969b5ed8..af9d3ec322 100755 --- a/cmd/account/service-principals/service-principals.go +++ b/cmd/account/service-principals/service-principals.go @@ -114,26 +114,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Account Service Principals drop-down." - names, err := a.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListAccountServicePrincipalsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks account") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Account Service Principals drop-down." + names, err := a.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListAccountServicePrincipalsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks account") + id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks account") + if err != nil { + return err } - deleteReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a service principal in the databricks account") } + deleteReq.Id = args[0] err = a.ServicePrincipals.Delete(ctx, deleteReq) if err != nil { @@ -176,26 +175,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Account Service Principals drop-down." - names, err := a.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListAccountServicePrincipalsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks account") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Account Service Principals drop-down." + names, err := a.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListAccountServicePrincipalsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks account") + id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks account") + if err != nil { + return err } - getReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a service principal in the databricks account") } + getReq.Id = args[0] response, err := a.ServicePrincipals.Get(ctx, getReq) if err != nil { @@ -298,26 +296,25 @@ var patchCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Account Service Principals drop-down." - names, err := a.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListAccountServicePrincipalsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks account") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Account Service Principals drop-down." + names, err := a.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListAccountServicePrincipalsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks account") + id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks account") + if err != nil { + return err } - patchReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a service principal in the databricks account") } + patchReq.Id = args[0] err = a.ServicePrincipals.Patch(ctx, patchReq) if err != nil { diff --git a/cmd/account/storage-credentials/storage-credentials.go b/cmd/account/storage-credentials/storage-credentials.go index 3baabaccc0..ef753983ee 100755 --- a/cmd/account/storage-credentials/storage-credentials.go +++ b/cmd/account/storage-credentials/storage-credentials.go @@ -49,9 +49,6 @@ var createCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -63,9 +60,8 @@ var createCmd = &cobra.Command{ if err != nil { return err } - } else { - createReq.MetastoreId = args[0] } + createReq.MetastoreId = args[0] response, err := a.StorageCredentials.Create(ctx, createReq) if err != nil { @@ -101,9 +97,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -115,10 +108,9 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteReq.MetastoreId = args[0] - deleteReq.Name = args[1] } + deleteReq.MetastoreId = args[0] + deleteReq.Name = args[1] err = a.StorageCredentials.Delete(ctx, deleteReq) if err != nil { @@ -155,9 +147,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -169,10 +158,9 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.MetastoreId = args[0] - getReq.Name = args[1] } + getReq.MetastoreId = args[0] + getReq.Name = args[1] response, err := a.StorageCredentials.Get(ctx, getReq) if err != nil { @@ -208,9 +196,6 @@ var listCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -222,9 +207,8 @@ var listCmd = &cobra.Command{ if err != nil { return err } - } else { - listReq.MetastoreId = args[0] } + listReq.MetastoreId = args[0] response, err := a.StorageCredentials.List(ctx, listReq) if err != nil { @@ -263,9 +247,6 @@ var updateCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -277,10 +258,9 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - updateReq.MetastoreId = args[0] - updateReq.Name = args[1] } + updateReq.MetastoreId = args[0] + updateReq.Name = args[1] response, err := a.StorageCredentials.Update(ctx, updateReq) if err != nil { diff --git a/cmd/account/storage/storage.go b/cmd/account/storage/storage.go index 9911d6af84..d83c8b400b 100755 --- a/cmd/account/storage/storage.go +++ b/cmd/account/storage/storage.go @@ -109,26 +109,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No STORAGE_CONFIGURATION_ID argument specified. Loading names for Storage drop-down." - names, err := a.Storage.StorageConfigurationStorageConfigurationNameToStorageConfigurationIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Storage drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks Account API storage configuration ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No STORAGE_CONFIGURATION_ID argument specified. Loading names for Storage drop-down." + names, err := a.Storage.StorageConfigurationStorageConfigurationNameToStorageConfigurationIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Storage drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks account api storage configuration id") + id, err := cmdio.Select(ctx, names, "Databricks Account API storage configuration ID") + if err != nil { + return err } - deleteReq.StorageConfigurationId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks account api storage configuration id") } + deleteReq.StorageConfigurationId = args[0] err = a.Storage.Delete(ctx, deleteReq) if err != nil { @@ -170,26 +169,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No STORAGE_CONFIGURATION_ID argument specified. Loading names for Storage drop-down." - names, err := a.Storage.StorageConfigurationStorageConfigurationNameToStorageConfigurationIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Storage drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks Account API storage configuration ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No STORAGE_CONFIGURATION_ID argument specified. Loading names for Storage drop-down." + names, err := a.Storage.StorageConfigurationStorageConfigurationNameToStorageConfigurationIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Storage drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks account api storage configuration id") + id, err := cmdio.Select(ctx, names, "Databricks Account API storage configuration ID") + if err != nil { + return err } - getReq.StorageConfigurationId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks account api storage configuration id") } + getReq.StorageConfigurationId = args[0] response, err := a.Storage.Get(ctx, getReq) if err != nil { diff --git a/cmd/account/users/users.go b/cmd/account/users/users.go index 981f143ef3..aff3ed1475 100755 --- a/cmd/account/users/users.go +++ b/cmd/account/users/users.go @@ -123,26 +123,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Account Users drop-down." - names, err := a.Users.UserUserNameToIdMap(ctx, iam.ListAccountUsersRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Users drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks account") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Account Users drop-down." + names, err := a.Users.UserUserNameToIdMap(ctx, iam.ListAccountUsersRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Users drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks account") + id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks account") + if err != nil { + return err } - deleteReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a user in the databricks account") } + deleteReq.Id = args[0] err = a.Users.Delete(ctx, deleteReq) if err != nil { @@ -184,26 +183,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Account Users drop-down." - names, err := a.Users.UserUserNameToIdMap(ctx, iam.ListAccountUsersRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Users drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks account") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Account Users drop-down." + names, err := a.Users.UserUserNameToIdMap(ctx, iam.ListAccountUsersRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Users drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks account") + id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks account") + if err != nil { + return err } - getReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a user in the databricks account") } + getReq.Id = args[0] response, err := a.Users.Get(ctx, getReq) if err != nil { @@ -306,26 +304,25 @@ var patchCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Account Users drop-down." - names, err := a.Users.UserUserNameToIdMap(ctx, iam.ListAccountUsersRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Account Users drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks account") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Account Users drop-down." + names, err := a.Users.UserUserNameToIdMap(ctx, iam.ListAccountUsersRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Account Users drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks account") + id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks account") + if err != nil { + return err } - patchReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a user in the databricks account") } + patchReq.Id = args[0] err = a.Users.Patch(ctx, patchReq) if err != nil { diff --git a/cmd/account/vpc-endpoints/vpc-endpoints.go b/cmd/account/vpc-endpoints/vpc-endpoints.go index d04559eb2c..276b030a62 100755 --- a/cmd/account/vpc-endpoints/vpc-endpoints.go +++ b/cmd/account/vpc-endpoints/vpc-endpoints.go @@ -125,26 +125,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No VPC_ENDPOINT_ID argument specified. Loading names for Vpc Endpoints drop-down." - names, err := a.VpcEndpoints.VpcEndpointVpcEndpointNameToVpcEndpointIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Vpc Endpoints drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks VPC endpoint ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No VPC_ENDPOINT_ID argument specified. Loading names for Vpc Endpoints drop-down." + names, err := a.VpcEndpoints.VpcEndpointVpcEndpointNameToVpcEndpointIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Vpc Endpoints drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks vpc endpoint id") + id, err := cmdio.Select(ctx, names, "Databricks VPC endpoint ID") + if err != nil { + return err } - deleteReq.VpcEndpointId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks vpc endpoint id") } + deleteReq.VpcEndpointId = args[0] err = a.VpcEndpoints.Delete(ctx, deleteReq) if err != nil { @@ -190,26 +189,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No VPC_ENDPOINT_ID argument specified. Loading names for Vpc Endpoints drop-down." - names, err := a.VpcEndpoints.VpcEndpointVpcEndpointNameToVpcEndpointIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Vpc Endpoints drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Databricks VPC endpoint ID") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No VPC_ENDPOINT_ID argument specified. Loading names for Vpc Endpoints drop-down." + names, err := a.VpcEndpoints.VpcEndpointVpcEndpointNameToVpcEndpointIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Vpc Endpoints drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have databricks vpc endpoint id") + id, err := cmdio.Select(ctx, names, "Databricks VPC endpoint ID") + if err != nil { + return err } - getReq.VpcEndpointId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have databricks vpc endpoint id") } + getReq.VpcEndpointId = args[0] response, err := a.VpcEndpoints.Get(ctx, getReq) if err != nil { diff --git a/cmd/account/workspace-assignment/workspace-assignment.go b/cmd/account/workspace-assignment/workspace-assignment.go index 36374961cb..18de0c0c40 100755 --- a/cmd/account/workspace-assignment/workspace-assignment.go +++ b/cmd/account/workspace-assignment/workspace-assignment.go @@ -45,9 +45,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -59,15 +56,14 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &deleteReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } - _, err = fmt.Sscan(args[1], &deleteReq.PrincipalId) - if err != nil { - return fmt.Errorf("invalid PRINCIPAL_ID: %s", args[1]) - } + } + _, err = fmt.Sscan(args[0], &deleteReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) + } + _, err = fmt.Sscan(args[1], &deleteReq.PrincipalId) + if err != nil { + return fmt.Errorf("invalid PRINCIPAL_ID: %s", args[1]) } err = a.WorkspaceAssignment.Delete(ctx, deleteReq) @@ -103,9 +99,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -117,11 +110,10 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &getReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } + } + _, err = fmt.Sscan(args[0], &getReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) } response, err := a.WorkspaceAssignment.Get(ctx, getReq) @@ -158,9 +150,6 @@ var listCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustAccountClient, @@ -172,11 +161,10 @@ var listCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &listReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } + } + _, err = fmt.Sscan(args[0], &listReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) } response, err := a.WorkspaceAssignment.ListAll(ctx, listReq) diff --git a/cmd/account/workspaces/workspaces.go b/cmd/account/workspaces/workspaces.go index 76189dc467..750570f5e6 100755 --- a/cmd/account/workspaces/workspaces.go +++ b/cmd/account/workspaces/workspaces.go @@ -154,28 +154,27 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Workspaces drop-down." - names, err := a.Workspaces.WorkspaceWorkspaceNameToWorkspaceIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Workspaces drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Workspace ID") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have workspace id") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Workspaces drop-down." + names, err := a.Workspaces.WorkspaceWorkspaceNameToWorkspaceIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Workspaces drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &deleteReq.WorkspaceId) + id, err := cmdio.Select(ctx, names, "Workspace ID") if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have workspace id") + } + _, err = fmt.Sscan(args[0], &deleteReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) } err = a.Workspaces.Delete(ctx, deleteReq) @@ -231,28 +230,27 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Workspaces drop-down." - names, err := a.Workspaces.WorkspaceWorkspaceNameToWorkspaceIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Workspaces drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Workspace ID") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have workspace id") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Workspaces drop-down." + names, err := a.Workspaces.WorkspaceWorkspaceNameToWorkspaceIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Workspaces drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &getReq.WorkspaceId) + id, err := cmdio.Select(ctx, names, "Workspace ID") if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have workspace id") + } + _, err = fmt.Sscan(args[0], &getReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) } response, err := a.Workspaces.Get(ctx, getReq) @@ -451,28 +449,27 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Workspaces drop-down." - names, err := a.Workspaces.WorkspaceWorkspaceNameToWorkspaceIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Workspaces drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Workspace ID") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have workspace id") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Workspaces drop-down." + names, err := a.Workspaces.WorkspaceWorkspaceNameToWorkspaceIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Workspaces drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &updateReq.WorkspaceId) + id, err := cmdio.Select(ctx, names, "Workspace ID") if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have workspace id") + } + _, err = fmt.Sscan(args[0], &updateReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) } wait, err := a.Workspaces.Update(ctx, updateReq) diff --git a/cmd/workspace/access-control-proxy/access-control-proxy.go b/cmd/workspace/access-control-proxy/access-control-proxy.go new file mode 100755 index 0000000000..8f1159c87c --- /dev/null +++ b/cmd/workspace/access-control-proxy/access-control-proxy.go @@ -0,0 +1,172 @@ +// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. + +package access_control_proxy + +import ( + "fmt" + + "github.com/databricks/cli/cmd/root" + "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/flags" + "github.com/databricks/databricks-sdk-go/service/iam" + "github.com/spf13/cobra" +) + +var Cmd = &cobra.Command{ + Use: "access-control-proxy", + Short: `These APIs manage access rules on resources in an account.`, + Long: `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. A + workspace must belong to an account for these APIs to work.`, + Annotations: map[string]string{ + "package": "iam", + }, +} + +// start get-assignable-roles-for-resource command + +var getAssignableRolesForResourceReq iam.GetAssignableRolesForResourceRequest +var getAssignableRolesForResourceJson flags.JsonFlag + +func init() { + Cmd.AddCommand(getAssignableRolesForResourceCmd) + // TODO: short flags + getAssignableRolesForResourceCmd.Flags().Var(&getAssignableRolesForResourceJson, "json", `either inline JSON string or @path/to/file.json with request body`) + +} + +var getAssignableRolesForResourceCmd = &cobra.Command{ + Use: "get-assignable-roles-for-resource RESOURCE", + Short: `Get assignable roles for a resource.`, + Long: `Get assignable roles for a resource. + + Gets all the roles that can be granted on an account-level resource. A role is + grantable if the rule set on the resource can contain an access rule of the + role.`, + + Annotations: map[string]string{}, + Args: func(cmd *cobra.Command, args []string) error { + check := cobra.ExactArgs(1) + return check(cmd, args) + }, + PreRunE: root.MustWorkspaceClient, + RunE: func(cmd *cobra.Command, args []string) (err error) { + ctx := cmd.Context() + w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { + err = getAssignableRolesForResourceJson.Unmarshal(&getAssignableRolesForResourceReq) + if err != nil { + return err + } + } + getAssignableRolesForResourceReq.Resource = args[0] + + response, err := w.AccessControlProxy.GetAssignableRolesForResource(ctx, getAssignableRolesForResourceReq) + if err != nil { + return err + } + return cmdio.Render(ctx, response) + }, + // Disable completions since they are not applicable. + // Can be overridden by manual implementation in `override.go`. + ValidArgsFunction: cobra.NoFileCompletions, +} + +// start get-rule-set command + +var getRuleSetReq iam.GetRuleSetRequest +var getRuleSetJson flags.JsonFlag + +func init() { + Cmd.AddCommand(getRuleSetCmd) + // TODO: short flags + getRuleSetCmd.Flags().Var(&getRuleSetJson, "json", `either inline JSON string or @path/to/file.json with request body`) + +} + +var getRuleSetCmd = &cobra.Command{ + Use: "get-rule-set NAME ETAG", + Short: `Get a rule set.`, + Long: `Get a rule set. + + Get a rule set by its name. A rule set is always attached to a resource and + contains a list of access rules on the said resource. Currently only a default + rule set for each resource is supported.`, + + Annotations: map[string]string{}, + Args: func(cmd *cobra.Command, args []string) error { + check := cobra.ExactArgs(2) + return check(cmd, args) + }, + PreRunE: root.MustWorkspaceClient, + RunE: func(cmd *cobra.Command, args []string) (err error) { + ctx := cmd.Context() + w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { + err = getRuleSetJson.Unmarshal(&getRuleSetReq) + if err != nil { + return err + } + } + getRuleSetReq.Name = args[0] + getRuleSetReq.Etag = args[1] + + response, err := w.AccessControlProxy.GetRuleSet(ctx, getRuleSetReq) + if err != nil { + return err + } + return cmdio.Render(ctx, response) + }, + // Disable completions since they are not applicable. + // Can be overridden by manual implementation in `override.go`. + ValidArgsFunction: cobra.NoFileCompletions, +} + +// start update-rule-set command + +var updateRuleSetReq iam.UpdateRuleSetRequest +var updateRuleSetJson flags.JsonFlag + +func init() { + Cmd.AddCommand(updateRuleSetCmd) + // TODO: short flags + updateRuleSetCmd.Flags().Var(&updateRuleSetJson, "json", `either inline JSON string or @path/to/file.json with request body`) + +} + +var updateRuleSetCmd = &cobra.Command{ + Use: "update-rule-set", + Short: `Update a rule set.`, + Long: `Update a rule set. + + Replace the rules of a rule set. First, use a GET rule set request to read the + current version of the rule set before modifying it. This pattern helps + prevent conflicts between concurrent updates.`, + + Annotations: map[string]string{}, + PreRunE: root.MustWorkspaceClient, + RunE: func(cmd *cobra.Command, args []string) (err error) { + ctx := cmd.Context() + w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { + err = updateRuleSetJson.Unmarshal(&updateRuleSetReq) + if err != nil { + return err + } + } else { + return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") + } + + response, err := w.AccessControlProxy.UpdateRuleSet(ctx, updateRuleSetReq) + if err != nil { + return err + } + return cmdio.Render(ctx, response) + }, + // Disable completions since they are not applicable. + // Can be overridden by manual implementation in `override.go`. + ValidArgsFunction: cobra.NoFileCompletions, +} + +// end service AccountAccessControlProxy diff --git a/cmd/workspace/alerts/alerts.go b/cmd/workspace/alerts/alerts.go index a926e836bd..fb5db952c0 100755 --- a/cmd/workspace/alerts/alerts.go +++ b/cmd/workspace/alerts/alerts.go @@ -105,26 +105,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ALERT_ID argument specified. Loading names for Alerts drop-down." - names, err := w.Alerts.AlertNameToIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Alerts drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ALERT_ID argument specified. Loading names for Alerts drop-down." + names, err := w.Alerts.AlertNameToIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Alerts drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - deleteReq.AlertId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + deleteReq.AlertId = args[0] err = w.Alerts.Delete(ctx, deleteReq) if err != nil { @@ -166,26 +165,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ALERT_ID argument specified. Loading names for Alerts drop-down." - names, err := w.Alerts.AlertNameToIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Alerts drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ALERT_ID argument specified. Loading names for Alerts drop-down." + names, err := w.Alerts.AlertNameToIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Alerts drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - getReq.AlertId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + getReq.AlertId = args[0] response, err := w.Alerts.Get(ctx, getReq) if err != nil { diff --git a/cmd/workspace/catalogs/catalogs.go b/cmd/workspace/catalogs/catalogs.go index 0f3ef061ff..9f39bed9df 100755 --- a/cmd/workspace/catalogs/catalogs.go +++ b/cmd/workspace/catalogs/catalogs.go @@ -109,9 +109,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -123,9 +120,8 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteReq.Name = args[0] } + deleteReq.Name = args[0] err = w.Catalogs.Delete(ctx, deleteReq) if err != nil { @@ -162,9 +158,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -176,9 +169,8 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.Name = args[0] } + getReq.Name = args[0] response, err := w.Catalogs.Get(ctx, getReq) if err != nil { diff --git a/cmd/workspace/cluster-policies/cluster-policies.go b/cmd/workspace/cluster-policies/cluster-policies.go index 5dff6aec16..6b22209c97 100755 --- a/cmd/workspace/cluster-policies/cluster-policies.go +++ b/cmd/workspace/cluster-policies/cluster-policies.go @@ -251,26 +251,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No POLICY_ID argument specified. Loading names for Cluster Policies drop-down." - names, err := w.ClusterPolicies.PolicyNameToPolicyIdMap(ctx, compute.ListClusterPoliciesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Cluster Policies drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Canonical unique identifier for the cluster policy") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No POLICY_ID argument specified. Loading names for Cluster Policies drop-down." + names, err := w.ClusterPolicies.PolicyNameToPolicyIdMap(ctx, compute.ListClusterPoliciesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Cluster Policies drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have canonical unique identifier for the cluster policy") + id, err := cmdio.Select(ctx, names, "Canonical unique identifier for the cluster policy") + if err != nil { + return err } - getReq.PolicyId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have canonical unique identifier for the cluster policy") } + getReq.PolicyId = args[0] response, err := w.ClusterPolicies.Get(ctx, getReq) if err != nil { diff --git a/cmd/workspace/clusters/clusters.go b/cmd/workspace/clusters/clusters.go index 841a4016cc..80106782fc 100755 --- a/cmd/workspace/clusters/clusters.go +++ b/cmd/workspace/clusters/clusters.go @@ -18,26 +18,26 @@ var Cmd = &cobra.Command{ 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 delete clusters. - + Databricks maps cluster node instance types to compute units known as DBUs. See the instance type pricing page for a list of the supported instance types and their corresponding DBUs. - + A Databricks cluster is a set of computation resources and configurations on which you run data engineering, data science, and data analytics workloads, such as production ETL pipelines, streaming analytics, ad-hoc analytics, and machine learning. - + You run these workloads as a set of commands in a notebook or as an automated job. Databricks makes a distinction between all-purpose clusters and job clusters. You use all-purpose clusters to analyze data collaboratively using interactive notebooks. You use job clusters to run fast and robust automated jobs. - + You can create an all-purpose cluster using the UI, CLI, or REST API. You can manually terminate and restart an all-purpose cluster. Multiple users can share such clusters to do collaborative interactive analysis. - + IMPORTANT: Databricks retains cluster configuration information for up to 200 all-purpose clusters terminated in the last 30 days and up to 30 job clusters recently terminated by the job scheduler. To keep an all-purpose cluster @@ -64,7 +64,7 @@ var changeOwnerCmd = &cobra.Command{ Use: "change-owner CLUSTER_ID OWNER_USERNAME", Short: `Change cluster owner.`, Long: `Change cluster owner. - + Change the owner of the cluster. You must be an admin to perform this operation.`, @@ -147,12 +147,12 @@ var createCmd = &cobra.Command{ Use: "create SPARK_VERSION", Short: `Create new cluster.`, Long: `Create new cluster. - + Creates a new Spark cluster. This method will acquire new instances from the cloud provider if necessary. Note: Databricks may not be able to acquire some of the requested nodes, due to cloud provider limitations (account limits, spot price, etc.) or transient network issues. - + If Databricks acquires at least 85% of the requested on-demand nodes, cluster creation will succeed. Otherwise the cluster will terminate with an informative error message.`, @@ -222,7 +222,7 @@ var deleteCmd = &cobra.Command{ Use: "delete CLUSTER_ID", Short: `Terminate cluster.`, Long: `Terminate cluster. - + Terminates the Spark cluster with the specified ID. The cluster is removed asynchronously. Once the termination has completed, the cluster will be in a TERMINATED state. If the cluster is already in a TERMINATING or @@ -331,18 +331,18 @@ var editCmd = &cobra.Command{ Use: "edit CLUSTER_ID SPARK_VERSION", Short: `Update cluster configuration.`, Long: `Update cluster configuration. - + Updates the configuration of a cluster to match the provided attributes and size. A cluster can be updated if it is in a RUNNING or TERMINATED state. - + If a cluster is updated while in a RUNNING state, it will be restarted so that the new attributes can take effect. - + If a cluster is updated while in a TERMINATED state, it will remain TERMINATED. The next time it is started using the clusters/start API, the new attributes will take effect. Any attempt to update a cluster in any other state will be rejected with an INVALID_STATE error code. - + Clusters created by the Databricks Jobs service cannot be edited.`, Annotations: map[string]string{}, @@ -413,7 +413,7 @@ var eventsCmd = &cobra.Command{ Use: "events CLUSTER_ID", Short: `List cluster activity events.`, Long: `List cluster activity events. - + Retrieves a list of events about the activity of a cluster. This API is paginated. If there are more events to read, the response includes all the nparameters necessary to request the next page of events.`, @@ -481,7 +481,7 @@ var getCmd = &cobra.Command{ Use: "get CLUSTER_ID", Short: `Get cluster info.`, Long: `Get cluster info. - + Retrieves the information for a cluster given its identifier. Clusters can be described while they are running, or up to 60 days after they are terminated.`, @@ -495,26 +495,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No CLUSTER_ID argument specified. Loading names for Clusters drop-down." - names, err := w.Clusters.ClusterDetailsClusterNameToClusterIdMap(ctx, compute.ListClustersRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Clusters drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The cluster about which to retrieve information") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No CLUSTER_ID argument specified. Loading names for Clusters drop-down." + names, err := w.Clusters.ClusterDetailsClusterNameToClusterIdMap(ctx, compute.ListClustersRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Clusters drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the cluster about which to retrieve information") + id, err := cmdio.Select(ctx, names, "The cluster about which to retrieve information") + if err != nil { + return err } - getReq.ClusterId = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have the cluster about which to retrieve information") + } + getReq.ClusterId = args[0] response, err := w.Clusters.Get(ctx, getReq) if err != nil { @@ -545,11 +544,11 @@ var listCmd = &cobra.Command{ Use: "list", Short: `List all clusters.`, Long: `List all clusters. - + Return information about all pinned clusters, active clusters, up to 200 of the most recently terminated all-purpose clusters in the past 30 days, and up to 30 of the most recently terminated job clusters in the past 30 days. - + For example, if there is 1 pinned cluster, 4 active clusters, 45 terminated all-purpose clusters in the past 30 days, and 50 terminated job clusters in the past 30 days, then this API returns the 1 pinned cluster, 4 active @@ -598,7 +597,7 @@ var listNodeTypesCmd = &cobra.Command{ Use: "list-node-types", Short: `List node types.`, Long: `List node types. - + Returns a list of supported Spark node types. These node types can be used to launch a cluster.`, @@ -629,7 +628,7 @@ var listZonesCmd = &cobra.Command{ Use: "list-zones", Short: `List availability zones.`, Long: `List availability zones. - + Returns a list of availability zones where clusters can be created in (For example, us-west-2a). These zones can be used to launch a cluster.`, @@ -665,10 +664,10 @@ var permanentDeleteCmd = &cobra.Command{ Use: "permanent-delete CLUSTER_ID", Short: `Permanently delete cluster.`, Long: `Permanently delete cluster. - + Permanently deletes a Spark cluster. This cluster is terminated and resources are asynchronously removed. - + In addition, users will no longer see permanently deleted clusters in the cluster list, and API users can no longer perform any action on permanently deleted clusters.`, @@ -731,7 +730,7 @@ var pinCmd = &cobra.Command{ Use: "pin CLUSTER_ID", Short: `Pin cluster.`, Long: `Pin cluster. - + Pinning a cluster ensures that the cluster will always be returned by the ListClusters API. Pinning a cluster that is already pinned will have no effect. This API can only be called by workspace admins.`, @@ -802,7 +801,7 @@ var resizeCmd = &cobra.Command{ Use: "resize CLUSTER_ID", Short: `Resize cluster.`, Long: `Resize cluster. - + Resizes a cluster to have a desired number of workers. This will fail unless the cluster is in a RUNNING state.`, @@ -883,7 +882,7 @@ var restartCmd = &cobra.Command{ Use: "restart CLUSTER_ID", Short: `Restart cluster.`, Long: `Restart cluster. - + Restarts a Spark cluster with the supplied ID. If the cluster is not currently in a RUNNING state, nothing will happen.`, @@ -952,7 +951,7 @@ var sparkVersionsCmd = &cobra.Command{ Use: "spark-versions", Short: `List available Spark versions.`, Long: `List available Spark versions. - + Returns the list of available Spark versions. These versions can be used to launch a cluster.`, @@ -993,10 +992,10 @@ var startCmd = &cobra.Command{ Use: "start CLUSTER_ID", Short: `Start terminated cluster.`, Long: `Start terminated cluster. - + Starts a terminated Spark cluster with the supplied ID. This works similar to createCluster except: - + * The previous cluster id and attributes are preserved. * The cluster starts with the last specified cluster size. * If the previous cluster was an autoscaling cluster, the current cluster starts with the minimum number of @@ -1073,7 +1072,7 @@ var unpinCmd = &cobra.Command{ Use: "unpin CLUSTER_ID", Short: `Unpin cluster.`, Long: `Unpin cluster. - + Unpinning a cluster will allow the cluster to eventually be removed from the ListClusters API. Unpinning a cluster that is not pinned will have no effect. This API can only be called by workspace admins.`, diff --git a/cmd/workspace/connections/connections.go b/cmd/workspace/connections/connections.go index 2bb459d6ee..6fd05acea6 100755 --- a/cmd/workspace/connections/connections.go +++ b/cmd/workspace/connections/connections.go @@ -116,26 +116,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME_ARG argument specified. Loading names for Connections drop-down." - names, err := w.Connections.ConnectionInfoNameToFullNameMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Connections drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The name of the connection to be deleted") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME_ARG argument specified. Loading names for Connections drop-down." + names, err := w.Connections.ConnectionInfoNameToFullNameMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Connections drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the name of the connection to be deleted") + id, err := cmdio.Select(ctx, names, "The name of the connection to be deleted") + if err != nil { + return err } - deleteReq.NameArg = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the name of the connection to be deleted") } + deleteReq.NameArg = args[0] err = w.Connections.Delete(ctx, deleteReq) if err != nil { @@ -177,26 +176,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME_ARG argument specified. Loading names for Connections drop-down." - names, err := w.Connections.ConnectionInfoNameToFullNameMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Connections drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Name of the connection") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME_ARG argument specified. Loading names for Connections drop-down." + names, err := w.Connections.ConnectionInfoNameToFullNameMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Connections drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have name of the connection") + id, err := cmdio.Select(ctx, names, "Name of the connection") + if err != nil { + return err } - getReq.NameArg = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have name of the connection") } + getReq.NameArg = args[0] response, err := w.Connections.Get(ctx, getReq) if err != nil { diff --git a/cmd/workspace/dashboards/dashboards.go b/cmd/workspace/dashboards/dashboards.go index 26c8b299d2..e6b74d6449 100755 --- a/cmd/workspace/dashboards/dashboards.go +++ b/cmd/workspace/dashboards/dashboards.go @@ -109,26 +109,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No DASHBOARD_ID argument specified. Loading names for Dashboards drop-down." - names, err := w.Dashboards.DashboardNameToIdMap(ctx, sql.ListDashboardsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Dashboards drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No DASHBOARD_ID argument specified. Loading names for Dashboards drop-down." + names, err := w.Dashboards.DashboardNameToIdMap(ctx, sql.ListDashboardsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Dashboards drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - deleteReq.DashboardId = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have ") + } + deleteReq.DashboardId = args[0] err = w.Dashboards.Delete(ctx, deleteReq) if err != nil { @@ -171,26 +170,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No DASHBOARD_ID argument specified. Loading names for Dashboards drop-down." - names, err := w.Dashboards.DashboardNameToIdMap(ctx, sql.ListDashboardsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Dashboards drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No DASHBOARD_ID argument specified. Loading names for Dashboards drop-down." + names, err := w.Dashboards.DashboardNameToIdMap(ctx, sql.ListDashboardsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Dashboards drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - getReq.DashboardId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + getReq.DashboardId = args[0] response, err := w.Dashboards.Get(ctx, getReq) if err != nil { @@ -287,26 +285,25 @@ var restoreCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No DASHBOARD_ID argument specified. Loading names for Dashboards drop-down." - names, err := w.Dashboards.DashboardNameToIdMap(ctx, sql.ListDashboardsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Dashboards drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No DASHBOARD_ID argument specified. Loading names for Dashboards drop-down." + names, err := w.Dashboards.DashboardNameToIdMap(ctx, sql.ListDashboardsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Dashboards drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - restoreReq.DashboardId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + restoreReq.DashboardId = args[0] err = w.Dashboards.Restore(ctx, restoreReq) if err != nil { diff --git a/cmd/workspace/experiments/experiments.go b/cmd/workspace/experiments/experiments.go index 5ab5b94e65..8e5c4f84a6 100755 --- a/cmd/workspace/experiments/experiments.go +++ b/cmd/workspace/experiments/experiments.go @@ -333,9 +333,6 @@ var getByNameCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -347,9 +344,8 @@ var getByNameCmd = &cobra.Command{ if err != nil { return err } - } else { - getByNameReq.ExperimentName = args[0] } + getByNameReq.ExperimentName = args[0] response, err := w.Experiments.GetByName(ctx, getByNameReq) if err != nil { @@ -384,9 +380,6 @@ var getExperimentCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -398,9 +391,8 @@ var getExperimentCmd = &cobra.Command{ if err != nil { return err } - } else { - getExperimentReq.ExperimentId = args[0] } + getExperimentReq.ExperimentId = args[0] response, err := w.Experiments.GetExperiment(ctx, getExperimentReq) if err != nil { @@ -440,9 +432,6 @@ var getHistoryCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -454,9 +443,8 @@ var getHistoryCmd = &cobra.Command{ if err != nil { return err } - } else { - getHistoryReq.MetricKey = args[0] } + getHistoryReq.MetricKey = args[0] response, err := w.Experiments.GetHistory(ctx, getHistoryReq) if err != nil { @@ -498,9 +486,6 @@ var getRunCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -512,9 +497,8 @@ var getRunCmd = &cobra.Command{ if err != nil { return err } - } else { - getRunReq.RunId = args[0] } + getRunReq.RunId = args[0] response, err := w.Experiments.GetRun(ctx, getRunReq) if err != nil { diff --git a/cmd/workspace/external-locations/external-locations.go b/cmd/workspace/external-locations/external-locations.go index 91696ef454..741ca44f8d 100755 --- a/cmd/workspace/external-locations/external-locations.go +++ b/cmd/workspace/external-locations/external-locations.go @@ -115,9 +115,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -129,9 +126,8 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteReq.Name = args[0] } + deleteReq.Name = args[0] err = w.ExternalLocations.Delete(ctx, deleteReq) if err != nil { @@ -168,9 +164,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -182,9 +175,8 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.Name = args[0] } + getReq.Name = args[0] response, err := w.ExternalLocations.Get(ctx, getReq) if err != nil { diff --git a/cmd/workspace/functions/functions.go b/cmd/workspace/functions/functions.go index c90d080760..f27a9ecf0c 100755 --- a/cmd/workspace/functions/functions.go +++ b/cmd/workspace/functions/functions.go @@ -116,26 +116,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Functions drop-down." - names, err := w.Functions.FunctionInfoNameToFullNameMap(ctx, catalog.ListFunctionsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Functions drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Functions drop-down." + names, err := w.Functions.FunctionInfoNameToFullNameMap(ctx, catalog.ListFunctionsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Functions drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") + id, err := cmdio.Select(ctx, names, "The fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") + if err != nil { + return err } - deleteReq.Name = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") } + deleteReq.Name = args[0] err = w.Functions.Delete(ctx, deleteReq) if err != nil { @@ -183,26 +182,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Functions drop-down." - names, err := w.Functions.FunctionInfoNameToFullNameMap(ctx, catalog.ListFunctionsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Functions drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Functions drop-down." + names, err := w.Functions.FunctionInfoNameToFullNameMap(ctx, catalog.ListFunctionsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Functions drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") + id, err := cmdio.Select(ctx, names, "The fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") + if err != nil { + return err } - getReq.Name = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have the fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") + } + getReq.Name = args[0] response, err := w.Functions.Get(ctx, getReq) if err != nil { @@ -243,9 +241,6 @@ var listCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -257,10 +252,9 @@ var listCmd = &cobra.Command{ if err != nil { return err } - } else { - listReq.CatalogName = args[0] - listReq.SchemaName = args[1] } + listReq.CatalogName = args[0] + listReq.SchemaName = args[1] response, err := w.Functions.ListAll(ctx, listReq) if err != nil { @@ -311,26 +305,25 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Functions drop-down." - names, err := w.Functions.FunctionInfoNameToFullNameMap(ctx, catalog.ListFunctionsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Functions drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Functions drop-down." + names, err := w.Functions.FunctionInfoNameToFullNameMap(ctx, catalog.ListFunctionsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Functions drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") + id, err := cmdio.Select(ctx, names, "The fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") + if err != nil { + return err } - updateReq.Name = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the fully-qualified name of the function (of the form __catalog_name__.__schema_name__.__function__name__)") } + updateReq.Name = args[0] response, err := w.Functions.Update(ctx, updateReq) if err != nil { diff --git a/cmd/workspace/git-credentials/git-credentials.go b/cmd/workspace/git-credentials/git-credentials.go index c2f1fece9f..722b4574f9 100755 --- a/cmd/workspace/git-credentials/git-credentials.go +++ b/cmd/workspace/git-credentials/git-credentials.go @@ -112,28 +112,27 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No CREDENTIAL_ID argument specified. Loading names for Git Credentials drop-down." - names, err := w.GitCredentials.CredentialInfoGitProviderToCredentialIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Git Credentials drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID for the corresponding credential to access") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have the id for the corresponding credential to access") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No CREDENTIAL_ID argument specified. Loading names for Git Credentials drop-down." + names, err := w.GitCredentials.CredentialInfoGitProviderToCredentialIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Git Credentials drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &deleteReq.CredentialId) + id, err := cmdio.Select(ctx, names, "The ID for the corresponding credential to access") if err != nil { - return fmt.Errorf("invalid CREDENTIAL_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id for the corresponding credential to access") + } + _, err = fmt.Sscan(args[0], &deleteReq.CredentialId) + if err != nil { + return fmt.Errorf("invalid CREDENTIAL_ID: %s", args[0]) } err = w.GitCredentials.Delete(ctx, deleteReq) @@ -176,28 +175,27 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No CREDENTIAL_ID argument specified. Loading names for Git Credentials drop-down." - names, err := w.GitCredentials.CredentialInfoGitProviderToCredentialIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Git Credentials drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID for the corresponding credential to access") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have the id for the corresponding credential to access") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No CREDENTIAL_ID argument specified. Loading names for Git Credentials drop-down." + names, err := w.GitCredentials.CredentialInfoGitProviderToCredentialIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Git Credentials drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &getReq.CredentialId) + id, err := cmdio.Select(ctx, names, "The ID for the corresponding credential to access") if err != nil { - return fmt.Errorf("invalid CREDENTIAL_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id for the corresponding credential to access") + } + _, err = fmt.Sscan(args[0], &getReq.CredentialId) + if err != nil { + return fmt.Errorf("invalid CREDENTIAL_ID: %s", args[0]) } response, err := w.GitCredentials.Get(ctx, getReq) @@ -275,28 +273,27 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No CREDENTIAL_ID argument specified. Loading names for Git Credentials drop-down." - names, err := w.GitCredentials.CredentialInfoGitProviderToCredentialIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Git Credentials drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID for the corresponding credential to access") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have the id for the corresponding credential to access") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No CREDENTIAL_ID argument specified. Loading names for Git Credentials drop-down." + names, err := w.GitCredentials.CredentialInfoGitProviderToCredentialIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Git Credentials drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &updateReq.CredentialId) + id, err := cmdio.Select(ctx, names, "The ID for the corresponding credential to access") if err != nil { - return fmt.Errorf("invalid CREDENTIAL_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id for the corresponding credential to access") + } + _, err = fmt.Sscan(args[0], &updateReq.CredentialId) + if err != nil { + return fmt.Errorf("invalid CREDENTIAL_ID: %s", args[0]) } err = w.GitCredentials.Update(ctx, updateReq) diff --git a/cmd/workspace/global-init-scripts/global-init-scripts.go b/cmd/workspace/global-init-scripts/global-init-scripts.go index ddc0ff7356..9f61f72038 100755 --- a/cmd/workspace/global-init-scripts/global-init-scripts.go +++ b/cmd/workspace/global-init-scripts/global-init-scripts.go @@ -113,26 +113,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No SCRIPT_ID argument specified. Loading names for Global Init Scripts drop-down." - names, err := w.GlobalInitScripts.GlobalInitScriptDetailsNameToScriptIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Global Init Scripts drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID of the global init script") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No SCRIPT_ID argument specified. Loading names for Global Init Scripts drop-down." + names, err := w.GlobalInitScripts.GlobalInitScriptDetailsNameToScriptIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Global Init Scripts drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the id of the global init script") + id, err := cmdio.Select(ctx, names, "The ID of the global init script") + if err != nil { + return err } - deleteReq.ScriptId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id of the global init script") } + deleteReq.ScriptId = args[0] err = w.GlobalInitScripts.Delete(ctx, deleteReq) if err != nil { @@ -174,26 +173,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No SCRIPT_ID argument specified. Loading names for Global Init Scripts drop-down." - names, err := w.GlobalInitScripts.GlobalInitScriptDetailsNameToScriptIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Global Init Scripts drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID of the global init script") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No SCRIPT_ID argument specified. Loading names for Global Init Scripts drop-down." + names, err := w.GlobalInitScripts.GlobalInitScriptDetailsNameToScriptIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Global Init Scripts drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the id of the global init script") + id, err := cmdio.Select(ctx, names, "The ID of the global init script") + if err != nil { + return err } - getReq.ScriptId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id of the global init script") } + getReq.ScriptId = args[0] response, err := w.GlobalInitScripts.Get(ctx, getReq) if err != nil { @@ -265,9 +263,6 @@ var updateCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(3) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -279,11 +274,10 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - updateReq.Name = args[0] - updateReq.Script = args[1] - updateReq.ScriptId = args[2] } + updateReq.Name = args[0] + updateReq.Script = args[1] + updateReq.ScriptId = args[2] err = w.GlobalInitScripts.Update(ctx, updateReq) if err != nil { diff --git a/cmd/workspace/grants/grants.go b/cmd/workspace/grants/grants.go index bd3e2ee29a..5ad793fe1b 100755 --- a/cmd/workspace/grants/grants.go +++ b/cmd/workspace/grants/grants.go @@ -55,9 +55,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -69,13 +66,12 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &getReq.SecurableType) - if err != nil { - return fmt.Errorf("invalid SECURABLE_TYPE: %s", args[0]) - } - getReq.FullName = args[1] } + _, err = fmt.Sscan(args[0], &getReq.SecurableType) + if err != nil { + return fmt.Errorf("invalid SECURABLE_TYPE: %s", args[0]) + } + getReq.FullName = args[1] response, err := w.Grants.Get(ctx, getReq) if err != nil { @@ -112,9 +108,6 @@ var getEffectiveCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -126,13 +119,12 @@ var getEffectiveCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &getEffectiveReq.SecurableType) - if err != nil { - return fmt.Errorf("invalid SECURABLE_TYPE: %s", args[0]) - } - getEffectiveReq.FullName = args[1] } + _, err = fmt.Sscan(args[0], &getEffectiveReq.SecurableType) + if err != nil { + return fmt.Errorf("invalid SECURABLE_TYPE: %s", args[0]) + } + getEffectiveReq.FullName = args[1] response, err := w.Grants.GetEffective(ctx, getEffectiveReq) if err != nil { @@ -169,9 +161,6 @@ var updateCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -183,13 +172,12 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &updateReq.SecurableType) - if err != nil { - return fmt.Errorf("invalid SECURABLE_TYPE: %s", args[0]) - } - updateReq.FullName = args[1] } + _, err = fmt.Sscan(args[0], &updateReq.SecurableType) + if err != nil { + return fmt.Errorf("invalid SECURABLE_TYPE: %s", args[0]) + } + updateReq.FullName = args[1] response, err := w.Grants.Update(ctx, updateReq) if err != nil { diff --git a/cmd/workspace/groups/groups.go b/cmd/workspace/groups/groups.go index c00bd9ff0f..ca26010c26 100755 --- a/cmd/workspace/groups/groups.go +++ b/cmd/workspace/groups/groups.go @@ -116,26 +116,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Groups drop-down." - names, err := w.Groups.GroupDisplayNameToIdMap(ctx, iam.ListGroupsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Groups drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks workspace") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Groups drop-down." + names, err := w.Groups.GroupDisplayNameToIdMap(ctx, iam.ListGroupsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Groups drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks workspace") + id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks workspace") + if err != nil { + return err } - deleteReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a group in the databricks workspace") } + deleteReq.Id = args[0] err = w.Groups.Delete(ctx, deleteReq) if err != nil { @@ -177,26 +176,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Groups drop-down." - names, err := w.Groups.GroupDisplayNameToIdMap(ctx, iam.ListGroupsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Groups drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks workspace") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Groups drop-down." + names, err := w.Groups.GroupDisplayNameToIdMap(ctx, iam.ListGroupsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Groups drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks workspace") + id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks workspace") + if err != nil { + return err } - getReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a group in the databricks workspace") } + getReq.Id = args[0] response, err := w.Groups.Get(ctx, getReq) if err != nil { @@ -298,26 +296,25 @@ var patchCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Groups drop-down." - names, err := w.Groups.GroupDisplayNameToIdMap(ctx, iam.ListGroupsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Groups drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks workspace") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Groups drop-down." + names, err := w.Groups.GroupDisplayNameToIdMap(ctx, iam.ListGroupsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Groups drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks workspace") + id, err := cmdio.Select(ctx, names, "Unique ID for a group in the Databricks workspace") + if err != nil { + return err } - patchReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a group in the databricks workspace") } + patchReq.Id = args[0] err = w.Groups.Patch(ctx, patchReq) if err != nil { diff --git a/cmd/workspace/instance-pools/instance-pools.go b/cmd/workspace/instance-pools/instance-pools.go index 88ce13e2b8..e498ad3106 100755 --- a/cmd/workspace/instance-pools/instance-pools.go +++ b/cmd/workspace/instance-pools/instance-pools.go @@ -260,26 +260,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No INSTANCE_POOL_ID argument specified. Loading names for Instance Pools drop-down." - names, err := w.InstancePools.InstancePoolAndStatsInstancePoolNameToInstancePoolIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Instance Pools drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The canonical unique identifier for the instance pool") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No INSTANCE_POOL_ID argument specified. Loading names for Instance Pools drop-down." + names, err := w.InstancePools.InstancePoolAndStatsInstancePoolNameToInstancePoolIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Instance Pools drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the canonical unique identifier for the instance pool") + id, err := cmdio.Select(ctx, names, "The canonical unique identifier for the instance pool") + if err != nil { + return err } - getReq.InstancePoolId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the canonical unique identifier for the instance pool") } + getReq.InstancePoolId = args[0] response, err := w.InstancePools.Get(ctx, getReq) if err != nil { diff --git a/cmd/workspace/ip-access-lists/ip-access-lists.go b/cmd/workspace/ip-access-lists/ip-access-lists.go index e6224d7826..3278e2425e 100755 --- a/cmd/workspace/ip-access-lists/ip-access-lists.go +++ b/cmd/workspace/ip-access-lists/ip-access-lists.go @@ -129,26 +129,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Ip Access Lists drop-down." - names, err := w.IpAccessLists.IpAccessListInfoLabelToListIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Ip Access Lists drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID for the corresponding IP access list to modify") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Ip Access Lists drop-down." + names, err := w.IpAccessLists.IpAccessListInfoLabelToListIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Ip Access Lists drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the id for the corresponding ip access list to modify") + id, err := cmdio.Select(ctx, names, "The ID for the corresponding IP access list to modify") + if err != nil { + return err } - deleteReq.IpAccessListId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id for the corresponding ip access list to modify") } + deleteReq.IpAccessListId = args[0] err = w.IpAccessLists.Delete(ctx, deleteReq) if err != nil { @@ -190,26 +189,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Ip Access Lists drop-down." - names, err := w.IpAccessLists.IpAccessListInfoLabelToListIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Ip Access Lists drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID for the corresponding IP access list to modify") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Ip Access Lists drop-down." + names, err := w.IpAccessLists.IpAccessListInfoLabelToListIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Ip Access Lists drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the id for the corresponding ip access list to modify") + id, err := cmdio.Select(ctx, names, "The ID for the corresponding IP access list to modify") + if err != nil { + return err } - getReq.IpAccessListId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id for the corresponding ip access list to modify") } + getReq.IpAccessListId = args[0] response, err := w.IpAccessLists.Get(ctx, getReq) if err != nil { diff --git a/cmd/workspace/jobs/jobs.go b/cmd/workspace/jobs/jobs.go index 802328b453..11733b5a50 100755 --- a/cmd/workspace/jobs/jobs.go +++ b/cmd/workspace/jobs/jobs.go @@ -421,28 +421,27 @@ var exportRunCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No RUN_ID argument specified. Loading names for Jobs drop-down." - names, err := w.Jobs.BaseJobSettingsNameToJobIdMap(ctx, jobs.ListJobsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Jobs drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The canonical identifier for the run") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have the canonical identifier for the run") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No RUN_ID argument specified. Loading names for Jobs drop-down." + names, err := w.Jobs.BaseJobSettingsNameToJobIdMap(ctx, jobs.ListJobsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Jobs drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &exportRunReq.RunId) + id, err := cmdio.Select(ctx, names, "The canonical identifier for the run") if err != nil { - return fmt.Errorf("invalid RUN_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the canonical identifier for the run") + } + _, err = fmt.Sscan(args[0], &exportRunReq.RunId) + if err != nil { + return fmt.Errorf("invalid RUN_ID: %s", args[0]) } response, err := w.Jobs.ExportRun(ctx, exportRunReq) @@ -485,28 +484,27 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No JOB_ID argument specified. Loading names for Jobs drop-down." - names, err := w.Jobs.BaseJobSettingsNameToJobIdMap(ctx, jobs.ListJobsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Jobs drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The canonical identifier of the job to retrieve information about") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have the canonical identifier of the job to retrieve information about") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No JOB_ID argument specified. Loading names for Jobs drop-down." + names, err := w.Jobs.BaseJobSettingsNameToJobIdMap(ctx, jobs.ListJobsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Jobs drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &getReq.JobId) + id, err := cmdio.Select(ctx, names, "The canonical identifier of the job to retrieve information about") if err != nil { - return fmt.Errorf("invalid JOB_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the canonical identifier of the job to retrieve information about") + } + _, err = fmt.Sscan(args[0], &getReq.JobId) + if err != nil { + return fmt.Errorf("invalid JOB_ID: %s", args[0]) } response, err := w.Jobs.Get(ctx, getReq) @@ -556,28 +554,27 @@ var getRunCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No RUN_ID argument specified. Loading names for Jobs drop-down." - names, err := w.Jobs.BaseJobSettingsNameToJobIdMap(ctx, jobs.ListJobsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Jobs drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The canonical identifier of the run for which to retrieve the metadata") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have the canonical identifier of the run for which to retrieve the metadata") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No RUN_ID argument specified. Loading names for Jobs drop-down." + names, err := w.Jobs.BaseJobSettingsNameToJobIdMap(ctx, jobs.ListJobsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Jobs drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &getRunReq.RunId) + id, err := cmdio.Select(ctx, names, "The canonical identifier of the run for which to retrieve the metadata") if err != nil { - return fmt.Errorf("invalid RUN_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the canonical identifier of the run for which to retrieve the metadata") + } + _, err = fmt.Sscan(args[0], &getRunReq.RunId) + if err != nil { + return fmt.Errorf("invalid RUN_ID: %s", args[0]) } response, err := w.Jobs.GetRun(ctx, getRunReq) @@ -629,28 +626,27 @@ var getRunOutputCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No RUN_ID argument specified. Loading names for Jobs drop-down." - names, err := w.Jobs.BaseJobSettingsNameToJobIdMap(ctx, jobs.ListJobsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Jobs drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The canonical identifier for the run") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have the canonical identifier for the run") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No RUN_ID argument specified. Loading names for Jobs drop-down." + names, err := w.Jobs.BaseJobSettingsNameToJobIdMap(ctx, jobs.ListJobsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Jobs drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &getRunOutputReq.RunId) + id, err := cmdio.Select(ctx, names, "The canonical identifier for the run") if err != nil { - return fmt.Errorf("invalid RUN_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the canonical identifier for the run") + } + _, err = fmt.Sscan(args[0], &getRunOutputReq.RunId) + if err != nil { + return fmt.Errorf("invalid RUN_ID: %s", args[0]) } response, err := w.Jobs.GetRunOutput(ctx, getRunOutputReq) diff --git a/cmd/workspace/libraries/libraries.go b/cmd/workspace/libraries/libraries.go index 16fce73351..578ff0543e 100755 --- a/cmd/workspace/libraries/libraries.go +++ b/cmd/workspace/libraries/libraries.go @@ -108,9 +108,6 @@ var clusterStatusCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -122,9 +119,8 @@ var clusterStatusCmd = &cobra.Command{ if err != nil { return err } - } else { - clusterStatusReq.ClusterId = args[0] } + clusterStatusReq.ClusterId = args[0] response, err := w.Libraries.ClusterStatus(ctx, clusterStatusReq) if err != nil { diff --git a/cmd/workspace/metastores/metastores.go b/cmd/workspace/metastores/metastores.go index 71e2d12283..8464cf588b 100755 --- a/cmd/workspace/metastores/metastores.go +++ b/cmd/workspace/metastores/metastores.go @@ -57,9 +57,6 @@ var assignCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(3) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -71,13 +68,12 @@ var assignCmd = &cobra.Command{ if err != nil { return err } - } else { - assignReq.MetastoreId = args[0] - assignReq.DefaultCatalogName = args[1] - _, err = fmt.Sscan(args[2], &assignReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[2]) - } + } + assignReq.MetastoreId = args[0] + assignReq.DefaultCatalogName = args[1] + _, err = fmt.Sscan(args[2], &assignReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[2]) } err = w.Metastores.Assign(ctx, assignReq) @@ -206,26 +202,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down." - names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID of the metastore") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down." + names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id of the metastore") + id, err := cmdio.Select(ctx, names, "Unique ID of the metastore") + if err != nil { + return err } - deleteReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id of the metastore") } + deleteReq.Id = args[0] err = w.Metastores.Delete(ctx, deleteReq) if err != nil { @@ -268,26 +263,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down." - names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID of the metastore") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down." + names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id of the metastore") + id, err := cmdio.Select(ctx, names, "Unique ID of the metastore") + if err != nil { + return err } - getReq.Id = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id of the metastore") + } + getReq.Id = args[0] response, err := w.Metastores.Get(ctx, getReq) if err != nil { @@ -443,9 +437,6 @@ var unassignCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -457,13 +448,12 @@ var unassignCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &unassignReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } - unassignReq.MetastoreId = args[1] } + _, err = fmt.Sscan(args[0], &unassignReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) + } + unassignReq.MetastoreId = args[1] err = w.Metastores.Unassign(ctx, unassignReq) if err != nil { @@ -514,26 +504,25 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down." - names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID of the metastore") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down." + names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id of the metastore") + id, err := cmdio.Select(ctx, names, "Unique ID of the metastore") + if err != nil { + return err } - updateReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id of the metastore") } + updateReq.Id = args[0] response, err := w.Metastores.Update(ctx, updateReq) if err != nil { @@ -581,28 +570,27 @@ var updateAssignmentCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Metastores drop-down." - names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "A workspace ID") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have a workspace id") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Metastores drop-down." + names, err := w.Metastores.MetastoreInfoNameToMetastoreIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Metastores drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &updateAssignmentReq.WorkspaceId) + id, err := cmdio.Select(ctx, names, "A workspace ID") if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have a workspace id") + } + _, err = fmt.Sscan(args[0], &updateAssignmentReq.WorkspaceId) + if err != nil { + return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) } err = w.Metastores.UpdateAssignment(ctx, updateAssignmentReq) diff --git a/cmd/workspace/model-registry/model-registry.go b/cmd/workspace/model-registry/model-registry.go index 8088d47d18..54195d7e02 100755 --- a/cmd/workspace/model-registry/model-registry.go +++ b/cmd/workspace/model-registry/model-registry.go @@ -385,9 +385,6 @@ var deleteCommentCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -399,9 +396,8 @@ var deleteCommentCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteCommentReq.Id = args[0] } + deleteCommentReq.Id = args[0] err = w.ModelRegistry.DeleteComment(ctx, deleteCommentReq) if err != nil { @@ -436,9 +432,6 @@ var deleteModelCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -450,9 +443,8 @@ var deleteModelCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteModelReq.Name = args[0] } + deleteModelReq.Name = args[0] err = w.ModelRegistry.DeleteModel(ctx, deleteModelReq) if err != nil { @@ -487,9 +479,6 @@ var deleteModelTagCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -501,10 +490,9 @@ var deleteModelTagCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteModelTagReq.Name = args[0] - deleteModelTagReq.Key = args[1] } + deleteModelTagReq.Name = args[0] + deleteModelTagReq.Key = args[1] err = w.ModelRegistry.DeleteModelTag(ctx, deleteModelTagReq) if err != nil { @@ -539,9 +527,6 @@ var deleteModelVersionCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -553,10 +538,9 @@ var deleteModelVersionCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteModelVersionReq.Name = args[0] - deleteModelVersionReq.Version = args[1] } + deleteModelVersionReq.Name = args[0] + deleteModelVersionReq.Version = args[1] err = w.ModelRegistry.DeleteModelVersion(ctx, deleteModelVersionReq) if err != nil { @@ -591,9 +575,6 @@ var deleteModelVersionTagCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(3) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -605,11 +586,10 @@ var deleteModelVersionTagCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteModelVersionTagReq.Name = args[0] - deleteModelVersionTagReq.Version = args[1] - deleteModelVersionTagReq.Key = args[2] } + deleteModelVersionTagReq.Name = args[0] + deleteModelVersionTagReq.Version = args[1] + deleteModelVersionTagReq.Key = args[2] err = w.ModelRegistry.DeleteModelVersionTag(ctx, deleteModelVersionTagReq) if err != nil { @@ -646,9 +626,6 @@ var deleteTransitionRequestCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(4) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -660,15 +637,14 @@ var deleteTransitionRequestCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteTransitionRequestReq.Name = args[0] - deleteTransitionRequestReq.Version = args[1] - _, err = fmt.Sscan(args[2], &deleteTransitionRequestReq.Stage) - if err != nil { - return fmt.Errorf("invalid STAGE: %s", args[2]) - } - deleteTransitionRequestReq.Creator = args[3] } + deleteTransitionRequestReq.Name = args[0] + deleteTransitionRequestReq.Version = args[1] + _, err = fmt.Sscan(args[2], &deleteTransitionRequestReq.Stage) + if err != nil { + return fmt.Errorf("invalid STAGE: %s", args[2]) + } + deleteTransitionRequestReq.Creator = args[3] err = w.ModelRegistry.DeleteTransitionRequest(ctx, deleteTransitionRequestReq) if err != nil { @@ -814,9 +790,6 @@ var getModelCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -828,9 +801,8 @@ var getModelCmd = &cobra.Command{ if err != nil { return err } - } else { - getModelReq.Name = args[0] } + getModelReq.Name = args[0] response, err := w.ModelRegistry.GetModel(ctx, getModelReq) if err != nil { @@ -865,9 +837,6 @@ var getModelVersionCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -879,10 +848,9 @@ var getModelVersionCmd = &cobra.Command{ if err != nil { return err } - } else { - getModelVersionReq.Name = args[0] - getModelVersionReq.Version = args[1] } + getModelVersionReq.Name = args[0] + getModelVersionReq.Version = args[1] response, err := w.ModelRegistry.GetModelVersion(ctx, getModelVersionReq) if err != nil { @@ -917,9 +885,6 @@ var getModelVersionDownloadUriCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -931,10 +896,9 @@ var getModelVersionDownloadUriCmd = &cobra.Command{ if err != nil { return err } - } else { - getModelVersionDownloadUriReq.Name = args[0] - getModelVersionDownloadUriReq.Version = args[1] } + getModelVersionDownloadUriReq.Name = args[0] + getModelVersionDownloadUriReq.Version = args[1] response, err := w.ModelRegistry.GetModelVersionDownloadUri(ctx, getModelVersionDownloadUriReq) if err != nil { @@ -1023,9 +987,6 @@ var listTransitionRequestsCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -1037,10 +998,9 @@ var listTransitionRequestsCmd = &cobra.Command{ if err != nil { return err } - } else { - listTransitionRequestsReq.Name = args[0] - listTransitionRequestsReq.Version = args[1] } + listTransitionRequestsReq.Name = args[0] + listTransitionRequestsReq.Version = args[1] response, err := w.ModelRegistry.ListTransitionRequestsAll(ctx, listTransitionRequestsReq) if err != nil { diff --git a/cmd/workspace/permissions/permissions.go b/cmd/workspace/permissions/permissions.go index f34a7ac7c6..174a2c615d 100755 --- a/cmd/workspace/permissions/permissions.go +++ b/cmd/workspace/permissions/permissions.go @@ -43,9 +43,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -57,10 +54,9 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.RequestObjectType = args[0] - getReq.RequestObjectId = args[1] } + getReq.RequestObjectType = args[0] + getReq.RequestObjectId = args[1] response, err := w.Permissions.Get(ctx, getReq) if err != nil { @@ -95,9 +91,6 @@ var getPermissionLevelsCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -109,10 +102,9 @@ var getPermissionLevelsCmd = &cobra.Command{ if err != nil { return err } - } else { - getPermissionLevelsReq.RequestObjectType = args[0] - getPermissionLevelsReq.RequestObjectId = args[1] } + getPermissionLevelsReq.RequestObjectType = args[0] + getPermissionLevelsReq.RequestObjectId = args[1] response, err := w.Permissions.GetPermissionLevels(ctx, getPermissionLevelsReq) if err != nil { @@ -150,9 +142,6 @@ var setCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -164,10 +153,9 @@ var setCmd = &cobra.Command{ if err != nil { return err } - } else { - setReq.RequestObjectType = args[0] - setReq.RequestObjectId = args[1] } + setReq.RequestObjectType = args[0] + setReq.RequestObjectId = args[1] err = w.Permissions.Set(ctx, setReq) if err != nil { @@ -204,9 +192,6 @@ var updateCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -218,10 +203,9 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - updateReq.RequestObjectType = args[0] - updateReq.RequestObjectId = args[1] } + updateReq.RequestObjectType = args[0] + updateReq.RequestObjectId = args[1] err = w.Permissions.Update(ctx, updateReq) if err != nil { diff --git a/cmd/workspace/pipelines/pipelines.go b/cmd/workspace/pipelines/pipelines.go index ebf484b6d6..0fd5f9a2e7 100755 --- a/cmd/workspace/pipelines/pipelines.go +++ b/cmd/workspace/pipelines/pipelines.go @@ -134,26 +134,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." - names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." + names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - deleteReq.PipelineId = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have ") + } + deleteReq.PipelineId = args[0] err = w.Pipelines.Delete(ctx, deleteReq) if err != nil { @@ -198,26 +197,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." - names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." + names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - getReq.PipelineId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + getReq.PipelineId = args[0] response, err := w.Pipelines.Get(ctx, getReq) if err != nil { @@ -252,9 +250,6 @@ var getUpdateCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -266,10 +261,9 @@ var getUpdateCmd = &cobra.Command{ if err != nil { return err } - } else { - getUpdateReq.PipelineId = args[0] - getUpdateReq.UpdateId = args[1] } + getUpdateReq.PipelineId = args[0] + getUpdateReq.UpdateId = args[1] response, err := w.Pipelines.GetUpdate(ctx, getUpdateReq) if err != nil { @@ -316,26 +310,25 @@ var listPipelineEventsCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." - names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." + names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - listPipelineEventsReq.PipelineId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + listPipelineEventsReq.PipelineId = args[0] response, err := w.Pipelines.ListPipelineEventsAll(ctx, listPipelineEventsReq) if err != nil { @@ -436,26 +429,25 @@ var listUpdatesCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." - names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The pipeline to return updates for") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." + names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the pipeline to return updates for") + id, err := cmdio.Select(ctx, names, "The pipeline to return updates for") + if err != nil { + return err } - listUpdatesReq.PipelineId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the pipeline to return updates for") } + listUpdatesReq.PipelineId = args[0] response, err := w.Pipelines.ListUpdates(ctx, listUpdatesReq) if err != nil { @@ -502,26 +494,25 @@ var resetCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." - names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." + names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - resetReq.PipelineId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + resetReq.PipelineId = args[0] wait, err := w.Pipelines.Reset(ctx, resetReq) if err != nil { @@ -580,26 +571,25 @@ var startUpdateCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." - names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." + names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - startUpdateReq.PipelineId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + startUpdateReq.PipelineId = args[0] response, err := w.Pipelines.StartUpdate(ctx, startUpdateReq) if err != nil { @@ -646,26 +636,25 @@ var stopCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." - names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." + names, err := w.Pipelines.PipelineStateInfoNameToPipelineIdMap(ctx, pipelines.ListPipelinesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Pipelines drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - stopReq.PipelineId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + stopReq.PipelineId = args[0] wait, err := w.Pipelines.Stop(ctx, stopReq) if err != nil { diff --git a/cmd/workspace/policy-families/policy-families.go b/cmd/workspace/policy-families/policy-families.go index d12572df4c..7eedc03f4d 100755 --- a/cmd/workspace/policy-families/policy-families.go +++ b/cmd/workspace/policy-families/policy-families.go @@ -45,9 +45,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -59,9 +56,8 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.PolicyFamilyId = args[0] } + getReq.PolicyFamilyId = args[0] response, err := w.PolicyFamilies.Get(ctx, getReq) if err != nil { diff --git a/cmd/workspace/providers/providers.go b/cmd/workspace/providers/providers.go index daf153e817..053f4f4b38 100755 --- a/cmd/workspace/providers/providers.go +++ b/cmd/workspace/providers/providers.go @@ -110,26 +110,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down." - names, err := w.Providers.ProviderInfoNameToMetastoreIdMap(ctx, sharing.ListProvidersRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Providers drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Name of the provider") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down." + names, err := w.Providers.ProviderInfoNameToMetastoreIdMap(ctx, sharing.ListProvidersRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Providers drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have name of the provider") + id, err := cmdio.Select(ctx, names, "Name of the provider") + if err != nil { + return err } - deleteReq.Name = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have name of the provider") } + deleteReq.Name = args[0] err = w.Providers.Delete(ctx, deleteReq) if err != nil { @@ -173,26 +172,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down." - names, err := w.Providers.ProviderInfoNameToMetastoreIdMap(ctx, sharing.ListProvidersRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Providers drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Name of the provider") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down." + names, err := w.Providers.ProviderInfoNameToMetastoreIdMap(ctx, sharing.ListProvidersRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Providers drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have name of the provider") + id, err := cmdio.Select(ctx, names, "Name of the provider") + if err != nil { + return err } - getReq.Name = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have name of the provider") } + getReq.Name = args[0] response, err := w.Providers.Get(ctx, getReq) if err != nil { @@ -291,26 +289,25 @@ var listSharesCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down." - names, err := w.Providers.ProviderInfoNameToMetastoreIdMap(ctx, sharing.ListProvidersRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Providers drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Name of the provider in which to list shares") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down." + names, err := w.Providers.ProviderInfoNameToMetastoreIdMap(ctx, sharing.ListProvidersRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Providers drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have name of the provider in which to list shares") + id, err := cmdio.Select(ctx, names, "Name of the provider in which to list shares") + if err != nil { + return err } - listSharesReq.Name = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have name of the provider in which to list shares") } + listSharesReq.Name = args[0] response, err := w.Providers.ListSharesAll(ctx, listSharesReq) if err != nil { diff --git a/cmd/workspace/queries/queries.go b/cmd/workspace/queries/queries.go index 2db5855a6d..7303b7f17d 100755 --- a/cmd/workspace/queries/queries.go +++ b/cmd/workspace/queries/queries.go @@ -120,26 +120,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." - names, err := w.Queries.QueryNameToIdMap(ctx, sql.ListQueriesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Queries drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." + names, err := w.Queries.QueryNameToIdMap(ctx, sql.ListQueriesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Queries drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - deleteReq.QueryId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + deleteReq.QueryId = args[0] err = w.Queries.Delete(ctx, deleteReq) if err != nil { @@ -182,26 +181,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." - names, err := w.Queries.QueryNameToIdMap(ctx, sql.ListQueriesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Queries drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." + names, err := w.Queries.QueryNameToIdMap(ctx, sql.ListQueriesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Queries drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - getReq.QueryId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + getReq.QueryId = args[0] response, err := w.Queries.Get(ctx, getReq) if err != nil { @@ -300,26 +298,25 @@ var restoreCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." - names, err := w.Queries.QueryNameToIdMap(ctx, sql.ListQueriesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Queries drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." + names, err := w.Queries.QueryNameToIdMap(ctx, sql.ListQueriesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Queries drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - restoreReq.QueryId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + restoreReq.QueryId = args[0] err = w.Queries.Restore(ctx, restoreReq) if err != nil { @@ -369,26 +366,25 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." - names, err := w.Queries.QueryNameToIdMap(ctx, sql.ListQueriesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Queries drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." + names, err := w.Queries.QueryNameToIdMap(ctx, sql.ListQueriesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Queries drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have ") + id, err := cmdio.Select(ctx, names, "") + if err != nil { + return err } - updateReq.QueryId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have ") } + updateReq.QueryId = args[0] response, err := w.Queries.Update(ctx, updateReq) if err != nil { diff --git a/cmd/workspace/recipient-activation/recipient-activation.go b/cmd/workspace/recipient-activation/recipient-activation.go index f0af854b4b..ab1a208d29 100755 --- a/cmd/workspace/recipient-activation/recipient-activation.go +++ b/cmd/workspace/recipient-activation/recipient-activation.go @@ -41,9 +41,6 @@ var getActivationUrlInfoCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -55,9 +52,8 @@ var getActivationUrlInfoCmd = &cobra.Command{ if err != nil { return err } - } else { - getActivationUrlInfoReq.ActivationUrl = args[0] } + getActivationUrlInfoReq.ActivationUrl = args[0] err = w.RecipientActivation.GetActivationUrlInfo(ctx, getActivationUrlInfoReq) if err != nil { @@ -93,9 +89,6 @@ var retrieveTokenCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -107,9 +100,8 @@ var retrieveTokenCmd = &cobra.Command{ if err != nil { return err } - } else { - retrieveTokenReq.ActivationUrl = args[0] } + retrieveTokenReq.ActivationUrl = args[0] response, err := w.RecipientActivation.RetrieveToken(ctx, retrieveTokenReq) if err != nil { diff --git a/cmd/workspace/recipients/recipients.go b/cmd/workspace/recipients/recipients.go index 98d8fb087d..c44ec6a3a6 100755 --- a/cmd/workspace/recipients/recipients.go +++ b/cmd/workspace/recipients/recipients.go @@ -115,26 +115,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Recipients drop-down." - names, err := w.Recipients.RecipientInfoNameToMetastoreIdMap(ctx, sharing.ListRecipientsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Recipients drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Name of the recipient") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Recipients drop-down." + names, err := w.Recipients.RecipientInfoNameToMetastoreIdMap(ctx, sharing.ListRecipientsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Recipients drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have name of the recipient") + id, err := cmdio.Select(ctx, names, "Name of the recipient") + if err != nil { + return err } - deleteReq.Name = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have name of the recipient") } + deleteReq.Name = args[0] err = w.Recipients.Delete(ctx, deleteReq) if err != nil { @@ -178,26 +177,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Recipients drop-down." - names, err := w.Recipients.RecipientInfoNameToMetastoreIdMap(ctx, sharing.ListRecipientsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Recipients drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Name of the recipient") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Recipients drop-down." + names, err := w.Recipients.RecipientInfoNameToMetastoreIdMap(ctx, sharing.ListRecipientsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Recipients drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have name of the recipient") + id, err := cmdio.Select(ctx, names, "Name of the recipient") + if err != nil { + return err } - getReq.Name = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have name of the recipient") + } + getReq.Name = args[0] response, err := w.Recipients.Get(ctx, getReq) if err != nil { @@ -288,9 +286,6 @@ var rotateTokenCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -302,13 +297,12 @@ var rotateTokenCmd = &cobra.Command{ if err != nil { return err } - } else { - _, err = fmt.Sscan(args[0], &rotateTokenReq.ExistingTokenExpireInSeconds) - if err != nil { - return fmt.Errorf("invalid EXISTING_TOKEN_EXPIRE_IN_SECONDS: %s", args[0]) - } - rotateTokenReq.Name = args[1] } + _, err = fmt.Sscan(args[0], &rotateTokenReq.ExistingTokenExpireInSeconds) + if err != nil { + return fmt.Errorf("invalid EXISTING_TOKEN_EXPIRE_IN_SECONDS: %s", args[0]) + } + rotateTokenReq.Name = args[1] response, err := w.Recipients.RotateToken(ctx, rotateTokenReq) if err != nil { @@ -351,26 +345,25 @@ var sharePermissionsCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Recipients drop-down." - names, err := w.Recipients.RecipientInfoNameToMetastoreIdMap(ctx, sharing.ListRecipientsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Recipients drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The name of the Recipient") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Recipients drop-down." + names, err := w.Recipients.RecipientInfoNameToMetastoreIdMap(ctx, sharing.ListRecipientsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Recipients drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the name of the recipient") + id, err := cmdio.Select(ctx, names, "The name of the Recipient") + if err != nil { + return err } - sharePermissionsReq.Name = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the name of the recipient") } + sharePermissionsReq.Name = args[0] response, err := w.Recipients.SharePermissions(ctx, sharePermissionsReq) if err != nil { diff --git a/cmd/workspace/repos/repos.go b/cmd/workspace/repos/repos.go index 7070493a95..f8c594f708 100755 --- a/cmd/workspace/repos/repos.go +++ b/cmd/workspace/repos/repos.go @@ -116,28 +116,27 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No REPO_ID argument specified. Loading names for Repos drop-down." - names, err := w.Repos.RepoInfoPathToIdMap(ctx, workspace.ListReposRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Repos drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID for the corresponding repo to access") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have the id for the corresponding repo to access") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No REPO_ID argument specified. Loading names for Repos drop-down." + names, err := w.Repos.RepoInfoPathToIdMap(ctx, workspace.ListReposRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Repos drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &deleteReq.RepoId) + id, err := cmdio.Select(ctx, names, "The ID for the corresponding repo to access") if err != nil { - return fmt.Errorf("invalid REPO_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id for the corresponding repo to access") + } + _, err = fmt.Sscan(args[0], &deleteReq.RepoId) + if err != nil { + return fmt.Errorf("invalid REPO_ID: %s", args[0]) } err = w.Repos.Delete(ctx, deleteReq) @@ -180,28 +179,27 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No REPO_ID argument specified. Loading names for Repos drop-down." - names, err := w.Repos.RepoInfoPathToIdMap(ctx, workspace.ListReposRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Repos drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID for the corresponding repo to access") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have the id for the corresponding repo to access") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No REPO_ID argument specified. Loading names for Repos drop-down." + names, err := w.Repos.RepoInfoPathToIdMap(ctx, workspace.ListReposRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Repos drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &getReq.RepoId) + id, err := cmdio.Select(ctx, names, "The ID for the corresponding repo to access") if err != nil { - return fmt.Errorf("invalid REPO_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id for the corresponding repo to access") + } + _, err = fmt.Sscan(args[0], &getReq.RepoId) + if err != nil { + return fmt.Errorf("invalid REPO_ID: %s", args[0]) } response, err := w.Repos.Get(ctx, getReq) @@ -303,28 +301,27 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No REPO_ID argument specified. Loading names for Repos drop-down." - names, err := w.Repos.RepoInfoPathToIdMap(ctx, workspace.ListReposRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Repos drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID for the corresponding repo to access") - if err != nil { - return err - } - args = append(args, id) - } - if len(args) != 1 { - return fmt.Errorf("expected to have the id for the corresponding repo to access") + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No REPO_ID argument specified. Loading names for Repos drop-down." + names, err := w.Repos.RepoInfoPathToIdMap(ctx, workspace.ListReposRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Repos drop-down. Please manually specify required arguments. Original error: %w", err) } - _, err = fmt.Sscan(args[0], &updateReq.RepoId) + id, err := cmdio.Select(ctx, names, "The ID for the corresponding repo to access") if err != nil { - return fmt.Errorf("invalid REPO_ID: %s", args[0]) + return err } + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id for the corresponding repo to access") + } + _, err = fmt.Sscan(args[0], &updateReq.RepoId) + if err != nil { + return fmt.Errorf("invalid REPO_ID: %s", args[0]) } err = w.Repos.Update(ctx, updateReq) diff --git a/cmd/workspace/schemas/schemas.go b/cmd/workspace/schemas/schemas.go index 65737f40b6..d8d8ac9d69 100755 --- a/cmd/workspace/schemas/schemas.go +++ b/cmd/workspace/schemas/schemas.go @@ -113,26 +113,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No FULL_NAME argument specified. Loading names for Schemas drop-down." - names, err := w.Schemas.SchemaInfoNameToFullNameMap(ctx, catalog.ListSchemasRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Schemas drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Full name of the schema") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No FULL_NAME argument specified. Loading names for Schemas drop-down." + names, err := w.Schemas.SchemaInfoNameToFullNameMap(ctx, catalog.ListSchemasRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Schemas drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have full name of the schema") + id, err := cmdio.Select(ctx, names, "Full name of the schema") + if err != nil { + return err } - deleteReq.FullName = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have full name of the schema") } + deleteReq.FullName = args[0] err = w.Schemas.Delete(ctx, deleteReq) if err != nil { @@ -176,26 +175,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No FULL_NAME argument specified. Loading names for Schemas drop-down." - names, err := w.Schemas.SchemaInfoNameToFullNameMap(ctx, catalog.ListSchemasRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Schemas drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Full name of the schema") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No FULL_NAME argument specified. Loading names for Schemas drop-down." + names, err := w.Schemas.SchemaInfoNameToFullNameMap(ctx, catalog.ListSchemasRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Schemas drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have full name of the schema") + id, err := cmdio.Select(ctx, names, "Full name of the schema") + if err != nil { + return err } - getReq.FullName = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have full name of the schema") + } + getReq.FullName = args[0] response, err := w.Schemas.Get(ctx, getReq) if err != nil { @@ -234,9 +232,6 @@ var listCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -248,9 +243,8 @@ var listCmd = &cobra.Command{ if err != nil { return err } - } else { - listReq.CatalogName = args[0] } + listReq.CatalogName = args[0] response, err := w.Schemas.ListAll(ctx, listReq) if err != nil { @@ -301,26 +295,25 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No FULL_NAME argument specified. Loading names for Schemas drop-down." - names, err := w.Schemas.SchemaInfoNameToFullNameMap(ctx, catalog.ListSchemasRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Schemas drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Full name of the schema") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No FULL_NAME argument specified. Loading names for Schemas drop-down." + names, err := w.Schemas.SchemaInfoNameToFullNameMap(ctx, catalog.ListSchemasRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Schemas drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have full name of the schema") + id, err := cmdio.Select(ctx, names, "Full name of the schema") + if err != nil { + return err } - updateReq.FullName = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have full name of the schema") } + updateReq.FullName = args[0] response, err := w.Schemas.Update(ctx, updateReq) if err != nil { diff --git a/cmd/workspace/secrets/secrets.go b/cmd/workspace/secrets/secrets.go index 5a8a8d608a..0e9f5d4e7b 100755 --- a/cmd/workspace/secrets/secrets.go +++ b/cmd/workspace/secrets/secrets.go @@ -285,9 +285,6 @@ var getAclCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -299,10 +296,9 @@ var getAclCmd = &cobra.Command{ if err != nil { return err } - } else { - getAclReq.Scope = args[0] - getAclReq.Principal = args[1] } + getAclReq.Scope = args[0] + getAclReq.Principal = args[1] response, err := w.Secrets.GetAcl(ctx, getAclReq) if err != nil { @@ -342,9 +338,6 @@ var listAclsCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -356,9 +349,8 @@ var listAclsCmd = &cobra.Command{ if err != nil { return err } - } else { - listAclsReq.Scope = args[0] } + listAclsReq.Scope = args[0] response, err := w.Secrets.ListAclsAll(ctx, listAclsReq) if err != nil { @@ -433,9 +425,6 @@ var listSecretsCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -447,9 +436,8 @@ var listSecretsCmd = &cobra.Command{ if err != nil { return err } - } else { - listSecretsReq.Scope = args[0] } + listSecretsReq.Scope = args[0] response, err := w.Secrets.ListSecretsAll(ctx, listSecretsReq) if err != nil { diff --git a/cmd/workspace/service-principals/service-principals.go b/cmd/workspace/service-principals/service-principals.go index 71760a559c..f444a83cb7 100755 --- a/cmd/workspace/service-principals/service-principals.go +++ b/cmd/workspace/service-principals/service-principals.go @@ -114,26 +114,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Service Principals drop-down." - names, err := w.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListServicePrincipalsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks workspace") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Service Principals drop-down." + names, err := w.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListServicePrincipalsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks workspace") + id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks workspace") + if err != nil { + return err } - deleteReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a service principal in the databricks workspace") } + deleteReq.Id = args[0] err = w.ServicePrincipals.Delete(ctx, deleteReq) if err != nil { @@ -176,26 +175,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Service Principals drop-down." - names, err := w.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListServicePrincipalsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks workspace") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Service Principals drop-down." + names, err := w.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListServicePrincipalsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks workspace") + id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks workspace") + if err != nil { + return err } - getReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a service principal in the databricks workspace") } + getReq.Id = args[0] response, err := w.ServicePrincipals.Get(ctx, getReq) if err != nil { @@ -298,26 +296,25 @@ var patchCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Service Principals drop-down." - names, err := w.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListServicePrincipalsRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks workspace") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Service Principals drop-down." + names, err := w.ServicePrincipals.ServicePrincipalDisplayNameToIdMap(ctx, iam.ListServicePrincipalsRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Service Principals drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks workspace") + id, err := cmdio.Select(ctx, names, "Unique ID for a service principal in the Databricks workspace") + if err != nil { + return err } - patchReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a service principal in the databricks workspace") } + patchReq.Id = args[0] err = w.ServicePrincipals.Patch(ctx, patchReq) if err != nil { diff --git a/cmd/workspace/serving-endpoints/serving-endpoints.go b/cmd/workspace/serving-endpoints/serving-endpoints.go index eb0df68a8a..5471f62891 100755 --- a/cmd/workspace/serving-endpoints/serving-endpoints.go +++ b/cmd/workspace/serving-endpoints/serving-endpoints.go @@ -57,9 +57,6 @@ var buildLogsCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -71,10 +68,9 @@ var buildLogsCmd = &cobra.Command{ if err != nil { return err } - } else { - buildLogsReq.Name = args[0] - buildLogsReq.ServedModelName = args[1] } + buildLogsReq.Name = args[0] + buildLogsReq.ServedModelName = args[1] response, err := w.ServingEndpoints.BuildLogs(ctx, buildLogsReq) if err != nil { @@ -167,9 +163,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -181,9 +174,8 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteReq.Name = args[0] } + deleteReq.Name = args[0] err = w.ServingEndpoints.Delete(ctx, deleteReq) if err != nil { @@ -219,9 +211,6 @@ var exportMetricsCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -233,9 +222,8 @@ var exportMetricsCmd = &cobra.Command{ if err != nil { return err } - } else { - exportMetricsReq.Name = args[0] } + exportMetricsReq.Name = args[0] err = w.ServingEndpoints.ExportMetrics(ctx, exportMetricsReq) if err != nil { @@ -270,9 +258,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -284,9 +269,8 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.Name = args[0] } + getReq.Name = args[0] response, err := w.ServingEndpoints.Get(ctx, getReq) if err != nil { @@ -350,9 +334,6 @@ var logsCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -364,10 +345,9 @@ var logsCmd = &cobra.Command{ if err != nil { return err } - } else { - logsReq.Name = args[0] - logsReq.ServedModelName = args[1] } + logsReq.Name = args[0] + logsReq.ServedModelName = args[1] response, err := w.ServingEndpoints.Logs(ctx, logsReq) if err != nil { @@ -400,9 +380,6 @@ var queryCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -414,9 +391,8 @@ var queryCmd = &cobra.Command{ if err != nil { return err } - } else { - queryReq.Name = args[0] } + queryReq.Name = args[0] response, err := w.ServingEndpoints.Query(ctx, queryReq) if err != nil { diff --git a/cmd/workspace/shares/shares.go b/cmd/workspace/shares/shares.go index c9c6734d64..1457ba514a 100755 --- a/cmd/workspace/shares/shares.go +++ b/cmd/workspace/shares/shares.go @@ -97,9 +97,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -111,9 +108,8 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteReq.Name = args[0] } + deleteReq.Name = args[0] err = w.Shares.Delete(ctx, deleteReq) if err != nil { @@ -151,9 +147,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -165,9 +158,8 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.Name = args[0] } + getReq.Name = args[0] response, err := w.Shares.Get(ctx, getReq) if err != nil { @@ -235,9 +227,6 @@ var sharePermissionsCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -249,9 +238,8 @@ var sharePermissionsCmd = &cobra.Command{ if err != nil { return err } - } else { - sharePermissionsReq.Name = args[0] } + sharePermissionsReq.Name = args[0] response, err := w.Shares.SharePermissions(ctx, sharePermissionsReq) if err != nil { @@ -361,9 +349,6 @@ var updatePermissionsCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -375,9 +360,8 @@ var updatePermissionsCmd = &cobra.Command{ if err != nil { return err } - } else { - updatePermissionsReq.Name = args[0] } + updatePermissionsReq.Name = args[0] err = w.Shares.UpdatePermissions(ctx, updatePermissionsReq) if err != nil { diff --git a/cmd/workspace/storage-credentials/storage-credentials.go b/cmd/workspace/storage-credentials/storage-credentials.go index ffec90783a..9518d8f2b5 100755 --- a/cmd/workspace/storage-credentials/storage-credentials.go +++ b/cmd/workspace/storage-credentials/storage-credentials.go @@ -131,26 +131,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Storage Credentials drop-down." - names, err := w.StorageCredentials.StorageCredentialInfoNameToIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Storage Credentials drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Name of the storage credential") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Storage Credentials drop-down." + names, err := w.StorageCredentials.StorageCredentialInfoNameToIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Storage Credentials drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have name of the storage credential") + id, err := cmdio.Select(ctx, names, "Name of the storage credential") + if err != nil { + return err } - deleteReq.Name = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have name of the storage credential") } + deleteReq.Name = args[0] err = w.StorageCredentials.Delete(ctx, deleteReq) if err != nil { @@ -194,26 +193,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No NAME argument specified. Loading names for Storage Credentials drop-down." - names, err := w.StorageCredentials.StorageCredentialInfoNameToIdMap(ctx) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Storage Credentials drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Name of the storage credential") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No NAME argument specified. Loading names for Storage Credentials drop-down." + names, err := w.StorageCredentials.StorageCredentialInfoNameToIdMap(ctx) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Storage Credentials drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have name of the storage credential") + id, err := cmdio.Select(ctx, names, "Name of the storage credential") + if err != nil { + return err } - getReq.Name = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have name of the storage credential") } + getReq.Name = args[0] response, err := w.StorageCredentials.Get(ctx, getReq) if err != nil { diff --git a/cmd/workspace/system-schemas/system-schemas.go b/cmd/workspace/system-schemas/system-schemas.go index 66a9fe5af6..76f20cc692 100755 --- a/cmd/workspace/system-schemas/system-schemas.go +++ b/cmd/workspace/system-schemas/system-schemas.go @@ -42,16 +42,13 @@ var disableCmd = &cobra.Command{ Use: "disable METASTORE_ID SCHEMA_NAME", Short: `Disable a system schema.`, Long: `Disable a system schema. - + Disables the system schema and removes it from the system catalog. The caller must be an account admin or a metastore admin.`, Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -63,12 +60,11 @@ var disableCmd = &cobra.Command{ if err != nil { return err } - } else { - disableReq.MetastoreId = args[0] - _, err = fmt.Sscan(args[1], &disableReq.SchemaName) - if err != nil { - return fmt.Errorf("invalid SCHEMA_NAME: %s", args[1]) - } + } + disableReq.MetastoreId = args[0] + _, err = fmt.Sscan(args[1], &disableReq.SchemaName) + if err != nil { + return fmt.Errorf("invalid SCHEMA_NAME: %s", args[1]) } err = w.SystemSchemas.Disable(ctx, disableReq) @@ -98,16 +94,13 @@ var enableCmd = &cobra.Command{ Use: "enable METASTORE_ID SCHEMA_NAME", Short: `Enable a system schema.`, Long: `Enable a system schema. - + Enables the system schema and adds it to the system catalog. The caller must be an account admin or a metastore admin.`, Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -119,12 +112,11 @@ var enableCmd = &cobra.Command{ if err != nil { return err } - } else { - enableReq.MetastoreId = args[0] - _, err = fmt.Sscan(args[1], &enableReq.SchemaName) - if err != nil { - return fmt.Errorf("invalid SCHEMA_NAME: %s", args[1]) - } + } + enableReq.MetastoreId = args[0] + _, err = fmt.Sscan(args[1], &enableReq.SchemaName) + if err != nil { + return fmt.Errorf("invalid SCHEMA_NAME: %s", args[1]) } err = w.SystemSchemas.Enable(ctx, enableReq) @@ -154,16 +146,13 @@ var listCmd = &cobra.Command{ Use: "list METASTORE_ID", Short: `List system schemas.`, Long: `List system schemas. - + Gets an array of system schemas for a metastore. The caller must be an account admin or a metastore admin.`, Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -175,9 +164,8 @@ var listCmd = &cobra.Command{ if err != nil { return err } - } else { - listReq.MetastoreId = args[0] } + listReq.MetastoreId = args[0] response, err := w.SystemSchemas.ListAll(ctx, listReq) if err != nil { diff --git a/cmd/workspace/table-constraints/table-constraints.go b/cmd/workspace/table-constraints/table-constraints.go index 800e43338c..de91465e96 100755 --- a/cmd/workspace/table-constraints/table-constraints.go +++ b/cmd/workspace/table-constraints/table-constraints.go @@ -116,9 +116,6 @@ var deleteCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(3) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -130,13 +127,12 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - deleteReq.FullName = args[0] - deleteReq.ConstraintName = args[1] - _, err = fmt.Sscan(args[2], &deleteReq.Cascade) - if err != nil { - return fmt.Errorf("invalid CASCADE: %s", args[2]) - } + } + deleteReq.FullName = args[0] + deleteReq.ConstraintName = args[1] + _, err = fmt.Sscan(args[2], &deleteReq.Cascade) + if err != nil { + return fmt.Errorf("invalid CASCADE: %s", args[2]) } err = w.TableConstraints.Delete(ctx, deleteReq) diff --git a/cmd/workspace/tables/tables.go b/cmd/workspace/tables/tables.go index 17c26359ef..4de5893348 100755 --- a/cmd/workspace/tables/tables.go +++ b/cmd/workspace/tables/tables.go @@ -62,26 +62,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No FULL_NAME argument specified. Loading names for Tables drop-down." - names, err := w.Tables.TableInfoNameToTableIdMap(ctx, catalog.ListTablesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Tables drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Full name of the table") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No FULL_NAME argument specified. Loading names for Tables drop-down." + names, err := w.Tables.TableInfoNameToTableIdMap(ctx, catalog.ListTablesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Tables drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have full name of the table") + id, err := cmdio.Select(ctx, names, "Full name of the table") + if err != nil { + return err } - deleteReq.FullName = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have full name of the table") } + deleteReq.FullName = args[0] err = w.Tables.Delete(ctx, deleteReq) if err != nil { @@ -129,26 +128,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No FULL_NAME argument specified. Loading names for Tables drop-down." - names, err := w.Tables.TableInfoNameToTableIdMap(ctx, catalog.ListTablesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Tables drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Full name of the table") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No FULL_NAME argument specified. Loading names for Tables drop-down." + names, err := w.Tables.TableInfoNameToTableIdMap(ctx, catalog.ListTablesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Tables drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have full name of the table") + id, err := cmdio.Select(ctx, names, "Full name of the table") + if err != nil { + return err } - getReq.FullName = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have full name of the table") + } + getReq.FullName = args[0] response, err := w.Tables.Get(ctx, getReq) if err != nil { @@ -192,9 +190,6 @@ var listCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -206,10 +201,9 @@ var listCmd = &cobra.Command{ if err != nil { return err } - } else { - listReq.CatalogName = args[0] - listReq.SchemaName = args[1] } + listReq.CatalogName = args[0] + listReq.SchemaName = args[1] response, err := w.Tables.ListAll(ctx, listReq) if err != nil { @@ -266,26 +260,25 @@ var listSummariesCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No CATALOG_NAME argument specified. Loading names for Tables drop-down." - names, err := w.Tables.TableInfoNameToTableIdMap(ctx, catalog.ListTablesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Tables drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Name of parent catalog for tables of interest") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No CATALOG_NAME argument specified. Loading names for Tables drop-down." + names, err := w.Tables.TableInfoNameToTableIdMap(ctx, catalog.ListTablesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Tables drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have name of parent catalog for tables of interest") + id, err := cmdio.Select(ctx, names, "Name of parent catalog for tables of interest") + if err != nil { + return err } - listSummariesReq.CatalogName = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have name of parent catalog for tables of interest") } + listSummariesReq.CatalogName = args[0] response, err := w.Tables.ListSummariesAll(ctx, listSummariesReq) if err != nil { diff --git a/cmd/workspace/token-management/token-management.go b/cmd/workspace/token-management/token-management.go index 749dbdb008..f6563fbd26 100755 --- a/cmd/workspace/token-management/token-management.go +++ b/cmd/workspace/token-management/token-management.go @@ -109,26 +109,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No TOKEN_ID argument specified. Loading names for Token Management drop-down." - names, err := w.TokenManagement.TokenInfoCommentToTokenIdMap(ctx, settings.ListTokenManagementRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Token Management drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID of the token to get") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No TOKEN_ID argument specified. Loading names for Token Management drop-down." + names, err := w.TokenManagement.TokenInfoCommentToTokenIdMap(ctx, settings.ListTokenManagementRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Token Management drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the id of the token to get") + id, err := cmdio.Select(ctx, names, "The ID of the token to get") + if err != nil { + return err } - deleteReq.TokenId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id of the token to get") } + deleteReq.TokenId = args[0] err = w.TokenManagement.Delete(ctx, deleteReq) if err != nil { @@ -170,26 +169,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No TOKEN_ID argument specified. Loading names for Token Management drop-down." - names, err := w.TokenManagement.TokenInfoCommentToTokenIdMap(ctx, settings.ListTokenManagementRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Token Management drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The ID of the token to get") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No TOKEN_ID argument specified. Loading names for Token Management drop-down." + names, err := w.TokenManagement.TokenInfoCommentToTokenIdMap(ctx, settings.ListTokenManagementRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Token Management drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the id of the token to get") + id, err := cmdio.Select(ctx, names, "The ID of the token to get") + if err != nil { + return err } - getReq.TokenId = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the id of the token to get") } + getReq.TokenId = args[0] response, err := w.TokenManagement.Get(ctx, getReq) if err != nil { diff --git a/cmd/workspace/users/users.go b/cmd/workspace/users/users.go index 0a2ced7b7e..08c20ade96 100755 --- a/cmd/workspace/users/users.go +++ b/cmd/workspace/users/users.go @@ -123,26 +123,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Users drop-down." - names, err := w.Users.UserUserNameToIdMap(ctx, iam.ListUsersRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Users drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks workspace") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Users drop-down." + names, err := w.Users.UserUserNameToIdMap(ctx, iam.ListUsersRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Users drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks workspace") + id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks workspace") + if err != nil { + return err } - deleteReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a user in the databricks workspace") } + deleteReq.Id = args[0] err = w.Users.Delete(ctx, deleteReq) if err != nil { @@ -184,26 +183,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Users drop-down." - names, err := w.Users.UserUserNameToIdMap(ctx, iam.ListUsersRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Users drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks workspace") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Users drop-down." + names, err := w.Users.UserUserNameToIdMap(ctx, iam.ListUsersRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Users drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks workspace") + id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks workspace") + if err != nil { + return err } - getReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a user in the databricks workspace") } + getReq.Id = args[0] response, err := w.Users.Get(ctx, getReq) if err != nil { @@ -306,26 +304,25 @@ var patchCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Users drop-down." - names, err := w.Users.UserUserNameToIdMap(ctx, iam.ListUsersRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Users drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks workspace") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Users drop-down." + names, err := w.Users.UserUserNameToIdMap(ctx, iam.ListUsersRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Users drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks workspace") + id, err := cmdio.Select(ctx, names, "Unique ID for a user in the Databricks workspace") + if err != nil { + return err } - patchReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have unique id for a user in the databricks workspace") } + patchReq.Id = args[0] err = w.Users.Patch(ctx, patchReq) if err != nil { diff --git a/cmd/workspace/volumes/volumes.go b/cmd/workspace/volumes/volumes.go index d1400f52f9..4dbcf41560 100755 --- a/cmd/workspace/volumes/volumes.go +++ b/cmd/workspace/volumes/volumes.go @@ -141,26 +141,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No FULL_NAME_ARG argument specified. Loading names for Volumes drop-down." - names, err := w.Volumes.VolumeInfoNameToVolumeIdMap(ctx, catalog.ListVolumesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Volumes drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The three-level (fully qualified) name of the volume") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No FULL_NAME_ARG argument specified. Loading names for Volumes drop-down." + names, err := w.Volumes.VolumeInfoNameToVolumeIdMap(ctx, catalog.ListVolumesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Volumes drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the three-level (fully qualified) name of the volume") + id, err := cmdio.Select(ctx, names, "The three-level (fully qualified) name of the volume") + if err != nil { + return err } - deleteReq.FullNameArg = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the three-level (fully qualified) name of the volume") } + deleteReq.FullNameArg = args[0] err = w.Volumes.Delete(ctx, deleteReq) if err != nil { @@ -205,9 +204,6 @@ var listCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(2) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -219,10 +215,9 @@ var listCmd = &cobra.Command{ if err != nil { return err } - } else { - listReq.CatalogName = args[0] - listReq.SchemaName = args[1] } + listReq.CatalogName = args[0] + listReq.SchemaName = args[1] response, err := w.Volumes.ListAll(ctx, listReq) if err != nil { @@ -269,26 +264,25 @@ var readCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No FULL_NAME_ARG argument specified. Loading names for Volumes drop-down." - names, err := w.Volumes.VolumeInfoNameToVolumeIdMap(ctx, catalog.ListVolumesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Volumes drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The three-level (fully qualified) name of the volume") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No FULL_NAME_ARG argument specified. Loading names for Volumes drop-down." + names, err := w.Volumes.VolumeInfoNameToVolumeIdMap(ctx, catalog.ListVolumesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Volumes drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the three-level (fully qualified) name of the volume") + id, err := cmdio.Select(ctx, names, "The three-level (fully qualified) name of the volume") + if err != nil { + return err } - readReq.FullNameArg = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the three-level (fully qualified) name of the volume") } + readReq.FullNameArg = args[0] response, err := w.Volumes.Read(ctx, readReq) if err != nil { @@ -341,26 +335,25 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No FULL_NAME_ARG argument specified. Loading names for Volumes drop-down." - names, err := w.Volumes.VolumeInfoNameToVolumeIdMap(ctx, catalog.ListVolumesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Volumes drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The three-level (fully qualified) name of the volume") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No FULL_NAME_ARG argument specified. Loading names for Volumes drop-down." + names, err := w.Volumes.VolumeInfoNameToVolumeIdMap(ctx, catalog.ListVolumesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Volumes drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the three-level (fully qualified) name of the volume") + id, err := cmdio.Select(ctx, names, "The three-level (fully qualified) name of the volume") + if err != nil { + return err } - updateReq.FullNameArg = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have the three-level (fully qualified) name of the volume") } + updateReq.FullNameArg = args[0] response, err := w.Volumes.Update(ctx, updateReq) if err != nil { diff --git a/cmd/workspace/warehouses/warehouses.go b/cmd/workspace/warehouses/warehouses.go index 9b2a5c0033..1c7ca23b1b 100755 --- a/cmd/workspace/warehouses/warehouses.go +++ b/cmd/workspace/warehouses/warehouses.go @@ -141,26 +141,25 @@ var deleteCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." - names, err := w.Warehouses.EndpointInfoNameToIdMap(ctx, sql.ListWarehousesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Warehouses drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Required") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." + names, err := w.Warehouses.EndpointInfoNameToIdMap(ctx, sql.ListWarehousesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Warehouses drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have required") + id, err := cmdio.Select(ctx, names, "Required") + if err != nil { + return err } - deleteReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have required") } + deleteReq.Id = args[0] err = w.Warehouses.Delete(ctx, deleteReq) if err != nil { @@ -221,26 +220,25 @@ var editCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." - names, err := w.Warehouses.EndpointInfoNameToIdMap(ctx, sql.ListWarehousesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Warehouses drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Required") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." + names, err := w.Warehouses.EndpointInfoNameToIdMap(ctx, sql.ListWarehousesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Warehouses drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have required") + id, err := cmdio.Select(ctx, names, "Required") + if err != nil { + return err } - editReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have required") } + editReq.Id = args[0] wait, err := w.Warehouses.Edit(ctx, editReq) if err != nil { @@ -306,26 +304,25 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." - names, err := w.Warehouses.EndpointInfoNameToIdMap(ctx, sql.ListWarehousesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Warehouses drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Required") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." + names, err := w.Warehouses.EndpointInfoNameToIdMap(ctx, sql.ListWarehousesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Warehouses drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have required") + id, err := cmdio.Select(ctx, names, "Required") + if err != nil { + return err } - getReq.Id = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have required") + } + getReq.Id = args[0] response, err := w.Warehouses.Get(ctx, getReq) if err != nil { @@ -516,26 +513,25 @@ var startCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." - names, err := w.Warehouses.EndpointInfoNameToIdMap(ctx, sql.ListWarehousesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Warehouses drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Required") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." + names, err := w.Warehouses.EndpointInfoNameToIdMap(ctx, sql.ListWarehousesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Warehouses drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have required") + id, err := cmdio.Select(ctx, names, "Required") + if err != nil { + return err } - startReq.Id = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have required") + } + startReq.Id = args[0] wait, err := w.Warehouses.Start(ctx, startReq) if err != nil { @@ -601,26 +597,25 @@ var stopCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." - names, err := w.Warehouses.EndpointInfoNameToIdMap(ctx, sql.ListWarehousesRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Warehouses drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "Required") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." + names, err := w.Warehouses.EndpointInfoNameToIdMap(ctx, sql.ListWarehousesRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Warehouses drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have required") + id, err := cmdio.Select(ctx, names, "Required") + if err != nil { + return err } - stopReq.Id = args[0] + args = append(args, id) + } + if len(args) != 1 { + return fmt.Errorf("expected to have required") } + stopReq.Id = args[0] wait, err := w.Warehouses.Stop(ctx, stopReq) if err != nil { diff --git a/cmd/workspace/workspace-bindings/workspace-bindings.go b/cmd/workspace/workspace-bindings/workspace-bindings.go index 4c05f60ba5..fdebd9dd24 100755 --- a/cmd/workspace/workspace-bindings/workspace-bindings.go +++ b/cmd/workspace/workspace-bindings/workspace-bindings.go @@ -47,9 +47,6 @@ var getCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -61,9 +58,8 @@ var getCmd = &cobra.Command{ if err != nil { return err } - } else { - getReq.Name = args[0] } + getReq.Name = args[0] response, err := w.WorkspaceBindings.Get(ctx, getReq) if err != nil { @@ -102,9 +98,6 @@ var updateCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -116,9 +109,8 @@ var updateCmd = &cobra.Command{ if err != nil { return err } - } else { - updateReq.Name = args[0] } + updateReq.Name = args[0] response, err := w.WorkspaceBindings.Update(ctx, updateReq) if err != nil { diff --git a/cmd/workspace/workspace-conf/workspace-conf.go b/cmd/workspace/workspace-conf/workspace-conf.go index 0a0a48fde6..233e3eabb4 100755 --- a/cmd/workspace/workspace-conf/workspace-conf.go +++ b/cmd/workspace/workspace-conf/workspace-conf.go @@ -41,9 +41,6 @@ var getStatusCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -55,9 +52,8 @@ var getStatusCmd = &cobra.Command{ if err != nil { return err } - } else { - getStatusReq.Keys = args[0] } + getStatusReq.Keys = args[0] response, err := w.WorkspaceConf.GetStatus(ctx, getStatusReq) if err != nil { diff --git a/cmd/workspace/workspace/workspace.go b/cmd/workspace/workspace/workspace.go index 6a51c47176..f20d4b67be 100755 --- a/cmd/workspace/workspace/workspace.go +++ b/cmd/workspace/workspace/workspace.go @@ -133,26 +133,25 @@ var exportCmd = &cobra.Command{ if err != nil { return err } - } else { - if len(args) == 0 { - promptSpinner := cmdio.Spinner(ctx) - promptSpinner <- "No PATH argument specified. Loading names for Workspace drop-down." - names, err := w.Workspace.ObjectInfoPathToObjectIdMap(ctx, workspace.ListWorkspaceRequest{}) - close(promptSpinner) - if err != nil { - return fmt.Errorf("failed to load names for Workspace drop-down. Please manually specify required arguments. Original error: %w", err) - } - id, err := cmdio.Select(ctx, names, "The absolute path of the object or directory") - if err != nil { - return err - } - args = append(args, id) + } + if len(args) == 0 { + promptSpinner := cmdio.Spinner(ctx) + promptSpinner <- "No PATH argument specified. Loading names for Workspace drop-down." + names, err := w.Workspace.ObjectInfoPathToObjectIdMap(ctx, workspace.ListWorkspaceRequest{}) + close(promptSpinner) + if err != nil { + return fmt.Errorf("failed to load names for Workspace drop-down. Please manually specify required arguments. Original error: %w", err) } - if len(args) != 1 { - return fmt.Errorf("expected to have the absolute path of the object or directory") + id, err := cmdio.Select(ctx, names, "The absolute path of the object or directory") + if err != nil { + return err } - exportReq.Path = args[0] + args = append(args, id) } + if len(args) != 1 { + return fmt.Errorf("expected to have the absolute path of the object or directory") + } + exportReq.Path = args[0] response, err := w.Workspace.Export(ctx, exportReq) if err != nil { @@ -188,9 +187,6 @@ var getStatusCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -202,9 +198,8 @@ var getStatusCmd = &cobra.Command{ if err != nil { return err } - } else { - getStatusReq.Path = args[0] } + getStatusReq.Path = args[0] response, err := w.Workspace.GetStatus(ctx, getStatusReq) if err != nil { @@ -302,9 +297,6 @@ var listCmd = &cobra.Command{ Annotations: map[string]string{}, Args: func(cmd *cobra.Command, args []string) error { check := cobra.ExactArgs(1) - if cmd.Flags().Changed("json") { - check = cobra.ExactArgs(0) - } return check(cmd, args) }, PreRunE: root.MustWorkspaceClient, @@ -316,9 +308,8 @@ var listCmd = &cobra.Command{ if err != nil { return err } - } else { - listReq.Path = args[0] } + listReq.Path = args[0] response, err := w.Workspace.ListAll(ctx, listReq) if err != nil { diff --git a/go.mod b/go.mod index f0d9060813..3294e20257 100644 --- a/go.mod +++ b/go.mod @@ -56,7 +56,7 @@ require ( golang.org/x/time v0.3.0 // indirect google.golang.org/api v0.129.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230628200519-e449d1ea0e82 // indirect google.golang.org/grpc v1.56.1 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 870d2ab2df..6e05f14fe0 100644 --- a/go.sum +++ b/go.sum @@ -253,8 +253,8 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc h1:XSJ8Vk1SWuNr8S18z1NZSziL0CPIXLCCMDOEFtHBOFc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230628200519-e449d1ea0e82 h1:6b+zGQBiXFlAMpQr+cCarAdrZD4QgXSG7uUZadYysgg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230628200519-e449d1ea0e82/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= From b9be6310218176ea86e2c9a07f2cc68f1e7e7dd5 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Thu, 29 Jun 2023 16:08:07 +0200 Subject: [PATCH 2/5] Remove --json field when not needed --- .codegen/service.go.tmpl | 13 +- cmd/account/access-control/access-control.go | 22 +-- cmd/account/billable-usage/billable-usage.go | 11 +- cmd/account/budgets/budgets.go | 24 +-- cmd/account/credentials/credentials.go | 22 +-- .../custom-app-integration.go | 24 +-- .../encryption-keys/encryption-keys.go | 22 +-- cmd/account/groups/groups.go | 28 +--- .../ip-access-lists/ip-access-lists.go | 26 +--- cmd/account/log-delivery/log-delivery.go | 24 +-- .../metastore-assignments.go | 34 +---- cmd/account/metastores/metastores.go | 24 +-- cmd/account/networks/networks.go | 22 +-- .../o-auth-enrollment/o-auth-enrollment.go | 2 +- cmd/account/private-access/private-access.go | 24 +-- .../published-app-integration.go | 24 +-- .../service-principal-secrets.go | 31 +--- .../service-principals/service-principals.go | 28 +--- cmd/account/settings/settings.go | 6 +- .../storage-credentials.go | 34 +---- cmd/account/storage/storage.go | 22 +-- cmd/account/users/users.go | 28 +--- cmd/account/vpc-endpoints/vpc-endpoints.go | 22 +-- .../workspace-assignment.go | 32 +--- cmd/account/workspaces/workspaces.go | 34 +---- .../access-control-proxy.go | 22 +-- cmd/workspace/alerts/alerts.go | 24 +-- cmd/workspace/catalogs/catalogs.go | 24 +-- .../cluster-policies/cluster-policies.go | 18 +-- cmd/workspace/clusters/clusters.go | 41 +++-- cmd/workspace/connections/connections.go | 24 +-- cmd/workspace/dashboards/dashboards.go | 34 +---- cmd/workspace/experiments/experiments.go | 80 +++------- .../external-locations/external-locations.go | 24 +-- cmd/workspace/functions/functions.go | 42 +---- .../git-credentials/git-credentials.go | 32 +--- .../global-init-scripts.go | 32 +--- cmd/workspace/grants/grants.go | 22 +-- cmd/workspace/groups/groups.go | 28 +--- .../instance-pools/instance-pools.go | 16 +- .../instance-profiles/instance-profiles.go | 6 +- .../ip-access-lists/ip-access-lists.go | 26 +--- cmd/workspace/jobs/jobs.go | 69 +++------ cmd/workspace/libraries/libraries.go | 14 +- cmd/workspace/metastores/metastores.go | 64 +------- .../model-registry/model-registry.go | 144 ++++-------------- cmd/workspace/permissions/permissions.go | 24 +-- cmd/workspace/pipelines/pipelines.go | 73 ++------- .../policy-families/policy-families.go | 12 +- cmd/workspace/providers/providers.go | 36 +---- cmd/workspace/queries/queries.go | 36 +---- cmd/workspace/query-history/query-history.go | 2 +- .../recipient-activation.go | 21 +-- cmd/workspace/recipients/recipients.go | 46 +----- cmd/workspace/repos/overrides.go | 27 +--- cmd/workspace/repos/repos.go | 26 +--- cmd/workspace/schemas/schemas.go | 34 +---- cmd/workspace/secrets/secrets.go | 40 +---- .../service-principals/service-principals.go | 28 +--- .../serving-endpoints/serving-endpoints.go | 66 ++------ cmd/workspace/shares/shares.go | 36 +---- .../storage-credentials.go | 26 +--- .../system-schemas/system-schemas.go | 31 +--- .../table-constraints/table-constraints.go | 12 +- cmd/workspace/tables/tables.go | 41 +---- .../token-management/token-management.go | 24 +-- cmd/workspace/tokens/tokens.go | 4 +- cmd/workspace/users/users.go | 28 +--- cmd/workspace/volumes/volumes.go | 42 +---- cmd/workspace/warehouses/warehouses.go | 53 ++----- .../workspace-bindings/workspace-bindings.go | 12 +- .../workspace-conf/workspace-conf.go | 12 +- cmd/workspace/workspace/workspace.go | 36 +---- 73 files changed, 417 insertions(+), 1780 deletions(-) diff --git a/.codegen/service.go.tmpl b/.codegen/service.go.tmpl index 46ff4c90ef..64c80b9a89 100644 --- a/.codegen/service.go.tmpl +++ b/.codegen/service.go.tmpl @@ -44,9 +44,14 @@ var Cmd = &cobra.Command{ {{end}} // start {{.KebabName}} command -{{if .Request}}var {{.CamelName}}Req {{.Service.Package.Name}}.{{.Request.PascalName}} +{{- $useJsonForAllFields := or .IsJsonOnly (and .Request (or (not .Request.IsAllRequiredFieldsPrimitive) .Request.IsAllRequiredFieldsJsonUnserialisable)) -}} +{{- $needJsonFlag := or $useJsonForAllFields (and .Request (not .Request.IsOnlyPrimitiveFields)) -}} +{{- if .Request}} +var {{.CamelName}}Req {{.Service.Package.Name}}.{{.Request.PascalName}} +{{- if $needJsonFlag}} var {{.CamelName}}Json flags.JsonFlag {{- end}} +{{end}} {{if .Wait}}var {{.CamelName}}SkipWait bool var {{.CamelName}}Timeout time.Duration{{end}} @@ -57,7 +62,9 @@ func init() { {{.CamelName}}Cmd.Flags().DurationVar(&{{.CamelName}}Timeout, "timeout", {{.Wait.Timeout}}*time.Minute, `maximum amount of time to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state`) {{end -}} {{if .Request}}// TODO: short flags + {{- if $needJsonFlag}} {{.CamelName}}Cmd.Flags().Var(&{{.CamelName}}Json, "json", `either inline JSON string or @path/to/file.json with request body`) + {{- end}} {{$method := .}} {{ if not .IsJsonOnly }} {{range .Request.Fields -}} @@ -85,7 +92,6 @@ func init() { {{- $hasIdPrompt := and (not $noPrompt) (and $hasSinglePosArg $serviceHasNamedIdMap) -}} {{- $wait := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}} {{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}} -{{- $useJsonForAllFields := or .IsJsonOnly (and .Request (or (not .Request.IsAllRequiredFieldsPrimitive) .Request.IsAllRequiredFieldsJsonUnserialisable)) -}} var {{.CamelName}}Cmd = &cobra.Command{ Use: "{{.KebabName}}{{if $hasPosArgs}}{{range .Request.RequiredFields}} {{.ConstantName}}{{end}}{{end}}", {{- if .Description }} @@ -113,12 +119,13 @@ var {{.CamelName}}Cmd = &cobra.Command{ ctx := cmd.Context() {{if .Service.IsAccounts}}a := root.AccountClient(ctx){{else}}w := root.WorkspaceClient(ctx){{end}} {{- if .Request }} + {{ if $needJsonFlag }} if cmd.Flags().Changed("json") { err = {{.CamelName}}Json.Unmarshal(&{{.CamelName}}Req) if err != nil { return err } - }{{if $useJsonForAllFields }} else { + }{{end}}{{if $useJsonForAllFields }} else { {{- end }} {{- if $hasIdPrompt}} if len(args) == 0 { diff --git a/cmd/account/access-control/access-control.go b/cmd/account/access-control/access-control.go index 216f49b698..5cec69a312 100755 --- a/cmd/account/access-control/access-control.go +++ b/cmd/account/access-control/access-control.go @@ -24,14 +24,11 @@ var Cmd = &cobra.Command{ } // start get-assignable-roles-for-resource command - var getAssignableRolesForResourceReq iam.GetAssignableRolesForResourceRequest -var getAssignableRolesForResourceJson flags.JsonFlag func init() { Cmd.AddCommand(getAssignableRolesForResourceCmd) // TODO: short flags - getAssignableRolesForResourceCmd.Flags().Var(&getAssignableRolesForResourceJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -53,12 +50,7 @@ var getAssignableRolesForResourceCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getAssignableRolesForResourceJson.Unmarshal(&getAssignableRolesForResourceReq) - if err != nil { - return err - } - } + getAssignableRolesForResourceReq.Resource = args[0] response, err := a.AccessControl.GetAssignableRolesForResource(ctx, getAssignableRolesForResourceReq) @@ -73,14 +65,11 @@ var getAssignableRolesForResourceCmd = &cobra.Command{ } // start get-rule-set command - var getRuleSetReq iam.GetRuleSetRequest -var getRuleSetJson flags.JsonFlag func init() { Cmd.AddCommand(getRuleSetCmd) // TODO: short flags - getRuleSetCmd.Flags().Var(&getRuleSetJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -102,12 +91,7 @@ var getRuleSetCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getRuleSetJson.Unmarshal(&getRuleSetReq) - if err != nil { - return err - } - } + getRuleSetReq.Name = args[0] getRuleSetReq.Etag = args[1] @@ -123,7 +107,6 @@ var getRuleSetCmd = &cobra.Command{ } // start update-rule-set command - var updateRuleSetReq iam.UpdateRuleSetRequest var updateRuleSetJson flags.JsonFlag @@ -148,6 +131,7 @@ var updateRuleSetCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateRuleSetJson.Unmarshal(&updateRuleSetReq) if err != nil { diff --git a/cmd/account/billable-usage/billable-usage.go b/cmd/account/billable-usage/billable-usage.go index 20b4cb2a21..babc7bc2ca 100755 --- a/cmd/account/billable-usage/billable-usage.go +++ b/cmd/account/billable-usage/billable-usage.go @@ -4,7 +4,6 @@ package billable_usage import ( "github.com/databricks/cli/cmd/root" - "github.com/databricks/cli/libs/flags" "github.com/databricks/databricks-sdk-go/service/billing" "github.com/spf13/cobra" ) @@ -20,14 +19,11 @@ var Cmd = &cobra.Command{ } // start download command - var downloadReq billing.DownloadRequest -var downloadJson flags.JsonFlag func init() { Cmd.AddCommand(downloadCmd) // TODO: short flags - downloadCmd.Flags().Var(&downloadJson, "json", `either inline JSON string or @path/to/file.json with request body`) downloadCmd.Flags().BoolVar(&downloadReq.PersonalData, "personal-data", downloadReq.PersonalData, `Specify whether to include personally identifiable information in the billable usage logs, for example the email addresses of cluster creators.`) @@ -58,12 +54,7 @@ var downloadCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = downloadJson.Unmarshal(&downloadReq) - if err != nil { - return err - } - } + downloadReq.StartMonth = args[0] downloadReq.EndMonth = args[1] diff --git a/cmd/account/budgets/budgets.go b/cmd/account/budgets/budgets.go index a5831198a1..3e26b181a8 100755 --- a/cmd/account/budgets/budgets.go +++ b/cmd/account/budgets/budgets.go @@ -26,7 +26,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq billing.WrappedBudget var createJson flags.JsonFlag @@ -49,6 +48,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -70,14 +70,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq billing.DeleteBudgetRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -93,12 +90,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No BUDGET_ID argument specified. Loading names for Budgets drop-down." @@ -130,14 +122,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq billing.GetBudgetRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -154,12 +143,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No BUDGET_ID argument specified. Loading names for Budgets drop-down." @@ -222,7 +206,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq billing.WrappedBudget var updateJson flags.JsonFlag @@ -246,6 +229,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/credentials/credentials.go b/cmd/account/credentials/credentials.go index b1ec7e1763..5a1362d15c 100755 --- a/cmd/account/credentials/credentials.go +++ b/cmd/account/credentials/credentials.go @@ -26,7 +26,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq provisioning.CreateCredentialRequest var createJson flags.JsonFlag @@ -62,6 +61,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -83,14 +83,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq provisioning.DeleteCredentialRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -108,12 +105,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No CREDENTIALS_ID argument specified. Loading names for Credentials drop-down." @@ -145,14 +137,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq provisioning.GetCredentialRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -169,12 +158,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No CREDENTIALS_ID argument specified. Loading names for Credentials drop-down." diff --git a/cmd/account/custom-app-integration/custom-app-integration.go b/cmd/account/custom-app-integration/custom-app-integration.go index 6e4a496085..837ac5188a 100755 --- a/cmd/account/custom-app-integration/custom-app-integration.go +++ b/cmd/account/custom-app-integration/custom-app-integration.go @@ -28,7 +28,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq oauth2.CreateCustomAppIntegration var createJson flags.JsonFlag @@ -57,6 +56,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -78,14 +78,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq oauth2.DeleteCustomAppIntegrationRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -106,12 +103,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + deleteReq.IntegrationId = args[0] err = a.CustomAppIntegration.Delete(ctx, deleteReq) @@ -126,14 +118,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq oauth2.GetCustomAppIntegrationRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -153,12 +142,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.IntegrationId = args[0] response, err := a.CustomAppIntegration.Get(ctx, getReq) @@ -204,7 +188,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq oauth2.UpdateCustomAppIntegration var updateJson flags.JsonFlag @@ -235,6 +218,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/encryption-keys/encryption-keys.go b/cmd/account/encryption-keys/encryption-keys.go index aea1826773..0db4af80e8 100755 --- a/cmd/account/encryption-keys/encryption-keys.go +++ b/cmd/account/encryption-keys/encryption-keys.go @@ -37,7 +37,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq provisioning.CreateCustomerManagedKeyRequest var createJson flags.JsonFlag @@ -79,6 +78,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -100,14 +100,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq provisioning.DeleteEncryptionKeyRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -128,12 +125,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + deleteReq.CustomerManagedKeyId = args[0] err = a.EncryptionKeys.Delete(ctx, deleteReq) @@ -148,14 +140,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq provisioning.GetEncryptionKeyRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -189,12 +178,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.CustomerManagedKeyId = args[0] response, err := a.EncryptionKeys.Get(ctx, getReq) diff --git a/cmd/account/groups/groups.go b/cmd/account/groups/groups.go index 6174249797..5897ef292b 100755 --- a/cmd/account/groups/groups.go +++ b/cmd/account/groups/groups.go @@ -28,7 +28,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq iam.Group var createJson flags.JsonFlag @@ -68,6 +67,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -88,14 +88,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq iam.DeleteAccountGroupRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -111,12 +108,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Account Groups drop-down." @@ -148,14 +140,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq iam.GetAccountGroupRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -171,12 +160,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Account Groups drop-down." @@ -208,7 +192,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListAccountGroupsRequest var listJson flags.JsonFlag @@ -246,6 +229,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -266,7 +250,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -291,6 +274,7 @@ var patchCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = patchJson.Unmarshal(&patchReq) if err != nil { @@ -328,7 +312,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.Group var updateJson flags.JsonFlag @@ -360,6 +343,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/ip-access-lists/ip-access-lists.go b/cmd/account/ip-access-lists/ip-access-lists.go index 8d0d4b7dcf..7f43ff2a71 100755 --- a/cmd/account/ip-access-lists/ip-access-lists.go +++ b/cmd/account/ip-access-lists/ip-access-lists.go @@ -43,7 +43,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq settings.CreateIpAccessList var createJson flags.JsonFlag @@ -79,6 +78,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -100,14 +100,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq settings.DeleteAccountIpAccessListRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -123,12 +120,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Account Ip Access Lists drop-down." @@ -160,14 +152,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq settings.GetAccountIpAccessListRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -183,12 +172,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Account Ip Access Lists drop-down." @@ -250,7 +234,6 @@ var listCmd = &cobra.Command{ } // start replace command - var replaceReq settings.ReplaceIpAccessList var replaceJson flags.JsonFlag @@ -284,6 +267,7 @@ var replaceCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = replaceJson.Unmarshal(&replaceReq) if err != nil { @@ -305,7 +289,6 @@ var replaceCmd = &cobra.Command{ } // start update command - var updateReq settings.UpdateIpAccessList var updateJson flags.JsonFlag @@ -343,6 +326,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/log-delivery/log-delivery.go b/cmd/account/log-delivery/log-delivery.go index c8472b0176..d5ae87b1b8 100755 --- a/cmd/account/log-delivery/log-delivery.go +++ b/cmd/account/log-delivery/log-delivery.go @@ -81,7 +81,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq billing.WrappedCreateLogDeliveryConfiguration var createJson flags.JsonFlag @@ -138,6 +137,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -158,14 +158,11 @@ var createCmd = &cobra.Command{ } // start get command - var getReq billing.GetLogDeliveryRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -182,12 +179,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No LOG_DELIVERY_CONFIGURATION_ID argument specified. Loading names for Log Delivery drop-down." @@ -219,7 +211,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq billing.ListLogDeliveryRequest var listJson flags.JsonFlag @@ -254,6 +245,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -274,14 +266,11 @@ var listCmd = &cobra.Command{ } // start patch-status command - var patchStatusReq billing.UpdateLogDeliveryConfigurationStatusRequest -var patchStatusJson flags.JsonFlag func init() { Cmd.AddCommand(patchStatusCmd) // TODO: short flags - patchStatusCmd.Flags().Var(&patchStatusJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -305,12 +294,7 @@ var patchStatusCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = patchStatusJson.Unmarshal(&patchStatusReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &patchStatusReq.Status) if err != nil { return fmt.Errorf("invalid STATUS: %s", args[0]) diff --git a/cmd/account/metastore-assignments/metastore-assignments.go b/cmd/account/metastore-assignments/metastore-assignments.go index 9e10bc214a..673bb8f4cf 100755 --- a/cmd/account/metastore-assignments/metastore-assignments.go +++ b/cmd/account/metastore-assignments/metastore-assignments.go @@ -22,7 +22,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.AccountsCreateMetastoreAssignment var createJson flags.JsonFlag @@ -52,6 +51,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -76,14 +76,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteAccountMetastoreAssignmentRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -105,12 +102,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &deleteReq.WorkspaceId) if err != nil { return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) @@ -129,14 +121,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetAccountMetastoreAssignmentRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -160,12 +149,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &getReq.WorkspaceId) if err != nil { return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) @@ -183,14 +167,11 @@ var getCmd = &cobra.Command{ } // start list command - var listReq catalog.ListAccountMetastoreAssignmentsRequest -var listJson flags.JsonFlag func init() { Cmd.AddCommand(listCmd) // TODO: short flags - listCmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -212,12 +193,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = listJson.Unmarshal(&listReq) - if err != nil { - return err - } - } + listReq.MetastoreId = args[0] response, err := a.MetastoreAssignments.List(ctx, listReq) @@ -232,7 +208,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.AccountsUpdateMetastoreAssignment var updateJson flags.JsonFlag @@ -263,6 +238,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/metastores/metastores.go b/cmd/account/metastores/metastores.go index ad8a4be7b7..decbb40602 100755 --- a/cmd/account/metastores/metastores.go +++ b/cmd/account/metastores/metastores.go @@ -21,7 +21,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.AccountsCreateMetastore var createJson flags.JsonFlag @@ -54,6 +53,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -74,14 +74,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteAccountMetastoreRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -102,12 +99,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + deleteReq.MetastoreId = args[0] err = a.Metastores.Delete(ctx, deleteReq) @@ -122,14 +114,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetAccountMetastoreRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -150,12 +139,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.MetastoreId = args[0] response, err := a.Metastores.Get(ctx, getReq) @@ -202,7 +186,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.AccountsUpdateMetastore var updateJson flags.JsonFlag @@ -232,6 +215,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/networks/networks.go b/cmd/account/networks/networks.go index a12b27f7e0..331f0869a4 100755 --- a/cmd/account/networks/networks.go +++ b/cmd/account/networks/networks.go @@ -23,7 +23,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq provisioning.CreateNetworkRequest var createJson flags.JsonFlag @@ -61,6 +60,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -82,14 +82,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq provisioning.DeleteNetworkRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -110,12 +107,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NETWORK_ID argument specified. Loading names for Networks drop-down." @@ -147,14 +139,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq provisioning.GetNetworkRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -171,12 +160,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NETWORK_ID argument specified. Loading names for Networks drop-down." diff --git a/cmd/account/o-auth-enrollment/o-auth-enrollment.go b/cmd/account/o-auth-enrollment/o-auth-enrollment.go index 62961da574..a39306a371 100755 --- a/cmd/account/o-auth-enrollment/o-auth-enrollment.go +++ b/cmd/account/o-auth-enrollment/o-auth-enrollment.go @@ -24,7 +24,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq oauth2.CreateOAuthEnrollment var createJson flags.JsonFlag @@ -64,6 +63,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { diff --git a/cmd/account/private-access/private-access.go b/cmd/account/private-access/private-access.go index f9e3bd1480..ebb31dd033 100755 --- a/cmd/account/private-access/private-access.go +++ b/cmd/account/private-access/private-access.go @@ -22,7 +22,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq provisioning.UpsertPrivateAccessSettingsRequest var createJson flags.JsonFlag @@ -70,6 +69,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -92,14 +92,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq provisioning.DeletePrivateAccesRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -122,12 +119,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No PRIVATE_ACCESS_SETTINGS_ID argument specified. Loading names for Private Access drop-down." @@ -159,14 +151,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq provisioning.GetPrivateAccesRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -189,12 +178,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No PRIVATE_ACCESS_SETTINGS_ID argument specified. Loading names for Private Access drop-down." @@ -257,7 +241,6 @@ var listCmd = &cobra.Command{ } // start replace command - var replaceReq provisioning.UpsertPrivateAccessSettingsRequest var replaceJson flags.JsonFlag @@ -308,6 +291,7 @@ var replaceCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = replaceJson.Unmarshal(&replaceReq) if err != nil { diff --git a/cmd/account/published-app-integration/published-app-integration.go b/cmd/account/published-app-integration/published-app-integration.go index f0a02b6cfe..7eb6d4c9ee 100755 --- a/cmd/account/published-app-integration/published-app-integration.go +++ b/cmd/account/published-app-integration/published-app-integration.go @@ -26,7 +26,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq oauth2.CreatePublishedAppIntegration var createJson flags.JsonFlag @@ -62,6 +61,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -82,14 +82,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq oauth2.DeletePublishedAppIntegrationRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -110,12 +107,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + deleteReq.IntegrationId = args[0] err = a.PublishedAppIntegration.Delete(ctx, deleteReq) @@ -130,14 +122,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq oauth2.GetPublishedAppIntegrationRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -157,12 +146,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.IntegrationId = args[0] response, err := a.PublishedAppIntegration.Get(ctx, getReq) @@ -208,7 +192,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq oauth2.UpdatePublishedAppIntegration var updateJson flags.JsonFlag @@ -238,6 +221,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/service-principal-secrets/service-principal-secrets.go b/cmd/account/service-principal-secrets/service-principal-secrets.go index 8cae113e31..8c4c1fb95a 100755 --- a/cmd/account/service-principal-secrets/service-principal-secrets.go +++ b/cmd/account/service-principal-secrets/service-principal-secrets.go @@ -7,7 +7,6 @@ import ( "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" - "github.com/databricks/cli/libs/flags" "github.com/databricks/databricks-sdk-go/service/oauth2" "github.com/spf13/cobra" ) @@ -34,14 +33,11 @@ var Cmd = &cobra.Command{ } // start create command - var createReq oauth2.CreateServicePrincipalSecretRequest -var createJson flags.JsonFlag func init() { Cmd.AddCommand(createCmd) // TODO: short flags - createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -61,12 +57,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = createJson.Unmarshal(&createReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &createReq.ServicePrincipalId) if err != nil { return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0]) @@ -84,14 +75,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq oauth2.DeleteServicePrincipalSecretRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -111,12 +99,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &deleteReq.ServicePrincipalId) if err != nil { return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0]) @@ -135,14 +118,11 @@ var deleteCmd = &cobra.Command{ } // start list command - var listReq oauth2.ListServicePrincipalSecretsRequest -var listJson flags.JsonFlag func init() { Cmd.AddCommand(listCmd) // TODO: short flags - listCmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -164,12 +144,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = listJson.Unmarshal(&listReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &listReq.ServicePrincipalId) if err != nil { return fmt.Errorf("invalid SERVICE_PRINCIPAL_ID: %s", args[0]) diff --git a/cmd/account/service-principals/service-principals.go b/cmd/account/service-principals/service-principals.go index af9d3ec322..6ed4a69ab4 100755 --- a/cmd/account/service-principals/service-principals.go +++ b/cmd/account/service-principals/service-principals.go @@ -27,7 +27,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq iam.ServicePrincipal var createJson flags.JsonFlag @@ -66,6 +65,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -86,14 +86,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq iam.DeleteAccountServicePrincipalRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -109,12 +106,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Account Service Principals drop-down." @@ -146,14 +138,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq iam.GetAccountServicePrincipalRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -170,12 +159,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Account Service Principals drop-down." @@ -207,7 +191,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListAccountServicePrincipalsRequest var listJson flags.JsonFlag @@ -245,6 +228,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -265,7 +249,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -291,6 +274,7 @@ var patchCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = patchJson.Unmarshal(&patchReq) if err != nil { @@ -328,7 +312,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.ServicePrincipal var updateJson flags.JsonFlag @@ -362,6 +345,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/settings/settings.go b/cmd/account/settings/settings.go index 0de24b2eaa..8c507c3f61 100755 --- a/cmd/account/settings/settings.go +++ b/cmd/account/settings/settings.go @@ -23,7 +23,6 @@ var Cmd = &cobra.Command{ } // start delete-personal-compute-setting command - var deletePersonalComputeSettingReq settings.DeletePersonalComputeSettingRequest var deletePersonalComputeSettingJson flags.JsonFlag @@ -55,6 +54,7 @@ var deletePersonalComputeSettingCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = deletePersonalComputeSettingJson.Unmarshal(&deletePersonalComputeSettingReq) if err != nil { @@ -75,7 +75,6 @@ var deletePersonalComputeSettingCmd = &cobra.Command{ } // start read-personal-compute-setting command - var readPersonalComputeSettingReq settings.ReadPersonalComputeSettingRequest var readPersonalComputeSettingJson flags.JsonFlag @@ -107,6 +106,7 @@ var readPersonalComputeSettingCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = readPersonalComputeSettingJson.Unmarshal(&readPersonalComputeSettingReq) if err != nil { @@ -127,7 +127,6 @@ var readPersonalComputeSettingCmd = &cobra.Command{ } // start update-personal-compute-setting command - var updatePersonalComputeSettingReq settings.UpdatePersonalComputeSettingRequest var updatePersonalComputeSettingJson flags.JsonFlag @@ -160,6 +159,7 @@ var updatePersonalComputeSettingCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updatePersonalComputeSettingJson.Unmarshal(&updatePersonalComputeSettingReq) if err != nil { diff --git a/cmd/account/storage-credentials/storage-credentials.go b/cmd/account/storage-credentials/storage-credentials.go index ef753983ee..73e328dc56 100755 --- a/cmd/account/storage-credentials/storage-credentials.go +++ b/cmd/account/storage-credentials/storage-credentials.go @@ -20,7 +20,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.AccountsCreateStorageCredential var createJson flags.JsonFlag @@ -55,6 +54,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -75,14 +75,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteAccountStorageCredentialRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -103,12 +100,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + deleteReq.MetastoreId = args[0] deleteReq.Name = args[1] @@ -124,14 +116,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetAccountStorageCredentialRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -153,12 +142,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.MetastoreId = args[0] getReq.Name = args[1] @@ -174,14 +158,11 @@ var getCmd = &cobra.Command{ } // start list command - var listReq catalog.ListAccountStorageCredentialsRequest -var listJson flags.JsonFlag func init() { Cmd.AddCommand(listCmd) // TODO: short flags - listCmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -202,12 +183,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = listJson.Unmarshal(&listReq) - if err != nil { - return err - } - } + listReq.MetastoreId = args[0] response, err := a.StorageCredentials.List(ctx, listReq) @@ -222,7 +198,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.AccountsUpdateStorageCredential var updateJson flags.JsonFlag @@ -253,6 +228,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/storage/storage.go b/cmd/account/storage/storage.go index d83c8b400b..54821d4d48 100755 --- a/cmd/account/storage/storage.go +++ b/cmd/account/storage/storage.go @@ -27,7 +27,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq provisioning.CreateStorageConfigurationRequest var createJson flags.JsonFlag @@ -59,6 +58,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -80,14 +80,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq provisioning.DeleteStorageRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -104,12 +101,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No STORAGE_CONFIGURATION_ID argument specified. Loading names for Storage drop-down." @@ -141,14 +133,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq provisioning.GetStorageRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -164,12 +153,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No STORAGE_CONFIGURATION_ID argument specified. Loading names for Storage drop-down." diff --git a/cmd/account/users/users.go b/cmd/account/users/users.go index aff3ed1475..8a0b40b838 100755 --- a/cmd/account/users/users.go +++ b/cmd/account/users/users.go @@ -32,7 +32,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq iam.User var createJson flags.JsonFlag @@ -74,6 +73,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -94,14 +94,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq iam.DeleteAccountUserRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -118,12 +115,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Account Users drop-down." @@ -155,14 +147,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq iam.GetAccountUserRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -178,12 +167,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Account Users drop-down." @@ -215,7 +199,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListAccountUsersRequest var listJson flags.JsonFlag @@ -253,6 +236,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -273,7 +257,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -299,6 +282,7 @@ var patchCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = patchJson.Unmarshal(&patchReq) if err != nil { @@ -336,7 +320,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.User var updateJson flags.JsonFlag @@ -370,6 +353,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/vpc-endpoints/vpc-endpoints.go b/cmd/account/vpc-endpoints/vpc-endpoints.go index 276b030a62..80ed3831e4 100755 --- a/cmd/account/vpc-endpoints/vpc-endpoints.go +++ b/cmd/account/vpc-endpoints/vpc-endpoints.go @@ -22,7 +22,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq provisioning.CreateVpcEndpointRequest var createJson flags.JsonFlag @@ -68,6 +67,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -89,14 +89,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq provisioning.DeleteVpcEndpointRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -120,12 +117,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No VPC_ENDPOINT_ID argument specified. Loading names for Vpc Endpoints drop-down." @@ -157,14 +149,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq provisioning.GetVpcEndpointRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -184,12 +173,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No VPC_ENDPOINT_ID argument specified. Loading names for Vpc Endpoints drop-down." diff --git a/cmd/account/workspace-assignment/workspace-assignment.go b/cmd/account/workspace-assignment/workspace-assignment.go index 18de0c0c40..dab3571223 100755 --- a/cmd/account/workspace-assignment/workspace-assignment.go +++ b/cmd/account/workspace-assignment/workspace-assignment.go @@ -23,14 +23,11 @@ var Cmd = &cobra.Command{ } // start delete command - var deleteReq iam.DeleteWorkspaceAssignmentRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -51,12 +48,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &deleteReq.WorkspaceId) if err != nil { return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) @@ -78,14 +70,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq iam.GetWorkspaceAssignmentRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -105,12 +94,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &getReq.WorkspaceId) if err != nil { return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) @@ -128,14 +112,11 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListWorkspaceAssignmentRequest -var listJson flags.JsonFlag func init() { Cmd.AddCommand(listCmd) // TODO: short flags - listCmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -156,12 +137,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = listJson.Unmarshal(&listReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &listReq.WorkspaceId) if err != nil { return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) @@ -179,7 +155,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq iam.UpdateWorkspaceAssignments var updateJson flags.JsonFlag @@ -203,6 +178,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/account/workspaces/workspaces.go b/cmd/account/workspaces/workspaces.go index 750570f5e6..833d3cc003 100755 --- a/cmd/account/workspaces/workspaces.go +++ b/cmd/account/workspaces/workspaces.go @@ -30,9 +30,9 @@ var Cmd = &cobra.Command{ } // start create command - var createReq provisioning.CreateWorkspaceRequest var createJson flags.JsonFlag + var createSkipWait bool var createTimeout time.Duration @@ -86,6 +86,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -119,14 +120,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq provisioning.DeleteWorkspaceRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -149,12 +147,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Workspaces drop-down." @@ -189,14 +182,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq provisioning.GetWorkspaceRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -225,12 +215,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Workspaces drop-down." @@ -299,9 +284,8 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq provisioning.UpdateWorkspaceRequest -var updateJson flags.JsonFlag + var updateSkipWait bool var updateTimeout time.Duration @@ -311,7 +295,6 @@ func init() { updateCmd.Flags().BoolVar(&updateSkipWait, "no-wait", updateSkipWait, `do not wait to reach RUNNING state`) updateCmd.Flags().DurationVar(&updateTimeout, "timeout", 20*time.Minute, `maximum amount of time to reach RUNNING state`) // TODO: short flags - updateCmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`) updateCmd.Flags().StringVar(&updateReq.AwsRegion, "aws-region", updateReq.AwsRegion, `The AWS region of the workspace's data plane (for example, us-west-2).`) updateCmd.Flags().StringVar(&updateReq.CredentialsId, "credentials-id", updateReq.CredentialsId, `ID of the workspace's credential configuration object.`) @@ -444,12 +427,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() a := root.AccountClient(ctx) - if cmd.Flags().Changed("json") { - err = updateJson.Unmarshal(&updateReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Workspaces drop-down." diff --git a/cmd/workspace/access-control-proxy/access-control-proxy.go b/cmd/workspace/access-control-proxy/access-control-proxy.go index 8f1159c87c..06d3b08fd5 100755 --- a/cmd/workspace/access-control-proxy/access-control-proxy.go +++ b/cmd/workspace/access-control-proxy/access-control-proxy.go @@ -25,14 +25,11 @@ var Cmd = &cobra.Command{ } // start get-assignable-roles-for-resource command - var getAssignableRolesForResourceReq iam.GetAssignableRolesForResourceRequest -var getAssignableRolesForResourceJson flags.JsonFlag func init() { Cmd.AddCommand(getAssignableRolesForResourceCmd) // TODO: short flags - getAssignableRolesForResourceCmd.Flags().Var(&getAssignableRolesForResourceJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -54,12 +51,7 @@ var getAssignableRolesForResourceCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getAssignableRolesForResourceJson.Unmarshal(&getAssignableRolesForResourceReq) - if err != nil { - return err - } - } + getAssignableRolesForResourceReq.Resource = args[0] response, err := w.AccessControlProxy.GetAssignableRolesForResource(ctx, getAssignableRolesForResourceReq) @@ -74,14 +66,11 @@ var getAssignableRolesForResourceCmd = &cobra.Command{ } // start get-rule-set command - var getRuleSetReq iam.GetRuleSetRequest -var getRuleSetJson flags.JsonFlag func init() { Cmd.AddCommand(getRuleSetCmd) // TODO: short flags - getRuleSetCmd.Flags().Var(&getRuleSetJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -103,12 +92,7 @@ var getRuleSetCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getRuleSetJson.Unmarshal(&getRuleSetReq) - if err != nil { - return err - } - } + getRuleSetReq.Name = args[0] getRuleSetReq.Etag = args[1] @@ -124,7 +108,6 @@ var getRuleSetCmd = &cobra.Command{ } // start update-rule-set command - var updateRuleSetReq iam.UpdateRuleSetRequest var updateRuleSetJson flags.JsonFlag @@ -149,6 +132,7 @@ var updateRuleSetCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateRuleSetJson.Unmarshal(&updateRuleSetReq) if err != nil { diff --git a/cmd/workspace/alerts/alerts.go b/cmd/workspace/alerts/alerts.go index fb5db952c0..91417c63f1 100755 --- a/cmd/workspace/alerts/alerts.go +++ b/cmd/workspace/alerts/alerts.go @@ -26,7 +26,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq sql.CreateAlert var createJson flags.JsonFlag @@ -54,6 +53,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -75,14 +75,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq sql.DeleteAlertRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -100,12 +97,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ALERT_ID argument specified. Loading names for Alerts drop-down." @@ -137,14 +129,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq sql.GetAlertRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -160,12 +149,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ALERT_ID argument specified. Loading names for Alerts drop-down." @@ -227,7 +211,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq sql.EditAlert var updateJson flags.JsonFlag @@ -252,6 +235,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/catalogs/catalogs.go b/cmd/workspace/catalogs/catalogs.go index 9f39bed9df..78b8b14996 100755 --- a/cmd/workspace/catalogs/catalogs.go +++ b/cmd/workspace/catalogs/catalogs.go @@ -27,7 +27,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.CreateCatalog var createJson flags.JsonFlag @@ -64,6 +63,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -85,14 +85,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteCatalogRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) deleteCmd.Flags().BoolVar(&deleteReq.Force, "force", deleteReq.Force, `Force deletion even if the catalog is not empty.`) @@ -115,12 +112,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + deleteReq.Name = args[0] err = w.Catalogs.Delete(ctx, deleteReq) @@ -135,14 +127,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetCatalogRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -164,12 +153,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.Name = args[0] response, err := w.Catalogs.Get(ctx, getReq) @@ -218,7 +202,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateCatalog var updateJson flags.JsonFlag @@ -256,6 +239,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/cluster-policies/cluster-policies.go b/cmd/workspace/cluster-policies/cluster-policies.go index 6b22209c97..1f1d36c1db 100755 --- a/cmd/workspace/cluster-policies/cluster-policies.go +++ b/cmd/workspace/cluster-policies/cluster-policies.go @@ -45,7 +45,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq compute.CreatePolicy var createJson flags.JsonFlag @@ -81,6 +80,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -102,7 +102,6 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq compute.DeletePolicy var deleteJson flags.JsonFlag @@ -126,6 +125,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteJson.Unmarshal(&deleteReq) if err != nil { @@ -164,7 +164,6 @@ var deleteCmd = &cobra.Command{ } // start edit command - var editReq compute.EditPolicy var editJson flags.JsonFlag @@ -201,6 +200,7 @@ var editCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = editJson.Unmarshal(&editReq) if err != nil { @@ -223,14 +223,11 @@ var editCmd = &cobra.Command{ } // start get command - var getReq compute.GetClusterPolicyRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -246,12 +243,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No POLICY_ID argument specified. Loading names for Cluster Policies drop-down." @@ -283,7 +275,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq compute.ListClusterPoliciesRequest var listJson flags.JsonFlag @@ -316,6 +307,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { diff --git a/cmd/workspace/clusters/clusters.go b/cmd/workspace/clusters/clusters.go index 80106782fc..250fcecc34 100755 --- a/cmd/workspace/clusters/clusters.go +++ b/cmd/workspace/clusters/clusters.go @@ -49,7 +49,6 @@ var Cmd = &cobra.Command{ } // start change-owner command - var changeOwnerReq compute.ChangeClusterOwner var changeOwnerJson flags.JsonFlag @@ -80,6 +79,7 @@ var changeOwnerCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = changeOwnerJson.Unmarshal(&changeOwnerReq) if err != nil { @@ -102,9 +102,9 @@ var changeOwnerCmd = &cobra.Command{ } // start create command - var createReq compute.CreateCluster var createJson flags.JsonFlag + var createSkipWait bool var createTimeout time.Duration @@ -169,6 +169,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -202,9 +203,9 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq compute.DeleteCluster var deleteJson flags.JsonFlag + var deleteSkipWait bool var deleteTimeout time.Duration @@ -233,6 +234,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteJson.Unmarshal(&deleteReq) if err != nil { @@ -283,9 +285,9 @@ var deleteCmd = &cobra.Command{ } // start edit command - var editReq compute.EditCluster var editJson flags.JsonFlag + var editSkipWait bool var editTimeout time.Duration @@ -357,6 +359,7 @@ var editCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = editJson.Unmarshal(&editReq) if err != nil { @@ -391,7 +394,6 @@ var editCmd = &cobra.Command{ } // start events command - var eventsReq compute.GetEvents var eventsJson flags.JsonFlag @@ -423,6 +425,7 @@ var eventsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = eventsJson.Unmarshal(&eventsReq) if err != nil { @@ -461,9 +464,8 @@ var eventsCmd = &cobra.Command{ } // start get command - var getReq compute.GetClusterRequest -var getJson flags.JsonFlag + var getSkipWait bool var getTimeout time.Duration @@ -473,7 +475,6 @@ func init() { getCmd.Flags().BoolVar(&getSkipWait, "no-wait", getSkipWait, `do not wait to reach RUNNING state`) getCmd.Flags().DurationVar(&getTimeout, "timeout", 20*time.Minute, `maximum amount of time to reach RUNNING state`) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -490,12 +491,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No CLUSTER_ID argument specified. Loading names for Clusters drop-down." @@ -527,7 +523,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq compute.ListClustersRequest var listJson flags.JsonFlag @@ -567,6 +562,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -649,7 +645,6 @@ var listZonesCmd = &cobra.Command{ } // start permanent-delete command - var permanentDeleteReq compute.PermanentDeleteCluster var permanentDeleteJson flags.JsonFlag @@ -677,6 +672,7 @@ var permanentDeleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = permanentDeleteJson.Unmarshal(&permanentDeleteReq) if err != nil { @@ -715,7 +711,6 @@ var permanentDeleteCmd = &cobra.Command{ } // start pin command - var pinReq compute.PinCluster var pinJson flags.JsonFlag @@ -740,6 +735,7 @@ var pinCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = pinJson.Unmarshal(&pinReq) if err != nil { @@ -778,9 +774,9 @@ var pinCmd = &cobra.Command{ } // start resize command - var resizeReq compute.ResizeCluster var resizeJson flags.JsonFlag + var resizeSkipWait bool var resizeTimeout time.Duration @@ -810,6 +806,7 @@ var resizeCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = resizeJson.Unmarshal(&resizeReq) if err != nil { @@ -860,9 +857,9 @@ var resizeCmd = &cobra.Command{ } // start restart command - var restartReq compute.RestartCluster var restartJson flags.JsonFlag + var restartSkipWait bool var restartTimeout time.Duration @@ -891,6 +888,7 @@ var restartCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = restartJson.Unmarshal(&restartReq) if err != nil { @@ -972,9 +970,9 @@ var sparkVersionsCmd = &cobra.Command{ } // start start command - var startReq compute.StartCluster var startJson flags.JsonFlag + var startSkipWait bool var startTimeout time.Duration @@ -1007,6 +1005,7 @@ var startCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = startJson.Unmarshal(&startReq) if err != nil { @@ -1057,7 +1056,6 @@ var startCmd = &cobra.Command{ } // start unpin command - var unpinReq compute.UnpinCluster var unpinJson flags.JsonFlag @@ -1082,6 +1080,7 @@ var unpinCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = unpinJson.Unmarshal(&unpinReq) if err != nil { diff --git a/cmd/workspace/connections/connections.go b/cmd/workspace/connections/connections.go index 6fd05acea6..146fdba9d6 100755 --- a/cmd/workspace/connections/connections.go +++ b/cmd/workspace/connections/connections.go @@ -35,7 +35,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.CreateConnection var createJson flags.JsonFlag @@ -67,6 +66,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -88,14 +88,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteConnectionRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -111,12 +108,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME_ARG argument specified. Loading names for Connections drop-down." @@ -148,14 +140,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetConnectionRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -171,12 +160,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME_ARG argument specified. Loading names for Connections drop-down." @@ -238,7 +222,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateConnection var updateJson flags.JsonFlag @@ -261,6 +244,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/dashboards/dashboards.go b/cmd/workspace/dashboards/dashboards.go index e6b74d6449..b18ddff8cc 100755 --- a/cmd/workspace/dashboards/dashboards.go +++ b/cmd/workspace/dashboards/dashboards.go @@ -27,7 +27,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq sql.CreateDashboardRequest var createJson flags.JsonFlag @@ -60,6 +59,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -80,14 +80,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq sql.DeleteDashboardRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -104,12 +101,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No DASHBOARD_ID argument specified. Loading names for Dashboards drop-down." @@ -141,14 +133,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq sql.GetDashboardRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -165,12 +154,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No DASHBOARD_ID argument specified. Loading names for Dashboards drop-down." @@ -202,7 +186,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq sql.ListDashboardsRequest var listJson flags.JsonFlag @@ -237,6 +220,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -257,14 +241,11 @@ var listCmd = &cobra.Command{ } // start restore command - var restoreReq sql.RestoreDashboardRequest -var restoreJson flags.JsonFlag func init() { Cmd.AddCommand(restoreCmd) // TODO: short flags - restoreCmd.Flags().Var(&restoreJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -280,12 +261,7 @@ var restoreCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = restoreJson.Unmarshal(&restoreReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No DASHBOARD_ID argument specified. Loading names for Dashboards drop-down." diff --git a/cmd/workspace/experiments/experiments.go b/cmd/workspace/experiments/experiments.go index 8e5c4f84a6..738c0240d1 100755 --- a/cmd/workspace/experiments/experiments.go +++ b/cmd/workspace/experiments/experiments.go @@ -30,7 +30,6 @@ var Cmd = &cobra.Command{ } // start create-experiment command - var createExperimentReq ml.CreateExperiment var createExperimentJson flags.JsonFlag @@ -68,6 +67,7 @@ var createExperimentCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createExperimentJson.Unmarshal(&createExperimentReq) if err != nil { @@ -89,7 +89,6 @@ var createExperimentCmd = &cobra.Command{ } // start create-run command - var createRunReq ml.CreateRun var createRunJson flags.JsonFlag @@ -127,6 +126,7 @@ var createRunCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createRunJson.Unmarshal(&createRunReq) if err != nil { @@ -147,7 +147,6 @@ var createRunCmd = &cobra.Command{ } // start delete-experiment command - var deleteExperimentReq ml.DeleteExperiment var deleteExperimentJson flags.JsonFlag @@ -179,6 +178,7 @@ var deleteExperimentCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteExperimentJson.Unmarshal(&deleteExperimentReq) if err != nil { @@ -200,7 +200,6 @@ var deleteExperimentCmd = &cobra.Command{ } // start delete-run command - var deleteRunReq ml.DeleteRun var deleteRunJson flags.JsonFlag @@ -230,6 +229,7 @@ var deleteRunCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteRunJson.Unmarshal(&deleteRunReq) if err != nil { @@ -251,7 +251,6 @@ var deleteRunCmd = &cobra.Command{ } // start delete-tag command - var deleteTagReq ml.DeleteTag var deleteTagJson flags.JsonFlag @@ -282,6 +281,7 @@ var deleteTagCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteTagJson.Unmarshal(&deleteTagReq) if err != nil { @@ -304,14 +304,11 @@ var deleteTagCmd = &cobra.Command{ } // start get-by-name command - var getByNameReq ml.GetByNameRequest -var getByNameJson flags.JsonFlag func init() { Cmd.AddCommand(getByNameCmd) // TODO: short flags - getByNameCmd.Flags().Var(&getByNameJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -339,12 +336,7 @@ var getByNameCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getByNameJson.Unmarshal(&getByNameReq) - if err != nil { - return err - } - } + getByNameReq.ExperimentName = args[0] response, err := w.Experiments.GetByName(ctx, getByNameReq) @@ -359,14 +351,11 @@ var getByNameCmd = &cobra.Command{ } // start get-experiment command - var getExperimentReq ml.GetExperimentRequest -var getExperimentJson flags.JsonFlag func init() { Cmd.AddCommand(getExperimentCmd) // TODO: short flags - getExperimentCmd.Flags().Var(&getExperimentJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -386,12 +375,7 @@ var getExperimentCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getExperimentJson.Unmarshal(&getExperimentReq) - if err != nil { - return err - } - } + getExperimentReq.ExperimentId = args[0] response, err := w.Experiments.GetExperiment(ctx, getExperimentReq) @@ -406,14 +390,11 @@ var getExperimentCmd = &cobra.Command{ } // start get-history command - var getHistoryReq ml.GetHistoryRequest -var getHistoryJson flags.JsonFlag func init() { Cmd.AddCommand(getHistoryCmd) // TODO: short flags - getHistoryCmd.Flags().Var(&getHistoryJson, "json", `either inline JSON string or @path/to/file.json with request body`) getHistoryCmd.Flags().IntVar(&getHistoryReq.MaxResults, "max-results", getHistoryReq.MaxResults, `Maximum number of Metric records to return per paginated request.`) getHistoryCmd.Flags().StringVar(&getHistoryReq.PageToken, "page-token", getHistoryReq.PageToken, `Token indicating the page of metric histories to fetch.`) @@ -438,12 +419,7 @@ var getHistoryCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getHistoryJson.Unmarshal(&getHistoryReq) - if err != nil { - return err - } - } + getHistoryReq.MetricKey = args[0] response, err := w.Experiments.GetHistory(ctx, getHistoryReq) @@ -458,14 +434,11 @@ var getHistoryCmd = &cobra.Command{ } // start get-run command - var getRunReq ml.GetRunRequest -var getRunJson flags.JsonFlag func init() { Cmd.AddCommand(getRunCmd) // TODO: short flags - getRunCmd.Flags().Var(&getRunJson, "json", `either inline JSON string or @path/to/file.json with request body`) getRunCmd.Flags().StringVar(&getRunReq.RunUuid, "run-uuid", getRunReq.RunUuid, `[Deprecated, use run_id instead] ID of the run to fetch.`) @@ -492,12 +465,7 @@ var getRunCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getRunJson.Unmarshal(&getRunReq) - if err != nil { - return err - } - } + getRunReq.RunId = args[0] response, err := w.Experiments.GetRun(ctx, getRunReq) @@ -512,7 +480,6 @@ var getRunCmd = &cobra.Command{ } // start list-artifacts command - var listArtifactsReq ml.ListArtifactsRequest var listArtifactsJson flags.JsonFlag @@ -548,6 +515,7 @@ var listArtifactsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listArtifactsJson.Unmarshal(&listArtifactsReq) if err != nil { @@ -568,7 +536,6 @@ var listArtifactsCmd = &cobra.Command{ } // start list-experiments command - var listExperimentsReq ml.ListExperimentsRequest var listExperimentsJson flags.JsonFlag @@ -602,6 +569,7 @@ var listExperimentsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listExperimentsJson.Unmarshal(&listExperimentsReq) if err != nil { @@ -622,7 +590,6 @@ var listExperimentsCmd = &cobra.Command{ } // start log-batch command - var logBatchReq ml.LogBatch var logBatchJson flags.JsonFlag @@ -693,6 +660,7 @@ var logBatchCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = logBatchJson.Unmarshal(&logBatchReq) if err != nil { @@ -713,7 +681,6 @@ var logBatchCmd = &cobra.Command{ } // start log-inputs command - var logInputsReq ml.LogInputs var logInputsJson flags.JsonFlag @@ -747,6 +714,7 @@ var logInputsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = logInputsJson.Unmarshal(&logInputsReq) if err != nil { @@ -767,7 +735,6 @@ var logInputsCmd = &cobra.Command{ } // start log-metric command - var logMetricReq ml.LogMetric var logMetricJson flags.JsonFlag @@ -803,6 +770,7 @@ var logMetricCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = logMetricJson.Unmarshal(&logMetricReq) if err != nil { @@ -832,7 +800,6 @@ var logMetricCmd = &cobra.Command{ } // start log-model command - var logModelReq ml.LogModel var logModelJson flags.JsonFlag @@ -866,6 +833,7 @@ var logModelCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = logModelJson.Unmarshal(&logModelReq) if err != nil { @@ -886,7 +854,6 @@ var logModelCmd = &cobra.Command{ } // start log-param command - var logParamReq ml.LogParam var logParamJson flags.JsonFlag @@ -922,6 +889,7 @@ var logParamCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = logParamJson.Unmarshal(&logParamReq) if err != nil { @@ -944,7 +912,6 @@ var logParamCmd = &cobra.Command{ } // start restore-experiment command - var restoreExperimentReq ml.RestoreExperiment var restoreExperimentJson flags.JsonFlag @@ -979,6 +946,7 @@ var restoreExperimentCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = restoreExperimentJson.Unmarshal(&restoreExperimentReq) if err != nil { @@ -1000,7 +968,6 @@ var restoreExperimentCmd = &cobra.Command{ } // start restore-run command - var restoreRunReq ml.RestoreRun var restoreRunJson flags.JsonFlag @@ -1030,6 +997,7 @@ var restoreRunCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = restoreRunJson.Unmarshal(&restoreRunReq) if err != nil { @@ -1051,7 +1019,6 @@ var restoreRunCmd = &cobra.Command{ } // start search-experiments command - var searchExperimentsReq ml.SearchExperiments var searchExperimentsJson flags.JsonFlag @@ -1087,6 +1054,7 @@ var searchExperimentsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = searchExperimentsJson.Unmarshal(&searchExperimentsReq) if err != nil { @@ -1107,7 +1075,6 @@ var searchExperimentsCmd = &cobra.Command{ } // start search-runs command - var searchRunsReq ml.SearchRuns var searchRunsJson flags.JsonFlag @@ -1146,6 +1113,7 @@ var searchRunsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = searchRunsJson.Unmarshal(&searchRunsReq) if err != nil { @@ -1166,7 +1134,6 @@ var searchRunsCmd = &cobra.Command{ } // start set-experiment-tag command - var setExperimentTagReq ml.SetExperimentTag var setExperimentTagJson flags.JsonFlag @@ -1196,6 +1163,7 @@ var setExperimentTagCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = setExperimentTagJson.Unmarshal(&setExperimentTagReq) if err != nil { @@ -1219,7 +1187,6 @@ var setExperimentTagCmd = &cobra.Command{ } // start set-tag command - var setTagReq ml.SetTag var setTagJson flags.JsonFlag @@ -1253,6 +1220,7 @@ var setTagCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = setTagJson.Unmarshal(&setTagReq) if err != nil { @@ -1275,7 +1243,6 @@ var setTagCmd = &cobra.Command{ } // start update-experiment command - var updateExperimentReq ml.UpdateExperiment var updateExperimentJson flags.JsonFlag @@ -1307,6 +1274,7 @@ var updateExperimentCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateExperimentJson.Unmarshal(&updateExperimentReq) if err != nil { @@ -1328,7 +1296,6 @@ var updateExperimentCmd = &cobra.Command{ } // start update-run command - var updateRunReq ml.UpdateRun var updateRunJson flags.JsonFlag @@ -1363,6 +1330,7 @@ var updateRunCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateRunJson.Unmarshal(&updateRunReq) if err != nil { diff --git a/cmd/workspace/external-locations/external-locations.go b/cmd/workspace/external-locations/external-locations.go index 741ca44f8d..a739c931c8 100755 --- a/cmd/workspace/external-locations/external-locations.go +++ b/cmd/workspace/external-locations/external-locations.go @@ -32,7 +32,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.CreateExternalLocation var createJson flags.JsonFlag @@ -68,6 +67,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -91,14 +91,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteExternalLocationRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) deleteCmd.Flags().BoolVar(&deleteReq.Force, "force", deleteReq.Force, `Force deletion even if there are dependent external tables or mounts.`) @@ -121,12 +118,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + deleteReq.Name = args[0] err = w.ExternalLocations.Delete(ctx, deleteReq) @@ -141,14 +133,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetExternalLocationRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -170,12 +159,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.Name = args[0] response, err := w.ExternalLocations.Get(ctx, getReq) @@ -223,7 +207,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateExternalLocation var updateJson flags.JsonFlag @@ -263,6 +246,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/functions/functions.go b/cmd/workspace/functions/functions.go index f27a9ecf0c..9ce3f2faf0 100755 --- a/cmd/workspace/functions/functions.go +++ b/cmd/workspace/functions/functions.go @@ -27,7 +27,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.CreateFunction var createJson flags.JsonFlag @@ -60,6 +59,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -81,14 +81,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteFunctionRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) deleteCmd.Flags().BoolVar(&deleteReq.Force, "force", deleteReq.Force, `Force deletion even if the function is notempty.`) @@ -111,12 +108,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Functions drop-down." @@ -148,14 +140,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetFunctionRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -177,12 +166,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Functions drop-down." @@ -214,14 +198,11 @@ var getCmd = &cobra.Command{ } // start list command - var listReq catalog.ListFunctionsRequest -var listJson flags.JsonFlag func init() { Cmd.AddCommand(listCmd) // TODO: short flags - listCmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -247,12 +228,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listJson.Unmarshal(&listReq) - if err != nil { - return err - } - } + listReq.CatalogName = args[0] listReq.SchemaName = args[1] @@ -268,14 +244,11 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateFunction -var updateJson flags.JsonFlag func init() { Cmd.AddCommand(updateCmd) // TODO: short flags - updateCmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`) updateCmd.Flags().StringVar(&updateReq.Owner, "owner", updateReq.Owner, `Username of current owner of function.`) @@ -300,12 +273,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = updateJson.Unmarshal(&updateReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Functions drop-down." diff --git a/cmd/workspace/git-credentials/git-credentials.go b/cmd/workspace/git-credentials/git-credentials.go index 722b4574f9..f75ed83e03 100755 --- a/cmd/workspace/git-credentials/git-credentials.go +++ b/cmd/workspace/git-credentials/git-credentials.go @@ -27,7 +27,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq workspace.CreateCredentials var createJson flags.JsonFlag @@ -63,6 +62,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -84,14 +84,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq workspace.DeleteGitCredentialRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -107,12 +104,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No CREDENTIAL_ID argument specified. Loading names for Git Credentials drop-down." @@ -147,14 +139,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq workspace.GetGitCredentialRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -170,12 +159,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No CREDENTIAL_ID argument specified. Loading names for Git Credentials drop-down." @@ -241,14 +225,11 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq workspace.UpdateCredentials -var updateJson flags.JsonFlag func init() { Cmd.AddCommand(updateCmd) // TODO: short flags - updateCmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`) updateCmd.Flags().StringVar(&updateReq.GitProvider, "git-provider", updateReq.GitProvider, `Git provider.`) updateCmd.Flags().StringVar(&updateReq.GitUsername, "git-username", updateReq.GitUsername, `Git username.`) @@ -268,12 +249,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = updateJson.Unmarshal(&updateReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No CREDENTIAL_ID argument specified. Loading names for Git Credentials drop-down." diff --git a/cmd/workspace/global-init-scripts/global-init-scripts.go b/cmd/workspace/global-init-scripts/global-init-scripts.go index 9f61f72038..b63338f6c3 100755 --- a/cmd/workspace/global-init-scripts/global-init-scripts.go +++ b/cmd/workspace/global-init-scripts/global-init-scripts.go @@ -30,7 +30,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq compute.GlobalInitScriptCreateRequest var createJson flags.JsonFlag @@ -63,6 +62,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -85,14 +85,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq compute.DeleteGlobalInitScriptRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -108,12 +105,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No SCRIPT_ID argument specified. Loading names for Global Init Scripts drop-down." @@ -145,14 +137,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq compute.GetGlobalInitScriptRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -168,12 +157,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No SCRIPT_ID argument specified. Loading names for Global Init Scripts drop-down." @@ -238,14 +222,11 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq compute.GlobalInitScriptUpdateRequest -var updateJson flags.JsonFlag func init() { Cmd.AddCommand(updateCmd) // TODO: short flags - updateCmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`) updateCmd.Flags().BoolVar(&updateReq.Enabled, "enabled", updateReq.Enabled, `Specifies whether the script is enabled.`) updateCmd.Flags().IntVar(&updateReq.Position, "position", updateReq.Position, `The position of a script, where 0 represents the first script to run, 1 is the second script to run, in ascending order.`) @@ -269,12 +250,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = updateJson.Unmarshal(&updateReq) - if err != nil { - return err - } - } + updateReq.Name = args[0] updateReq.Script = args[1] updateReq.ScriptId = args[2] diff --git a/cmd/workspace/grants/grants.go b/cmd/workspace/grants/grants.go index 5ad793fe1b..1cc973872d 100755 --- a/cmd/workspace/grants/grants.go +++ b/cmd/workspace/grants/grants.go @@ -32,14 +32,11 @@ var Cmd = &cobra.Command{ } // start get command - var getReq catalog.GetGrantRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) getCmd.Flags().StringVar(&getReq.Principal, "principal", getReq.Principal, `If provided, only the permissions for the specified principal (user or group) are returned.`) @@ -61,12 +58,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &getReq.SecurableType) if err != nil { return fmt.Errorf("invalid SECURABLE_TYPE: %s", args[0]) @@ -85,14 +77,11 @@ var getCmd = &cobra.Command{ } // start get-effective command - var getEffectiveReq catalog.GetEffectiveRequest -var getEffectiveJson flags.JsonFlag func init() { Cmd.AddCommand(getEffectiveCmd) // TODO: short flags - getEffectiveCmd.Flags().Var(&getEffectiveJson, "json", `either inline JSON string or @path/to/file.json with request body`) getEffectiveCmd.Flags().StringVar(&getEffectiveReq.Principal, "principal", getEffectiveReq.Principal, `If provided, only the effective permissions for the specified principal (user or group) are returned.`) @@ -114,12 +103,7 @@ var getEffectiveCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getEffectiveJson.Unmarshal(&getEffectiveReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &getEffectiveReq.SecurableType) if err != nil { return fmt.Errorf("invalid SECURABLE_TYPE: %s", args[0]) @@ -138,7 +122,6 @@ var getEffectiveCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdatePermissions var updateJson flags.JsonFlag @@ -167,6 +150,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/groups/groups.go b/cmd/workspace/groups/groups.go index ca26010c26..bdadd1125d 100755 --- a/cmd/workspace/groups/groups.go +++ b/cmd/workspace/groups/groups.go @@ -28,7 +28,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq iam.Group var createJson flags.JsonFlag @@ -68,6 +67,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -88,14 +88,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq iam.DeleteGroupRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -111,12 +108,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Groups drop-down." @@ -148,14 +140,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq iam.GetGroupRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -171,12 +160,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Groups drop-down." @@ -208,7 +192,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListGroupsRequest var listJson flags.JsonFlag @@ -246,6 +229,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -266,7 +250,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -291,6 +274,7 @@ var patchCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = patchJson.Unmarshal(&patchReq) if err != nil { @@ -328,7 +312,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.Group var updateJson flags.JsonFlag @@ -360,6 +343,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/instance-pools/instance-pools.go b/cmd/workspace/instance-pools/instance-pools.go index e498ad3106..80c091e2af 100755 --- a/cmd/workspace/instance-pools/instance-pools.go +++ b/cmd/workspace/instance-pools/instance-pools.go @@ -39,7 +39,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq compute.CreateInstancePool var createJson flags.JsonFlag @@ -82,6 +81,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -104,7 +104,6 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq compute.DeleteInstancePool var deleteJson flags.JsonFlag @@ -128,6 +127,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteJson.Unmarshal(&deleteReq) if err != nil { @@ -166,7 +166,6 @@ var deleteCmd = &cobra.Command{ } // start edit command - var editReq compute.EditInstancePool var editJson flags.JsonFlag @@ -209,6 +208,7 @@ var editCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = editJson.Unmarshal(&editReq) if err != nil { @@ -232,14 +232,11 @@ var editCmd = &cobra.Command{ } // start get command - var getReq compute.GetInstancePoolRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -255,12 +252,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No INSTANCE_POOL_ID argument specified. Loading names for Instance Pools drop-down." diff --git a/cmd/workspace/instance-profiles/instance-profiles.go b/cmd/workspace/instance-profiles/instance-profiles.go index 8b7e957dda..ee2d928085 100755 --- a/cmd/workspace/instance-profiles/instance-profiles.go +++ b/cmd/workspace/instance-profiles/instance-profiles.go @@ -25,7 +25,6 @@ var Cmd = &cobra.Command{ } // start add command - var addReq compute.AddInstanceProfile var addJson flags.JsonFlag @@ -60,6 +59,7 @@ var addCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = addJson.Unmarshal(&addReq) if err != nil { @@ -81,7 +81,6 @@ var addCmd = &cobra.Command{ } // start edit command - var editReq compute.InstanceProfile var editJson flags.JsonFlag @@ -128,6 +127,7 @@ var editCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = editJson.Unmarshal(&editReq) if err != nil { @@ -181,7 +181,6 @@ var listCmd = &cobra.Command{ } // start remove command - var removeReq compute.RemoveInstanceProfile var removeJson flags.JsonFlag @@ -214,6 +213,7 @@ var removeCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = removeJson.Unmarshal(&removeReq) if err != nil { diff --git a/cmd/workspace/ip-access-lists/ip-access-lists.go b/cmd/workspace/ip-access-lists/ip-access-lists.go index 3278e2425e..94bd110d06 100755 --- a/cmd/workspace/ip-access-lists/ip-access-lists.go +++ b/cmd/workspace/ip-access-lists/ip-access-lists.go @@ -42,7 +42,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq settings.CreateIpAccessList var createJson flags.JsonFlag @@ -80,6 +79,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -101,14 +101,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq settings.DeleteIpAccessListRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -124,12 +121,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Ip Access Lists drop-down." @@ -161,14 +153,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq settings.GetIpAccessListRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -184,12 +173,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No IP_ACCESS_LIST_ID argument specified. Loading names for Ip Access Lists drop-down." @@ -251,7 +235,6 @@ var listCmd = &cobra.Command{ } // start replace command - var replaceReq settings.ReplaceIpAccessList var replaceJson flags.JsonFlag @@ -287,6 +270,7 @@ var replaceCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = replaceJson.Unmarshal(&replaceReq) if err != nil { @@ -308,7 +292,6 @@ var replaceCmd = &cobra.Command{ } // start update command - var updateReq settings.UpdateIpAccessList var updateJson flags.JsonFlag @@ -348,6 +331,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/jobs/jobs.go b/cmd/workspace/jobs/jobs.go index 11733b5a50..1dfb065b1d 100755 --- a/cmd/workspace/jobs/jobs.go +++ b/cmd/workspace/jobs/jobs.go @@ -40,7 +40,6 @@ var Cmd = &cobra.Command{ } // start cancel-all-runs command - var cancelAllRunsReq jobs.CancelAllRuns var cancelAllRunsJson flags.JsonFlag @@ -64,6 +63,7 @@ var cancelAllRunsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = cancelAllRunsJson.Unmarshal(&cancelAllRunsReq) if err != nil { @@ -105,9 +105,9 @@ var cancelAllRunsCmd = &cobra.Command{ } // start cancel-run command - var cancelRunReq jobs.CancelRun var cancelRunJson flags.JsonFlag + var cancelRunSkipWait bool var cancelRunTimeout time.Duration @@ -134,6 +134,7 @@ var cancelRunCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = cancelRunJson.Unmarshal(&cancelRunReq) if err != nil { @@ -194,7 +195,6 @@ var cancelRunCmd = &cobra.Command{ } // start create command - var createReq jobs.CreateJob var createJson flags.JsonFlag @@ -243,6 +243,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -263,7 +264,6 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq jobs.DeleteJob var deleteJson flags.JsonFlag @@ -286,6 +286,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteJson.Unmarshal(&deleteReq) if err != nil { @@ -327,7 +328,6 @@ var deleteCmd = &cobra.Command{ } // start delete-run command - var deleteRunReq jobs.DeleteRun var deleteRunJson flags.JsonFlag @@ -350,6 +350,7 @@ var deleteRunCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteRunJson.Unmarshal(&deleteRunReq) if err != nil { @@ -391,14 +392,11 @@ var deleteRunCmd = &cobra.Command{ } // start export-run command - var exportRunReq jobs.ExportRunRequest -var exportRunJson flags.JsonFlag func init() { Cmd.AddCommand(exportRunCmd) // TODO: short flags - exportRunCmd.Flags().Var(&exportRunJson, "json", `either inline JSON string or @path/to/file.json with request body`) exportRunCmd.Flags().Var(&exportRunReq.ViewsToExport, "views-to-export", `Which views to export (CODE, DASHBOARDS, or ALL).`) @@ -416,12 +414,7 @@ var exportRunCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = exportRunJson.Unmarshal(&exportRunReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No RUN_ID argument specified. Loading names for Jobs drop-down." @@ -456,14 +449,11 @@ var exportRunCmd = &cobra.Command{ } // start get command - var getReq jobs.GetJobRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -479,12 +469,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No JOB_ID argument specified. Loading names for Jobs drop-down." @@ -519,9 +504,8 @@ var getCmd = &cobra.Command{ } // start get-run command - var getRunReq jobs.GetRunRequest -var getRunJson flags.JsonFlag + var getRunSkipWait bool var getRunTimeout time.Duration @@ -531,7 +515,6 @@ func init() { getRunCmd.Flags().BoolVar(&getRunSkipWait, "no-wait", getRunSkipWait, `do not wait to reach TERMINATED or SKIPPED state`) getRunCmd.Flags().DurationVar(&getRunTimeout, "timeout", 20*time.Minute, `maximum amount of time to reach TERMINATED or SKIPPED state`) // TODO: short flags - getRunCmd.Flags().Var(&getRunJson, "json", `either inline JSON string or @path/to/file.json with request body`) getRunCmd.Flags().BoolVar(&getRunReq.IncludeHistory, "include-history", getRunReq.IncludeHistory, `Whether to include the repair history in the response.`) @@ -549,12 +532,7 @@ var getRunCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getRunJson.Unmarshal(&getRunReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No RUN_ID argument specified. Loading names for Jobs drop-down." @@ -589,14 +567,11 @@ var getRunCmd = &cobra.Command{ } // start get-run-output command - var getRunOutputReq jobs.GetRunOutputRequest -var getRunOutputJson flags.JsonFlag func init() { Cmd.AddCommand(getRunOutputCmd) // TODO: short flags - getRunOutputCmd.Flags().Var(&getRunOutputJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -621,12 +596,7 @@ var getRunOutputCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getRunOutputJson.Unmarshal(&getRunOutputReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No RUN_ID argument specified. Loading names for Jobs drop-down." @@ -661,7 +631,6 @@ var getRunOutputCmd = &cobra.Command{ } // start list command - var listReq jobs.ListJobsRequest var listJson flags.JsonFlag @@ -697,6 +666,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -717,7 +687,6 @@ var listCmd = &cobra.Command{ } // start list-runs command - var listRunsReq jobs.ListRunsRequest var listRunsJson flags.JsonFlag @@ -758,6 +727,7 @@ var listRunsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listRunsJson.Unmarshal(&listRunsReq) if err != nil { @@ -778,9 +748,9 @@ var listRunsCmd = &cobra.Command{ } // start repair-run command - var repairRunReq jobs.RepairRun var repairRunJson flags.JsonFlag + var repairRunSkipWait bool var repairRunTimeout time.Duration @@ -821,6 +791,7 @@ var repairRunCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = repairRunJson.Unmarshal(&repairRunReq) if err != nil { @@ -881,7 +852,6 @@ var repairRunCmd = &cobra.Command{ } // start reset command - var resetReq jobs.ResetJob var resetJson flags.JsonFlag @@ -905,6 +875,7 @@ var resetCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = resetJson.Unmarshal(&resetReq) if err != nil { @@ -926,9 +897,9 @@ var resetCmd = &cobra.Command{ } // start run-now command - var runNowReq jobs.RunNow var runNowJson flags.JsonFlag + var runNowSkipWait bool var runNowTimeout time.Duration @@ -965,6 +936,7 @@ var runNowCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = runNowJson.Unmarshal(&runNowReq) if err != nil { @@ -1025,9 +997,9 @@ var runNowCmd = &cobra.Command{ } // start submit command - var submitReq jobs.SubmitRun var submitJson flags.JsonFlag + var submitSkipWait bool var submitTimeout time.Duration @@ -1072,6 +1044,7 @@ var submitCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = submitJson.Unmarshal(&submitReq) if err != nil { @@ -1111,7 +1084,6 @@ var submitCmd = &cobra.Command{ } // start update command - var updateReq jobs.UpdateJob var updateJson flags.JsonFlag @@ -1138,6 +1110,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/libraries/libraries.go b/cmd/workspace/libraries/libraries.go index 578ff0543e..70b5584ab0 100755 --- a/cmd/workspace/libraries/libraries.go +++ b/cmd/workspace/libraries/libraries.go @@ -73,14 +73,11 @@ var allClusterStatusesCmd = &cobra.Command{ } // start cluster-status command - var clusterStatusReq compute.ClusterStatusRequest -var clusterStatusJson flags.JsonFlag func init() { Cmd.AddCommand(clusterStatusCmd) // TODO: short flags - clusterStatusCmd.Flags().Var(&clusterStatusJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -114,12 +111,7 @@ var clusterStatusCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = clusterStatusJson.Unmarshal(&clusterStatusReq) - if err != nil { - return err - } - } + clusterStatusReq.ClusterId = args[0] response, err := w.Libraries.ClusterStatus(ctx, clusterStatusReq) @@ -134,7 +126,6 @@ var clusterStatusCmd = &cobra.Command{ } // start install command - var installReq compute.InstallLibraries var installJson flags.JsonFlag @@ -162,6 +153,7 @@ var installCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = installJson.Unmarshal(&installReq) if err != nil { @@ -183,7 +175,6 @@ var installCmd = &cobra.Command{ } // start uninstall command - var uninstallReq compute.UninstallLibraries var uninstallJson flags.JsonFlag @@ -208,6 +199,7 @@ var uninstallCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = uninstallJson.Unmarshal(&uninstallReq) if err != nil { diff --git a/cmd/workspace/metastores/metastores.go b/cmd/workspace/metastores/metastores.go index 8464cf588b..e16f74ff11 100755 --- a/cmd/workspace/metastores/metastores.go +++ b/cmd/workspace/metastores/metastores.go @@ -34,14 +34,11 @@ var Cmd = &cobra.Command{ } // start assign command - var assignReq catalog.CreateMetastoreAssignment -var assignJson flags.JsonFlag func init() { Cmd.AddCommand(assignCmd) // TODO: short flags - assignCmd.Flags().Var(&assignJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -63,12 +60,7 @@ var assignCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = assignJson.Unmarshal(&assignReq) - if err != nil { - return err - } - } + assignReq.MetastoreId = args[0] assignReq.DefaultCatalogName = args[1] _, err = fmt.Sscan(args[2], &assignReq.WorkspaceId) @@ -88,7 +80,6 @@ var assignCmd = &cobra.Command{ } // start create command - var createReq catalog.CreateMetastore var createJson flags.JsonFlag @@ -120,6 +111,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -172,14 +164,11 @@ var currentCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteMetastoreRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) deleteCmd.Flags().BoolVar(&deleteReq.Force, "force", deleteReq.Force, `Force deletion even if the metastore is not empty.`) @@ -197,12 +186,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down." @@ -234,14 +218,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetMetastoreRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -258,12 +239,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down." @@ -327,7 +303,6 @@ var listCmd = &cobra.Command{ } // start maintenance command - var maintenanceReq catalog.UpdateAutoMaintenance var maintenanceJson flags.JsonFlag @@ -360,6 +335,7 @@ var maintenanceCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = maintenanceJson.Unmarshal(&maintenanceReq) if err != nil { @@ -416,14 +392,11 @@ var summaryCmd = &cobra.Command{ } // start unassign command - var unassignReq catalog.UnassignRequest -var unassignJson flags.JsonFlag func init() { Cmd.AddCommand(unassignCmd) // TODO: short flags - unassignCmd.Flags().Var(&unassignJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -443,12 +416,7 @@ var unassignCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = unassignJson.Unmarshal(&unassignReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &unassignReq.WorkspaceId) if err != nil { return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) @@ -467,14 +435,11 @@ var unassignCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateMetastore -var updateJson flags.JsonFlag func init() { Cmd.AddCommand(updateCmd) // TODO: short flags - updateCmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`) updateCmd.Flags().StringVar(&updateReq.DeltaSharingOrganizationName, "delta-sharing-organization-name", updateReq.DeltaSharingOrganizationName, `The organization name of a Delta Sharing entity, to be used in Databricks-to-Databricks Delta Sharing as the official name.`) updateCmd.Flags().Int64Var(&updateReq.DeltaSharingRecipientTokenLifetimeInSeconds, "delta-sharing-recipient-token-lifetime-in-seconds", updateReq.DeltaSharingRecipientTokenLifetimeInSeconds, `The lifetime of delta sharing recipient token in seconds.`) @@ -499,12 +464,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = updateJson.Unmarshal(&updateReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Metastores drop-down." @@ -536,14 +496,11 @@ var updateCmd = &cobra.Command{ } // start update-assignment command - var updateAssignmentReq catalog.UpdateMetastoreAssignment -var updateAssignmentJson flags.JsonFlag func init() { Cmd.AddCommand(updateAssignmentCmd) // TODO: short flags - updateAssignmentCmd.Flags().Var(&updateAssignmentJson, "json", `either inline JSON string or @path/to/file.json with request body`) updateAssignmentCmd.Flags().StringVar(&updateAssignmentReq.DefaultCatalogName, "default-catalog-name", updateAssignmentReq.DefaultCatalogName, `The name of the default catalog for the metastore.`) updateAssignmentCmd.Flags().StringVar(&updateAssignmentReq.MetastoreId, "metastore-id", updateAssignmentReq.MetastoreId, `The unique ID of the metastore.`) @@ -565,12 +522,7 @@ var updateAssignmentCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = updateAssignmentJson.Unmarshal(&updateAssignmentReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No WORKSPACE_ID argument specified. Loading names for Metastores drop-down." diff --git a/cmd/workspace/model-registry/model-registry.go b/cmd/workspace/model-registry/model-registry.go index 54195d7e02..ce7f4806c9 100755 --- a/cmd/workspace/model-registry/model-registry.go +++ b/cmd/workspace/model-registry/model-registry.go @@ -23,7 +23,6 @@ var Cmd = &cobra.Command{ } // start approve-transition-request command - var approveTransitionRequestReq ml.ApproveTransitionRequest var approveTransitionRequestJson flags.JsonFlag @@ -55,6 +54,7 @@ var approveTransitionRequestCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = approveTransitionRequestJson.Unmarshal(&approveTransitionRequestReq) if err != nil { @@ -85,7 +85,6 @@ var approveTransitionRequestCmd = &cobra.Command{ } // start create-comment command - var createCommentReq ml.CreateComment var createCommentJson flags.JsonFlag @@ -117,6 +116,7 @@ var createCommentCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createCommentJson.Unmarshal(&createCommentReq) if err != nil { @@ -140,7 +140,6 @@ var createCommentCmd = &cobra.Command{ } // start create-model command - var createModelReq ml.CreateModelRequest var createModelJson flags.JsonFlag @@ -176,6 +175,7 @@ var createModelCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createModelJson.Unmarshal(&createModelReq) if err != nil { @@ -197,7 +197,6 @@ var createModelCmd = &cobra.Command{ } // start create-model-version command - var createModelVersionReq ml.CreateModelVersionRequest var createModelVersionJson flags.JsonFlag @@ -232,6 +231,7 @@ var createModelVersionCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createModelVersionJson.Unmarshal(&createModelVersionReq) if err != nil { @@ -254,7 +254,6 @@ var createModelVersionCmd = &cobra.Command{ } // start create-transition-request command - var createTransitionRequestReq ml.CreateTransitionRequest var createTransitionRequestJson flags.JsonFlag @@ -286,6 +285,7 @@ var createTransitionRequestCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createTransitionRequestJson.Unmarshal(&createTransitionRequestReq) if err != nil { @@ -312,7 +312,6 @@ var createTransitionRequestCmd = &cobra.Command{ } // start create-webhook command - var createWebhookReq ml.CreateRegistryWebhook var createWebhookJson flags.JsonFlag @@ -343,6 +342,7 @@ var createWebhookCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createWebhookJson.Unmarshal(&createWebhookReq) if err != nil { @@ -364,14 +364,11 @@ var createWebhookCmd = &cobra.Command{ } // start delete-comment command - var deleteCommentReq ml.DeleteCommentRequest -var deleteCommentJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCommentCmd) // TODO: short flags - deleteCommentCmd.Flags().Var(&deleteCommentJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -391,12 +388,7 @@ var deleteCommentCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteCommentJson.Unmarshal(&deleteCommentReq) - if err != nil { - return err - } - } + deleteCommentReq.Id = args[0] err = w.ModelRegistry.DeleteComment(ctx, deleteCommentReq) @@ -411,14 +403,11 @@ var deleteCommentCmd = &cobra.Command{ } // start delete-model command - var deleteModelReq ml.DeleteModelRequest -var deleteModelJson flags.JsonFlag func init() { Cmd.AddCommand(deleteModelCmd) // TODO: short flags - deleteModelCmd.Flags().Var(&deleteModelJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -438,12 +427,7 @@ var deleteModelCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteModelJson.Unmarshal(&deleteModelReq) - if err != nil { - return err - } - } + deleteModelReq.Name = args[0] err = w.ModelRegistry.DeleteModel(ctx, deleteModelReq) @@ -458,14 +442,11 @@ var deleteModelCmd = &cobra.Command{ } // start delete-model-tag command - var deleteModelTagReq ml.DeleteModelTagRequest -var deleteModelTagJson flags.JsonFlag func init() { Cmd.AddCommand(deleteModelTagCmd) // TODO: short flags - deleteModelTagCmd.Flags().Var(&deleteModelTagJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -485,12 +466,7 @@ var deleteModelTagCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteModelTagJson.Unmarshal(&deleteModelTagReq) - if err != nil { - return err - } - } + deleteModelTagReq.Name = args[0] deleteModelTagReq.Key = args[1] @@ -506,14 +482,11 @@ var deleteModelTagCmd = &cobra.Command{ } // start delete-model-version command - var deleteModelVersionReq ml.DeleteModelVersionRequest -var deleteModelVersionJson flags.JsonFlag func init() { Cmd.AddCommand(deleteModelVersionCmd) // TODO: short flags - deleteModelVersionCmd.Flags().Var(&deleteModelVersionJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -533,12 +506,7 @@ var deleteModelVersionCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteModelVersionJson.Unmarshal(&deleteModelVersionReq) - if err != nil { - return err - } - } + deleteModelVersionReq.Name = args[0] deleteModelVersionReq.Version = args[1] @@ -554,14 +522,11 @@ var deleteModelVersionCmd = &cobra.Command{ } // start delete-model-version-tag command - var deleteModelVersionTagReq ml.DeleteModelVersionTagRequest -var deleteModelVersionTagJson flags.JsonFlag func init() { Cmd.AddCommand(deleteModelVersionTagCmd) // TODO: short flags - deleteModelVersionTagCmd.Flags().Var(&deleteModelVersionTagJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -581,12 +546,7 @@ var deleteModelVersionTagCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteModelVersionTagJson.Unmarshal(&deleteModelVersionTagReq) - if err != nil { - return err - } - } + deleteModelVersionTagReq.Name = args[0] deleteModelVersionTagReq.Version = args[1] deleteModelVersionTagReq.Key = args[2] @@ -603,14 +563,11 @@ var deleteModelVersionTagCmd = &cobra.Command{ } // start delete-transition-request command - var deleteTransitionRequestReq ml.DeleteTransitionRequestRequest -var deleteTransitionRequestJson flags.JsonFlag func init() { Cmd.AddCommand(deleteTransitionRequestCmd) // TODO: short flags - deleteTransitionRequestCmd.Flags().Var(&deleteTransitionRequestJson, "json", `either inline JSON string or @path/to/file.json with request body`) deleteTransitionRequestCmd.Flags().StringVar(&deleteTransitionRequestReq.Comment, "comment", deleteTransitionRequestReq.Comment, `User-provided comment on the action.`) @@ -632,12 +589,7 @@ var deleteTransitionRequestCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteTransitionRequestJson.Unmarshal(&deleteTransitionRequestReq) - if err != nil { - return err - } - } + deleteTransitionRequestReq.Name = args[0] deleteTransitionRequestReq.Version = args[1] _, err = fmt.Sscan(args[2], &deleteTransitionRequestReq.Stage) @@ -658,7 +610,6 @@ var deleteTransitionRequestCmd = &cobra.Command{ } // start delete-webhook command - var deleteWebhookReq ml.DeleteWebhookRequest var deleteWebhookJson flags.JsonFlag @@ -692,6 +643,7 @@ var deleteWebhookCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteWebhookJson.Unmarshal(&deleteWebhookReq) if err != nil { @@ -712,7 +664,6 @@ var deleteWebhookCmd = &cobra.Command{ } // start get-latest-versions command - var getLatestVersionsReq ml.GetLatestVersionsRequest var getLatestVersionsJson flags.JsonFlag @@ -744,6 +695,7 @@ var getLatestVersionsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = getLatestVersionsJson.Unmarshal(&getLatestVersionsReq) if err != nil { @@ -765,14 +717,11 @@ var getLatestVersionsCmd = &cobra.Command{ } // start get-model command - var getModelReq ml.GetModelRequest -var getModelJson flags.JsonFlag func init() { Cmd.AddCommand(getModelCmd) // TODO: short flags - getModelCmd.Flags().Var(&getModelJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -796,12 +745,7 @@ var getModelCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getModelJson.Unmarshal(&getModelReq) - if err != nil { - return err - } - } + getModelReq.Name = args[0] response, err := w.ModelRegistry.GetModel(ctx, getModelReq) @@ -816,14 +760,11 @@ var getModelCmd = &cobra.Command{ } // start get-model-version command - var getModelVersionReq ml.GetModelVersionRequest -var getModelVersionJson flags.JsonFlag func init() { Cmd.AddCommand(getModelVersionCmd) // TODO: short flags - getModelVersionCmd.Flags().Var(&getModelVersionJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -843,12 +784,7 @@ var getModelVersionCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getModelVersionJson.Unmarshal(&getModelVersionReq) - if err != nil { - return err - } - } + getModelVersionReq.Name = args[0] getModelVersionReq.Version = args[1] @@ -864,14 +800,11 @@ var getModelVersionCmd = &cobra.Command{ } // start get-model-version-download-uri command - var getModelVersionDownloadUriReq ml.GetModelVersionDownloadUriRequest -var getModelVersionDownloadUriJson flags.JsonFlag func init() { Cmd.AddCommand(getModelVersionDownloadUriCmd) // TODO: short flags - getModelVersionDownloadUriCmd.Flags().Var(&getModelVersionDownloadUriJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -891,12 +824,7 @@ var getModelVersionDownloadUriCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getModelVersionDownloadUriJson.Unmarshal(&getModelVersionDownloadUriReq) - if err != nil { - return err - } - } + getModelVersionDownloadUriReq.Name = args[0] getModelVersionDownloadUriReq.Version = args[1] @@ -912,7 +840,6 @@ var getModelVersionDownloadUriCmd = &cobra.Command{ } // start list-models command - var listModelsReq ml.ListModelsRequest var listModelsJson flags.JsonFlag @@ -946,6 +873,7 @@ var listModelsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listModelsJson.Unmarshal(&listModelsReq) if err != nil { @@ -966,14 +894,11 @@ var listModelsCmd = &cobra.Command{ } // start list-transition-requests command - var listTransitionRequestsReq ml.ListTransitionRequestsRequest -var listTransitionRequestsJson flags.JsonFlag func init() { Cmd.AddCommand(listTransitionRequestsCmd) // TODO: short flags - listTransitionRequestsCmd.Flags().Var(&listTransitionRequestsJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -993,12 +918,7 @@ var listTransitionRequestsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listTransitionRequestsJson.Unmarshal(&listTransitionRequestsReq) - if err != nil { - return err - } - } + listTransitionRequestsReq.Name = args[0] listTransitionRequestsReq.Version = args[1] @@ -1014,7 +934,6 @@ var listTransitionRequestsCmd = &cobra.Command{ } // start list-webhooks command - var listWebhooksReq ml.ListWebhooksRequest var listWebhooksJson flags.JsonFlag @@ -1050,6 +969,7 @@ var listWebhooksCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listWebhooksJson.Unmarshal(&listWebhooksReq) if err != nil { @@ -1070,7 +990,6 @@ var listWebhooksCmd = &cobra.Command{ } // start reject-transition-request command - var rejectTransitionRequestReq ml.RejectTransitionRequest var rejectTransitionRequestJson flags.JsonFlag @@ -1102,6 +1021,7 @@ var rejectTransitionRequestCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = rejectTransitionRequestJson.Unmarshal(&rejectTransitionRequestReq) if err != nil { @@ -1128,7 +1048,6 @@ var rejectTransitionRequestCmd = &cobra.Command{ } // start rename-model command - var renameModelReq ml.RenameModelRequest var renameModelJson flags.JsonFlag @@ -1160,6 +1079,7 @@ var renameModelCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = renameModelJson.Unmarshal(&renameModelReq) if err != nil { @@ -1181,7 +1101,6 @@ var renameModelCmd = &cobra.Command{ } // start search-model-versions command - var searchModelVersionsReq ml.SearchModelVersionsRequest var searchModelVersionsJson flags.JsonFlag @@ -1216,6 +1135,7 @@ var searchModelVersionsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = searchModelVersionsJson.Unmarshal(&searchModelVersionsReq) if err != nil { @@ -1236,7 +1156,6 @@ var searchModelVersionsCmd = &cobra.Command{ } // start search-models command - var searchModelsReq ml.SearchModelsRequest var searchModelsJson flags.JsonFlag @@ -1271,6 +1190,7 @@ var searchModelsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = searchModelsJson.Unmarshal(&searchModelsReq) if err != nil { @@ -1291,7 +1211,6 @@ var searchModelsCmd = &cobra.Command{ } // start set-model-tag command - var setModelTagReq ml.SetModelTagRequest var setModelTagJson flags.JsonFlag @@ -1321,6 +1240,7 @@ var setModelTagCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = setModelTagJson.Unmarshal(&setModelTagReq) if err != nil { @@ -1344,7 +1264,6 @@ var setModelTagCmd = &cobra.Command{ } // start set-model-version-tag command - var setModelVersionTagReq ml.SetModelVersionTagRequest var setModelVersionTagJson flags.JsonFlag @@ -1374,6 +1293,7 @@ var setModelVersionTagCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = setModelVersionTagJson.Unmarshal(&setModelVersionTagReq) if err != nil { @@ -1398,7 +1318,6 @@ var setModelVersionTagCmd = &cobra.Command{ } // start test-registry-webhook command - var testRegistryWebhookReq ml.TestRegistryWebhookRequest var testRegistryWebhookJson flags.JsonFlag @@ -1432,6 +1351,7 @@ var testRegistryWebhookCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = testRegistryWebhookJson.Unmarshal(&testRegistryWebhookReq) if err != nil { @@ -1453,7 +1373,6 @@ var testRegistryWebhookCmd = &cobra.Command{ } // start transition-stage command - var transitionStageReq ml.TransitionModelVersionStageDatabricks var transitionStageJson flags.JsonFlag @@ -1489,6 +1408,7 @@ var transitionStageCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = transitionStageJson.Unmarshal(&transitionStageReq) if err != nil { @@ -1519,7 +1439,6 @@ var transitionStageCmd = &cobra.Command{ } // start update-comment command - var updateCommentReq ml.UpdateComment var updateCommentJson flags.JsonFlag @@ -1549,6 +1468,7 @@ var updateCommentCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateCommentJson.Unmarshal(&updateCommentReq) if err != nil { @@ -1571,7 +1491,6 @@ var updateCommentCmd = &cobra.Command{ } // start update-model command - var updateModelReq ml.UpdateModelRequest var updateModelJson flags.JsonFlag @@ -1603,6 +1522,7 @@ var updateModelCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateModelJson.Unmarshal(&updateModelReq) if err != nil { @@ -1624,7 +1544,6 @@ var updateModelCmd = &cobra.Command{ } // start update-model-version command - var updateModelVersionReq ml.UpdateModelVersionRequest var updateModelVersionJson flags.JsonFlag @@ -1656,6 +1575,7 @@ var updateModelVersionCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateModelVersionJson.Unmarshal(&updateModelVersionReq) if err != nil { @@ -1678,7 +1598,6 @@ var updateModelVersionCmd = &cobra.Command{ } // start update-webhook command - var updateWebhookReq ml.UpdateRegistryWebhook var updateWebhookJson flags.JsonFlag @@ -1716,6 +1635,7 @@ var updateWebhookCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateWebhookJson.Unmarshal(&updateWebhookReq) if err != nil { diff --git a/cmd/workspace/permissions/permissions.go b/cmd/workspace/permissions/permissions.go index 174a2c615d..c925012071 100755 --- a/cmd/workspace/permissions/permissions.go +++ b/cmd/workspace/permissions/permissions.go @@ -21,14 +21,11 @@ var Cmd = &cobra.Command{ } // start get command - var getReq iam.GetPermissionRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -49,12 +46,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.RequestObjectType = args[0] getReq.RequestObjectId = args[1] @@ -70,14 +62,11 @@ var getCmd = &cobra.Command{ } // start get-permission-levels command - var getPermissionLevelsReq iam.GetPermissionLevelsRequest -var getPermissionLevelsJson flags.JsonFlag func init() { Cmd.AddCommand(getPermissionLevelsCmd) // TODO: short flags - getPermissionLevelsCmd.Flags().Var(&getPermissionLevelsJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -97,12 +86,7 @@ var getPermissionLevelsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getPermissionLevelsJson.Unmarshal(&getPermissionLevelsReq) - if err != nil { - return err - } - } + getPermissionLevelsReq.RequestObjectType = args[0] getPermissionLevelsReq.RequestObjectId = args[1] @@ -118,7 +102,6 @@ var getPermissionLevelsCmd = &cobra.Command{ } // start set command - var setReq iam.PermissionsRequest var setJson flags.JsonFlag @@ -148,6 +131,7 @@ var setCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = setJson.Unmarshal(&setReq) if err != nil { @@ -169,7 +153,6 @@ var setCmd = &cobra.Command{ } // start update command - var updateReq iam.PermissionsRequest var updateJson flags.JsonFlag @@ -198,6 +181,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/pipelines/pipelines.go b/cmd/workspace/pipelines/pipelines.go index 0fd5f9a2e7..8d6ffff144 100755 --- a/cmd/workspace/pipelines/pipelines.go +++ b/cmd/workspace/pipelines/pipelines.go @@ -36,7 +36,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq pipelines.CreatePipeline var createJson flags.JsonFlag @@ -86,6 +85,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -106,14 +106,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq pipelines.DeletePipelineRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -129,12 +126,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." @@ -166,9 +158,8 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq pipelines.GetPipelineRequest -var getJson flags.JsonFlag + var getSkipWait bool var getTimeout time.Duration @@ -178,7 +169,6 @@ func init() { getCmd.Flags().BoolVar(&getSkipWait, "no-wait", getSkipWait, `do not wait to reach RUNNING state`) getCmd.Flags().DurationVar(&getTimeout, "timeout", 20*time.Minute, `maximum amount of time to reach RUNNING state`) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -192,12 +182,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." @@ -229,14 +214,11 @@ var getCmd = &cobra.Command{ } // start get-update command - var getUpdateReq pipelines.GetUpdateRequest -var getUpdateJson flags.JsonFlag func init() { Cmd.AddCommand(getUpdateCmd) // TODO: short flags - getUpdateCmd.Flags().Var(&getUpdateJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -256,12 +238,7 @@ var getUpdateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getUpdateJson.Unmarshal(&getUpdateReq) - if err != nil { - return err - } - } + getUpdateReq.PipelineId = args[0] getUpdateReq.UpdateId = args[1] @@ -277,7 +254,6 @@ var getUpdateCmd = &cobra.Command{ } // start list-pipeline-events command - var listPipelineEventsReq pipelines.ListPipelineEventsRequest var listPipelineEventsJson flags.JsonFlag @@ -305,6 +281,7 @@ var listPipelineEventsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listPipelineEventsJson.Unmarshal(&listPipelineEventsReq) if err != nil { @@ -342,7 +319,6 @@ var listPipelineEventsCmd = &cobra.Command{ } // start list-pipelines command - var listPipelinesReq pipelines.ListPipelinesRequest var listPipelinesJson flags.JsonFlag @@ -377,6 +353,7 @@ var listPipelinesCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listPipelinesJson.Unmarshal(&listPipelinesReq) if err != nil { @@ -397,14 +374,11 @@ var listPipelinesCmd = &cobra.Command{ } // start list-updates command - var listUpdatesReq pipelines.ListUpdatesRequest -var listUpdatesJson flags.JsonFlag func init() { Cmd.AddCommand(listUpdatesCmd) // TODO: short flags - listUpdatesCmd.Flags().Var(&listUpdatesJson, "json", `either inline JSON string or @path/to/file.json with request body`) listUpdatesCmd.Flags().IntVar(&listUpdatesReq.MaxResults, "max-results", listUpdatesReq.MaxResults, `Max number of entries to return in a single page.`) listUpdatesCmd.Flags().StringVar(&listUpdatesReq.PageToken, "page-token", listUpdatesReq.PageToken, `Page token returned by previous call.`) @@ -424,12 +398,7 @@ var listUpdatesCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listUpdatesJson.Unmarshal(&listUpdatesReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." @@ -461,9 +430,8 @@ var listUpdatesCmd = &cobra.Command{ } // start reset command - var resetReq pipelines.ResetRequest -var resetJson flags.JsonFlag + var resetSkipWait bool var resetTimeout time.Duration @@ -473,7 +441,6 @@ func init() { resetCmd.Flags().BoolVar(&resetSkipWait, "no-wait", resetSkipWait, `do not wait to reach RUNNING state`) resetCmd.Flags().DurationVar(&resetTimeout, "timeout", 20*time.Minute, `maximum amount of time to reach RUNNING state`) // TODO: short flags - resetCmd.Flags().Var(&resetJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -489,12 +456,7 @@ var resetCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = resetJson.Unmarshal(&resetReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." @@ -538,7 +500,6 @@ var resetCmd = &cobra.Command{ } // start start-update command - var startUpdateReq pipelines.StartUpdate var startUpdateJson flags.JsonFlag @@ -566,6 +527,7 @@ var startUpdateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = startUpdateJson.Unmarshal(&startUpdateReq) if err != nil { @@ -603,9 +565,8 @@ var startUpdateCmd = &cobra.Command{ } // start stop command - var stopReq pipelines.StopRequest -var stopJson flags.JsonFlag + var stopSkipWait bool var stopTimeout time.Duration @@ -615,7 +576,6 @@ func init() { stopCmd.Flags().BoolVar(&stopSkipWait, "no-wait", stopSkipWait, `do not wait to reach IDLE state`) stopCmd.Flags().DurationVar(&stopTimeout, "timeout", 20*time.Minute, `maximum amount of time to reach IDLE state`) // TODO: short flags - stopCmd.Flags().Var(&stopJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -631,12 +591,7 @@ var stopCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = stopJson.Unmarshal(&stopReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No PIPELINE_ID argument specified. Loading names for Pipelines drop-down." @@ -680,7 +635,6 @@ var stopCmd = &cobra.Command{ } // start update command - var updateReq pipelines.EditPipeline var updateJson flags.JsonFlag @@ -723,6 +677,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/policy-families/policy-families.go b/cmd/workspace/policy-families/policy-families.go index 7eedc03f4d..37b45c8e15 100755 --- a/cmd/workspace/policy-families/policy-families.go +++ b/cmd/workspace/policy-families/policy-families.go @@ -28,14 +28,11 @@ var Cmd = &cobra.Command{ } // start get command - var getReq compute.GetPolicyFamilyRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -51,12 +48,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.PolicyFamilyId = args[0] response, err := w.PolicyFamilies.Get(ctx, getReq) @@ -71,7 +63,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq compute.ListPolicyFamiliesRequest var listJson flags.JsonFlag @@ -100,6 +91,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { diff --git a/cmd/workspace/providers/providers.go b/cmd/workspace/providers/providers.go index 053f4f4b38..58ed33954a 100755 --- a/cmd/workspace/providers/providers.go +++ b/cmd/workspace/providers/providers.go @@ -22,7 +22,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq sharing.CreateProvider var createJson flags.JsonFlag @@ -56,6 +55,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -81,14 +81,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq sharing.DeleteProviderRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -105,12 +102,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down." @@ -142,14 +134,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq sharing.GetProviderRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -167,12 +156,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down." @@ -204,7 +188,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq sharing.ListProvidersRequest var listJson flags.JsonFlag @@ -239,6 +222,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -259,14 +243,11 @@ var listCmd = &cobra.Command{ } // start list-shares command - var listSharesReq sharing.ListSharesRequest -var listSharesJson flags.JsonFlag func init() { Cmd.AddCommand(listSharesCmd) // TODO: short flags - listSharesCmd.Flags().Var(&listSharesJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -284,12 +265,7 @@ var listSharesCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listSharesJson.Unmarshal(&listSharesReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Providers drop-down." @@ -321,7 +297,6 @@ var listSharesCmd = &cobra.Command{ } // start update command - var updateReq sharing.UpdateProvider var updateJson flags.JsonFlag @@ -352,6 +327,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/queries/queries.go b/cmd/workspace/queries/queries.go index 7303b7f17d..3f7e8ca319 100755 --- a/cmd/workspace/queries/queries.go +++ b/cmd/workspace/queries/queries.go @@ -25,7 +25,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq sql.QueryPostContent var createJson flags.JsonFlag @@ -70,6 +69,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -90,14 +90,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq sql.DeleteQueryRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -115,12 +112,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." @@ -152,14 +144,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq sql.GetQueryRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -176,12 +165,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." @@ -213,7 +197,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq sql.ListQueriesRequest var listJson flags.JsonFlag @@ -249,6 +232,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -269,14 +253,11 @@ var listCmd = &cobra.Command{ } // start restore command - var restoreReq sql.RestoreQueryRequest -var restoreJson flags.JsonFlag func init() { Cmd.AddCommand(restoreCmd) // TODO: short flags - restoreCmd.Flags().Var(&restoreJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -293,12 +274,7 @@ var restoreCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = restoreJson.Unmarshal(&restoreReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No QUERY_ID argument specified. Loading names for Queries drop-down." @@ -330,7 +306,6 @@ var restoreCmd = &cobra.Command{ } // start update command - var updateReq sql.QueryEditContent var updateJson flags.JsonFlag @@ -361,6 +336,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/query-history/query-history.go b/cmd/workspace/query-history/query-history.go index 1ed8a48895..5b1e86d0d4 100755 --- a/cmd/workspace/query-history/query-history.go +++ b/cmd/workspace/query-history/query-history.go @@ -20,7 +20,6 @@ var Cmd = &cobra.Command{ } // start list command - var listReq sql.ListQueryHistoryRequest var listJson flags.JsonFlag @@ -57,6 +56,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { diff --git a/cmd/workspace/recipient-activation/recipient-activation.go b/cmd/workspace/recipient-activation/recipient-activation.go index ab1a208d29..33bc54ef2b 100755 --- a/cmd/workspace/recipient-activation/recipient-activation.go +++ b/cmd/workspace/recipient-activation/recipient-activation.go @@ -5,7 +5,6 @@ package recipient_activation import ( "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" - "github.com/databricks/cli/libs/flags" "github.com/databricks/databricks-sdk-go/service/sharing" "github.com/spf13/cobra" ) @@ -20,14 +19,11 @@ var Cmd = &cobra.Command{ } // start get-activation-url-info command - var getActivationUrlInfoReq sharing.GetActivationUrlInfoRequest -var getActivationUrlInfoJson flags.JsonFlag func init() { Cmd.AddCommand(getActivationUrlInfoCmd) // TODO: short flags - getActivationUrlInfoCmd.Flags().Var(&getActivationUrlInfoJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -47,12 +43,7 @@ var getActivationUrlInfoCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getActivationUrlInfoJson.Unmarshal(&getActivationUrlInfoReq) - if err != nil { - return err - } - } + getActivationUrlInfoReq.ActivationUrl = args[0] err = w.RecipientActivation.GetActivationUrlInfo(ctx, getActivationUrlInfoReq) @@ -67,14 +58,11 @@ var getActivationUrlInfoCmd = &cobra.Command{ } // start retrieve-token command - var retrieveTokenReq sharing.RetrieveTokenRequest -var retrieveTokenJson flags.JsonFlag func init() { Cmd.AddCommand(retrieveTokenCmd) // TODO: short flags - retrieveTokenCmd.Flags().Var(&retrieveTokenJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -95,12 +83,7 @@ var retrieveTokenCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = retrieveTokenJson.Unmarshal(&retrieveTokenReq) - if err != nil { - return err - } - } + retrieveTokenReq.ActivationUrl = args[0] response, err := w.RecipientActivation.RetrieveToken(ctx, retrieveTokenReq) diff --git a/cmd/workspace/recipients/recipients.go b/cmd/workspace/recipients/recipients.go index c44ec6a3a6..bb8f9b17f7 100755 --- a/cmd/workspace/recipients/recipients.go +++ b/cmd/workspace/recipients/recipients.go @@ -22,7 +22,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq sharing.CreateRecipient var createJson flags.JsonFlag @@ -61,6 +60,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -86,14 +86,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq sharing.DeleteRecipientRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -110,12 +107,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Recipients drop-down." @@ -147,14 +139,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq sharing.GetRecipientRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -172,12 +161,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Recipients drop-down." @@ -209,7 +193,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq sharing.ListRecipientsRequest var listJson flags.JsonFlag @@ -244,6 +227,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -264,14 +248,11 @@ var listCmd = &cobra.Command{ } // start rotate-token command - var rotateTokenReq sharing.RotateRecipientToken -var rotateTokenJson flags.JsonFlag func init() { Cmd.AddCommand(rotateTokenCmd) // TODO: short flags - rotateTokenCmd.Flags().Var(&rotateTokenJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -292,12 +273,7 @@ var rotateTokenCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = rotateTokenJson.Unmarshal(&rotateTokenReq) - if err != nil { - return err - } - } + _, err = fmt.Sscan(args[0], &rotateTokenReq.ExistingTokenExpireInSeconds) if err != nil { return fmt.Errorf("invalid EXISTING_TOKEN_EXPIRE_IN_SECONDS: %s", args[0]) @@ -316,14 +292,11 @@ var rotateTokenCmd = &cobra.Command{ } // start share-permissions command - var sharePermissionsReq sharing.SharePermissionsRequest -var sharePermissionsJson flags.JsonFlag func init() { Cmd.AddCommand(sharePermissionsCmd) // TODO: short flags - sharePermissionsCmd.Flags().Var(&sharePermissionsJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -340,12 +313,7 @@ var sharePermissionsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = sharePermissionsJson.Unmarshal(&sharePermissionsReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Recipients drop-down." @@ -377,7 +345,6 @@ var sharePermissionsCmd = &cobra.Command{ } // start update command - var updateReq sharing.UpdateRecipient var updateJson flags.JsonFlag @@ -408,6 +375,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/repos/overrides.go b/cmd/workspace/repos/overrides.go index 44d9dca473..127a794a51 100644 --- a/cmd/workspace/repos/overrides.go +++ b/cmd/workspace/repos/overrides.go @@ -57,16 +57,10 @@ func init() { deleteCmd.RunE = func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } else { - deleteReq.RepoId, err = repoArgumentToRepoID(ctx, w, args) - if err != nil { - return err - } + + deleteReq.RepoId, err = repoArgumentToRepoID(ctx, w, args) + if err != nil { + return err } err = w.Repos.Delete(ctx, deleteReq) if err != nil { @@ -79,16 +73,9 @@ func init() { getCmd.RunE = func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } else { - getReq.RepoId, err = repoArgumentToRepoID(ctx, w, args) - if err != nil { - return err - } + getReq.RepoId, err = repoArgumentToRepoID(ctx, w, args) + if err != nil { + return err } response, err := w.Repos.Get(ctx, getReq) diff --git a/cmd/workspace/repos/repos.go b/cmd/workspace/repos/repos.go index f8c594f708..fdd9556d49 100755 --- a/cmd/workspace/repos/repos.go +++ b/cmd/workspace/repos/repos.go @@ -31,7 +31,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq workspace.CreateRepo var createJson flags.JsonFlag @@ -66,6 +65,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -88,14 +88,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq workspace.DeleteRepoRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -111,12 +108,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No REPO_ID argument specified. Loading names for Repos drop-down." @@ -151,14 +143,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq workspace.GetRepoRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -174,12 +163,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No REPO_ID argument specified. Loading names for Repos drop-down." @@ -214,7 +198,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq workspace.ListReposRequest var listJson flags.JsonFlag @@ -248,6 +231,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -268,7 +252,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq workspace.UpdateRepo var updateJson flags.JsonFlag @@ -296,6 +279,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/schemas/schemas.go b/cmd/workspace/schemas/schemas.go index d8d8ac9d69..4a6eb33b96 100755 --- a/cmd/workspace/schemas/schemas.go +++ b/cmd/workspace/schemas/schemas.go @@ -26,7 +26,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.CreateSchema var createJson flags.JsonFlag @@ -62,6 +61,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -84,14 +84,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteSchemaRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -108,12 +105,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No FULL_NAME argument specified. Loading names for Schemas drop-down." @@ -145,14 +137,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetSchemaRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -170,12 +159,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No FULL_NAME argument specified. Loading names for Schemas drop-down." @@ -207,14 +191,11 @@ var getCmd = &cobra.Command{ } // start list command - var listReq catalog.ListSchemasRequest -var listJson flags.JsonFlag func init() { Cmd.AddCommand(listCmd) // TODO: short flags - listCmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -238,12 +219,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listJson.Unmarshal(&listReq) - if err != nil { - return err - } - } + listReq.CatalogName = args[0] response, err := w.Schemas.ListAll(ctx, listReq) @@ -258,7 +234,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateSchema var updateJson flags.JsonFlag @@ -290,6 +265,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/secrets/secrets.go b/cmd/workspace/secrets/secrets.go index 0e9f5d4e7b..fada4d1fe5 100755 --- a/cmd/workspace/secrets/secrets.go +++ b/cmd/workspace/secrets/secrets.go @@ -33,7 +33,6 @@ var Cmd = &cobra.Command{ } // start create-scope command - var createScopeReq workspace.CreateScope var createScopeJson flags.JsonFlag @@ -69,6 +68,7 @@ var createScopeCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createScopeJson.Unmarshal(&createScopeReq) if err != nil { @@ -90,7 +90,6 @@ var createScopeCmd = &cobra.Command{ } // start delete-acl command - var deleteAclReq workspace.DeleteAcl var deleteAclJson flags.JsonFlag @@ -125,6 +124,7 @@ var deleteAclCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteAclJson.Unmarshal(&deleteAclReq) if err != nil { @@ -147,7 +147,6 @@ var deleteAclCmd = &cobra.Command{ } // start delete-scope command - var deleteScopeReq workspace.DeleteScope var deleteScopeJson flags.JsonFlag @@ -181,6 +180,7 @@ var deleteScopeCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteScopeJson.Unmarshal(&deleteScopeReq) if err != nil { @@ -202,7 +202,6 @@ var deleteScopeCmd = &cobra.Command{ } // start delete-secret command - var deleteSecretReq workspace.DeleteSecret var deleteSecretJson flags.JsonFlag @@ -237,6 +236,7 @@ var deleteSecretCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteSecretJson.Unmarshal(&deleteSecretReq) if err != nil { @@ -259,14 +259,11 @@ var deleteSecretCmd = &cobra.Command{ } // start get-acl command - var getAclReq workspace.GetAclRequest -var getAclJson flags.JsonFlag func init() { Cmd.AddCommand(getAclCmd) // TODO: short flags - getAclCmd.Flags().Var(&getAclJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -291,12 +288,7 @@ var getAclCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getAclJson.Unmarshal(&getAclReq) - if err != nil { - return err - } - } + getAclReq.Scope = args[0] getAclReq.Principal = args[1] @@ -312,14 +304,11 @@ var getAclCmd = &cobra.Command{ } // start list-acls command - var listAclsReq workspace.ListAclsRequest -var listAclsJson flags.JsonFlag func init() { Cmd.AddCommand(listAclsCmd) // TODO: short flags - listAclsCmd.Flags().Var(&listAclsJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -344,12 +333,7 @@ var listAclsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listAclsJson.Unmarshal(&listAclsReq) - if err != nil { - return err - } - } + listAclsReq.Scope = args[0] response, err := w.Secrets.ListAclsAll(ctx, listAclsReq) @@ -397,14 +381,11 @@ var listScopesCmd = &cobra.Command{ } // start list-secrets command - var listSecretsReq workspace.ListSecretsRequest -var listSecretsJson flags.JsonFlag func init() { Cmd.AddCommand(listSecretsCmd) // TODO: short flags - listSecretsCmd.Flags().Var(&listSecretsJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -431,12 +412,7 @@ var listSecretsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listSecretsJson.Unmarshal(&listSecretsReq) - if err != nil { - return err - } - } + listSecretsReq.Scope = args[0] response, err := w.Secrets.ListSecretsAll(ctx, listSecretsReq) @@ -451,7 +427,6 @@ var listSecretsCmd = &cobra.Command{ } // start put-acl command - var putAclReq workspace.PutAcl var putAclJson flags.JsonFlag @@ -506,6 +481,7 @@ var putAclCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = putAclJson.Unmarshal(&putAclReq) if err != nil { diff --git a/cmd/workspace/service-principals/service-principals.go b/cmd/workspace/service-principals/service-principals.go index f444a83cb7..7dfc390f24 100755 --- a/cmd/workspace/service-principals/service-principals.go +++ b/cmd/workspace/service-principals/service-principals.go @@ -27,7 +27,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq iam.ServicePrincipal var createJson flags.JsonFlag @@ -66,6 +65,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -86,14 +86,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq iam.DeleteServicePrincipalRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -109,12 +106,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Service Principals drop-down." @@ -146,14 +138,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq iam.GetServicePrincipalRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -170,12 +159,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Service Principals drop-down." @@ -207,7 +191,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListServicePrincipalsRequest var listJson flags.JsonFlag @@ -245,6 +228,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -265,7 +249,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -291,6 +274,7 @@ var patchCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = patchJson.Unmarshal(&patchReq) if err != nil { @@ -328,7 +312,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.ServicePrincipal var updateJson flags.JsonFlag @@ -362,6 +345,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/serving-endpoints/serving-endpoints.go b/cmd/workspace/serving-endpoints/serving-endpoints.go index 5471f62891..46c830ebc9 100755 --- a/cmd/workspace/serving-endpoints/serving-endpoints.go +++ b/cmd/workspace/serving-endpoints/serving-endpoints.go @@ -35,14 +35,11 @@ var Cmd = &cobra.Command{ } // start build-logs command - var buildLogsReq serving.BuildLogsRequest -var buildLogsJson flags.JsonFlag func init() { Cmd.AddCommand(buildLogsCmd) // TODO: short flags - buildLogsCmd.Flags().Var(&buildLogsJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -63,12 +60,7 @@ var buildLogsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = buildLogsJson.Unmarshal(&buildLogsReq) - if err != nil { - return err - } - } + buildLogsReq.Name = args[0] buildLogsReq.ServedModelName = args[1] @@ -84,9 +76,9 @@ var buildLogsCmd = &cobra.Command{ } // start create command - var createReq serving.CreateServingEndpoint var createJson flags.JsonFlag + var createSkipWait bool var createTimeout time.Duration @@ -110,6 +102,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -144,14 +137,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq serving.DeleteServingEndpointRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -169,12 +159,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + deleteReq.Name = args[0] err = w.ServingEndpoints.Delete(ctx, deleteReq) @@ -189,14 +174,11 @@ var deleteCmd = &cobra.Command{ } // start export-metrics command - var exportMetricsReq serving.ExportMetricsRequest -var exportMetricsJson flags.JsonFlag func init() { Cmd.AddCommand(exportMetricsCmd) // TODO: short flags - exportMetricsCmd.Flags().Var(&exportMetricsJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -217,12 +199,7 @@ var exportMetricsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = exportMetricsJson.Unmarshal(&exportMetricsReq) - if err != nil { - return err - } - } + exportMetricsReq.Name = args[0] err = w.ServingEndpoints.ExportMetrics(ctx, exportMetricsReq) @@ -237,14 +214,11 @@ var exportMetricsCmd = &cobra.Command{ } // start get command - var getReq serving.GetServingEndpointRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -264,12 +238,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.Name = args[0] response, err := w.ServingEndpoints.Get(ctx, getReq) @@ -312,14 +281,11 @@ var listCmd = &cobra.Command{ } // start logs command - var logsReq serving.LogsRequest -var logsJson flags.JsonFlag func init() { Cmd.AddCommand(logsCmd) // TODO: short flags - logsCmd.Flags().Var(&logsJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -340,12 +306,7 @@ var logsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = logsJson.Unmarshal(&logsReq) - if err != nil { - return err - } - } + logsReq.Name = args[0] logsReq.ServedModelName = args[1] @@ -361,14 +322,11 @@ var logsCmd = &cobra.Command{ } // start query command - var queryReq serving.QueryRequest -var queryJson flags.JsonFlag func init() { Cmd.AddCommand(queryCmd) // TODO: short flags - queryCmd.Flags().Var(&queryJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -386,12 +344,7 @@ var queryCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = queryJson.Unmarshal(&queryReq) - if err != nil { - return err - } - } + queryReq.Name = args[0] response, err := w.ServingEndpoints.Query(ctx, queryReq) @@ -406,9 +359,9 @@ var queryCmd = &cobra.Command{ } // start update-config command - var updateConfigReq serving.EndpointCoreConfigInput var updateConfigJson flags.JsonFlag + var updateConfigSkipWait bool var updateConfigTimeout time.Duration @@ -439,6 +392,7 @@ var updateConfigCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateConfigJson.Unmarshal(&updateConfigReq) if err != nil { diff --git a/cmd/workspace/shares/shares.go b/cmd/workspace/shares/shares.go index 1457ba514a..2580b060e3 100755 --- a/cmd/workspace/shares/shares.go +++ b/cmd/workspace/shares/shares.go @@ -20,7 +20,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq sharing.CreateShare var createJson flags.JsonFlag @@ -54,6 +53,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -75,14 +75,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq sharing.DeleteShareRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -103,12 +100,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + deleteReq.Name = args[0] err = w.Shares.Delete(ctx, deleteReq) @@ -123,14 +115,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq sharing.GetShareRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) getCmd.Flags().BoolVar(&getReq.IncludeSharedData, "include-shared-data", getReq.IncludeSharedData, `Query for data to include in the share.`) @@ -153,12 +142,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.Name = args[0] response, err := w.Shares.Get(ctx, getReq) @@ -205,14 +189,11 @@ var listCmd = &cobra.Command{ } // start share-permissions command - var sharePermissionsReq sharing.SharePermissionsRequest -var sharePermissionsJson flags.JsonFlag func init() { Cmd.AddCommand(sharePermissionsCmd) // TODO: short flags - sharePermissionsCmd.Flags().Var(&sharePermissionsJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -233,12 +214,7 @@ var sharePermissionsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = sharePermissionsJson.Unmarshal(&sharePermissionsReq) - if err != nil { - return err - } - } + sharePermissionsReq.Name = args[0] response, err := w.Shares.SharePermissions(ctx, sharePermissionsReq) @@ -253,7 +229,6 @@ var sharePermissionsCmd = &cobra.Command{ } // start update command - var updateReq sharing.UpdateShare var updateJson flags.JsonFlag @@ -301,6 +276,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { @@ -322,7 +298,6 @@ var updateCmd = &cobra.Command{ } // start update-permissions command - var updatePermissionsReq sharing.UpdateSharePermissions var updatePermissionsJson flags.JsonFlag @@ -355,6 +330,7 @@ var updatePermissionsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updatePermissionsJson.Unmarshal(&updatePermissionsReq) if err != nil { diff --git a/cmd/workspace/storage-credentials/storage-credentials.go b/cmd/workspace/storage-credentials/storage-credentials.go index 9518d8f2b5..bbd7dd581e 100755 --- a/cmd/workspace/storage-credentials/storage-credentials.go +++ b/cmd/workspace/storage-credentials/storage-credentials.go @@ -34,7 +34,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.CreateStorageCredential var createJson flags.JsonFlag @@ -79,6 +78,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -100,14 +100,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteStorageCredentialRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) deleteCmd.Flags().BoolVar(&deleteReq.Force, "force", deleteReq.Force, `Force deletion even if there are dependent external locations or external tables.`) @@ -126,12 +123,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Storage Credentials drop-down." @@ -163,14 +155,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetStorageCredentialRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -188,12 +177,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No NAME argument specified. Loading names for Storage Credentials drop-down." @@ -259,7 +243,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateStorageCredential var updateJson flags.JsonFlag @@ -295,6 +278,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { @@ -333,7 +317,6 @@ var updateCmd = &cobra.Command{ } // start validate command - var validateReq catalog.ValidateStorageCredential var validateJson flags.JsonFlag @@ -383,6 +366,7 @@ var validateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = validateJson.Unmarshal(&validateReq) if err != nil { diff --git a/cmd/workspace/system-schemas/system-schemas.go b/cmd/workspace/system-schemas/system-schemas.go index 76f20cc692..b492f27450 100755 --- a/cmd/workspace/system-schemas/system-schemas.go +++ b/cmd/workspace/system-schemas/system-schemas.go @@ -7,7 +7,6 @@ import ( "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" - "github.com/databricks/cli/libs/flags" "github.com/databricks/databricks-sdk-go/service/catalog" "github.com/spf13/cobra" ) @@ -27,14 +26,11 @@ var Cmd = &cobra.Command{ } // start disable command - var disableReq catalog.DisableRequest -var disableJson flags.JsonFlag func init() { Cmd.AddCommand(disableCmd) // TODO: short flags - disableCmd.Flags().Var(&disableJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -55,12 +51,7 @@ var disableCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = disableJson.Unmarshal(&disableReq) - if err != nil { - return err - } - } + disableReq.MetastoreId = args[0] _, err = fmt.Sscan(args[1], &disableReq.SchemaName) if err != nil { @@ -79,14 +70,11 @@ var disableCmd = &cobra.Command{ } // start enable command - var enableReq catalog.EnableRequest -var enableJson flags.JsonFlag func init() { Cmd.AddCommand(enableCmd) // TODO: short flags - enableCmd.Flags().Var(&enableJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -107,12 +95,7 @@ var enableCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = enableJson.Unmarshal(&enableReq) - if err != nil { - return err - } - } + enableReq.MetastoreId = args[0] _, err = fmt.Sscan(args[1], &enableReq.SchemaName) if err != nil { @@ -131,14 +114,11 @@ var enableCmd = &cobra.Command{ } // start list command - var listReq catalog.ListSystemSchemasRequest -var listJson flags.JsonFlag func init() { Cmd.AddCommand(listCmd) // TODO: short flags - listCmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -159,12 +139,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listJson.Unmarshal(&listReq) - if err != nil { - return err - } - } + listReq.MetastoreId = args[0] response, err := w.SystemSchemas.ListAll(ctx, listReq) diff --git a/cmd/workspace/table-constraints/table-constraints.go b/cmd/workspace/table-constraints/table-constraints.go index de91465e96..d9588b8fcd 100755 --- a/cmd/workspace/table-constraints/table-constraints.go +++ b/cmd/workspace/table-constraints/table-constraints.go @@ -34,7 +34,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.CreateTableConstraint var createJson flags.JsonFlag @@ -66,6 +65,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -87,14 +87,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteTableConstraintRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -122,12 +119,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + deleteReq.FullName = args[0] deleteReq.ConstraintName = args[1] _, err = fmt.Sscan(args[2], &deleteReq.Cascade) diff --git a/cmd/workspace/tables/tables.go b/cmd/workspace/tables/tables.go index 4de5893348..9ff653b992 100755 --- a/cmd/workspace/tables/tables.go +++ b/cmd/workspace/tables/tables.go @@ -7,7 +7,6 @@ import ( "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" - "github.com/databricks/cli/libs/flags" "github.com/databricks/databricks-sdk-go/service/catalog" "github.com/spf13/cobra" ) @@ -30,14 +29,11 @@ var Cmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteTableRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -57,12 +53,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No FULL_NAME argument specified. Loading names for Tables drop-down." @@ -94,14 +85,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq catalog.GetTableRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) getCmd.Flags().BoolVar(&getReq.IncludeDeltaMetadata, "include-delta-metadata", getReq.IncludeDeltaMetadata, `Whether delta metadata should be included in the response.`) @@ -123,12 +111,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No FULL_NAME argument specified. Loading names for Tables drop-down." @@ -160,14 +143,11 @@ var getCmd = &cobra.Command{ } // start list command - var listReq catalog.ListTablesRequest -var listJson flags.JsonFlag func init() { Cmd.AddCommand(listCmd) // TODO: short flags - listCmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`) listCmd.Flags().BoolVar(&listReq.IncludeDeltaMetadata, "include-delta-metadata", listReq.IncludeDeltaMetadata, `Whether delta metadata should be included in the response.`) listCmd.Flags().IntVar(&listReq.MaxResults, "max-results", listReq.MaxResults, `Maximum number of tables to return (page length).`) @@ -196,12 +176,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listJson.Unmarshal(&listReq) - if err != nil { - return err - } - } + listReq.CatalogName = args[0] listReq.SchemaName = args[1] @@ -217,14 +192,11 @@ var listCmd = &cobra.Command{ } // start list-summaries command - var listSummariesReq catalog.ListSummariesRequest -var listSummariesJson flags.JsonFlag func init() { Cmd.AddCommand(listSummariesCmd) // TODO: short flags - listSummariesCmd.Flags().Var(&listSummariesJson, "json", `either inline JSON string or @path/to/file.json with request body`) listSummariesCmd.Flags().IntVar(&listSummariesReq.MaxResults, "max-results", listSummariesReq.MaxResults, `Maximum number of tables to return (page length).`) listSummariesCmd.Flags().StringVar(&listSummariesReq.PageToken, "page-token", listSummariesReq.PageToken, `Opaque token to send for the next page of results (pagination).`) @@ -255,12 +227,7 @@ var listSummariesCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listSummariesJson.Unmarshal(&listSummariesReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No CATALOG_NAME argument specified. Loading names for Tables drop-down." diff --git a/cmd/workspace/token-management/token-management.go b/cmd/workspace/token-management/token-management.go index f6563fbd26..b5cc542c18 100755 --- a/cmd/workspace/token-management/token-management.go +++ b/cmd/workspace/token-management/token-management.go @@ -24,7 +24,6 @@ var Cmd = &cobra.Command{ } // start create-obo-token command - var createOboTokenReq settings.CreateOboTokenRequest var createOboTokenJson flags.JsonFlag @@ -56,6 +55,7 @@ var createOboTokenCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createOboTokenJson.Unmarshal(&createOboTokenReq) if err != nil { @@ -81,14 +81,11 @@ var createOboTokenCmd = &cobra.Command{ } // start delete command - var deleteReq settings.DeleteTokenManagementRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -104,12 +101,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No TOKEN_ID argument specified. Loading names for Token Management drop-down." @@ -141,14 +133,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq settings.GetTokenManagementRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -164,12 +153,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No TOKEN_ID argument specified. Loading names for Token Management drop-down." @@ -201,7 +185,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq settings.ListTokenManagementRequest var listJson flags.JsonFlag @@ -234,6 +217,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { diff --git a/cmd/workspace/tokens/tokens.go b/cmd/workspace/tokens/tokens.go index e0fc5a9b79..c121793b65 100755 --- a/cmd/workspace/tokens/tokens.go +++ b/cmd/workspace/tokens/tokens.go @@ -23,7 +23,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq settings.CreateTokenRequest var createJson flags.JsonFlag @@ -59,6 +58,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -79,7 +79,6 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq settings.RevokeTokenRequest var deleteJson flags.JsonFlag @@ -105,6 +104,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteJson.Unmarshal(&deleteReq) if err != nil { diff --git a/cmd/workspace/users/users.go b/cmd/workspace/users/users.go index 08c20ade96..570a8f79c0 100755 --- a/cmd/workspace/users/users.go +++ b/cmd/workspace/users/users.go @@ -32,7 +32,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq iam.User var createJson flags.JsonFlag @@ -74,6 +73,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -94,14 +94,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq iam.DeleteUserRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -118,12 +115,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Users drop-down." @@ -155,14 +147,11 @@ var deleteCmd = &cobra.Command{ } // start get command - var getReq iam.GetUserRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -178,12 +167,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Users drop-down." @@ -215,7 +199,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListUsersRequest var listJson flags.JsonFlag @@ -253,6 +236,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -273,7 +257,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -299,6 +282,7 @@ var patchCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = patchJson.Unmarshal(&patchReq) if err != nil { @@ -336,7 +320,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.User var updateJson flags.JsonFlag @@ -370,6 +353,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/volumes/volumes.go b/cmd/workspace/volumes/volumes.go index 4dbcf41560..e020700aa8 100755 --- a/cmd/workspace/volumes/volumes.go +++ b/cmd/workspace/volumes/volumes.go @@ -32,7 +32,6 @@ var Cmd = &cobra.Command{ } // start create command - var createReq catalog.CreateVolumeRequestContent var createJson flags.JsonFlag @@ -82,6 +81,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -109,14 +109,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq catalog.DeleteVolumeRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -136,12 +133,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No FULL_NAME_ARG argument specified. Loading names for Volumes drop-down." @@ -173,14 +165,11 @@ var deleteCmd = &cobra.Command{ } // start list command - var listReq catalog.ListVolumesRequest -var listJson flags.JsonFlag func init() { Cmd.AddCommand(listCmd) // TODO: short flags - listCmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -210,12 +199,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listJson.Unmarshal(&listReq) - if err != nil { - return err - } - } + listReq.CatalogName = args[0] listReq.SchemaName = args[1] @@ -231,14 +215,11 @@ var listCmd = &cobra.Command{ } // start read command - var readReq catalog.ReadVolumeRequest -var readJson flags.JsonFlag func init() { Cmd.AddCommand(readCmd) // TODO: short flags - readCmd.Flags().Var(&readJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -259,12 +240,7 @@ var readCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = readJson.Unmarshal(&readReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No FULL_NAME_ARG argument specified. Loading names for Volumes drop-down." @@ -296,14 +272,11 @@ var readCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateVolumeRequestContent -var updateJson flags.JsonFlag func init() { Cmd.AddCommand(updateCmd) // TODO: short flags - updateCmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`) updateCmd.Flags().StringVar(&updateReq.Comment, "comment", updateReq.Comment, `The comment attached to the volume.`) updateCmd.Flags().StringVar(&updateReq.Name, "name", updateReq.Name, `The name of the volume.`) @@ -330,12 +303,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = updateJson.Unmarshal(&updateReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No FULL_NAME_ARG argument specified. Loading names for Volumes drop-down." diff --git a/cmd/workspace/warehouses/warehouses.go b/cmd/workspace/warehouses/warehouses.go index 1c7ca23b1b..a29c4031e4 100755 --- a/cmd/workspace/warehouses/warehouses.go +++ b/cmd/workspace/warehouses/warehouses.go @@ -25,9 +25,9 @@ var Cmd = &cobra.Command{ } // start create command - var createReq sql.CreateWarehouseRequest var createJson flags.JsonFlag + var createSkipWait bool var createTimeout time.Duration @@ -74,6 +74,7 @@ var createCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = createJson.Unmarshal(&createReq) if err != nil { @@ -113,14 +114,11 @@ var createCmd = &cobra.Command{ } // start delete command - var deleteReq sql.DeleteWarehouseRequest -var deleteJson flags.JsonFlag func init() { Cmd.AddCommand(deleteCmd) // TODO: short flags - deleteCmd.Flags().Var(&deleteJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -136,12 +134,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = deleteJson.Unmarshal(&deleteReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." @@ -173,9 +166,9 @@ var deleteCmd = &cobra.Command{ } // start edit command - var editReq sql.EditWarehouseRequest var editJson flags.JsonFlag + var editSkipWait bool var editTimeout time.Duration @@ -215,6 +208,7 @@ var editCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = editJson.Unmarshal(&editReq) if err != nil { @@ -271,9 +265,8 @@ var editCmd = &cobra.Command{ } // start get command - var getReq sql.GetWarehouseRequest -var getJson flags.JsonFlag + var getSkipWait bool var getTimeout time.Duration @@ -283,7 +276,6 @@ func init() { getCmd.Flags().BoolVar(&getSkipWait, "no-wait", getSkipWait, `do not wait to reach RUNNING state`) getCmd.Flags().DurationVar(&getTimeout, "timeout", 20*time.Minute, `maximum amount of time to reach RUNNING state`) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -299,12 +291,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." @@ -367,7 +354,6 @@ var getWorkspaceWarehouseConfigCmd = &cobra.Command{ } // start list command - var listReq sql.ListWarehousesRequest var listJson flags.JsonFlag @@ -399,6 +385,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = listJson.Unmarshal(&listReq) if err != nil { @@ -419,7 +406,6 @@ var listCmd = &cobra.Command{ } // start set-workspace-warehouse-config command - var setWorkspaceWarehouseConfigReq sql.SetWorkspaceWarehouseConfigRequest var setWorkspaceWarehouseConfigJson flags.JsonFlag @@ -460,6 +446,7 @@ var setWorkspaceWarehouseConfigCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = setWorkspaceWarehouseConfigJson.Unmarshal(&setWorkspaceWarehouseConfigReq) if err != nil { @@ -480,9 +467,8 @@ var setWorkspaceWarehouseConfigCmd = &cobra.Command{ } // start start command - var startReq sql.StartRequest -var startJson flags.JsonFlag + var startSkipWait bool var startTimeout time.Duration @@ -492,7 +478,6 @@ func init() { startCmd.Flags().BoolVar(&startSkipWait, "no-wait", startSkipWait, `do not wait to reach RUNNING state`) startCmd.Flags().DurationVar(&startTimeout, "timeout", 20*time.Minute, `maximum amount of time to reach RUNNING state`) // TODO: short flags - startCmd.Flags().Var(&startJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -508,12 +493,7 @@ var startCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = startJson.Unmarshal(&startReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." @@ -564,9 +544,8 @@ var startCmd = &cobra.Command{ } // start stop command - var stopReq sql.StopRequest -var stopJson flags.JsonFlag + var stopSkipWait bool var stopTimeout time.Duration @@ -576,7 +555,6 @@ func init() { stopCmd.Flags().BoolVar(&stopSkipWait, "no-wait", stopSkipWait, `do not wait to reach STOPPED state`) stopCmd.Flags().DurationVar(&stopTimeout, "timeout", 20*time.Minute, `maximum amount of time to reach STOPPED state`) // TODO: short flags - stopCmd.Flags().Var(&stopJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -592,12 +570,7 @@ var stopCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = stopJson.Unmarshal(&stopReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No ID argument specified. Loading names for Warehouses drop-down." diff --git a/cmd/workspace/workspace-bindings/workspace-bindings.go b/cmd/workspace/workspace-bindings/workspace-bindings.go index fdebd9dd24..8780106b1d 100755 --- a/cmd/workspace/workspace-bindings/workspace-bindings.go +++ b/cmd/workspace/workspace-bindings/workspace-bindings.go @@ -25,14 +25,11 @@ var Cmd = &cobra.Command{ } // start get command - var getReq catalog.GetWorkspaceBindingRequest -var getJson flags.JsonFlag func init() { Cmd.AddCommand(getCmd) // TODO: short flags - getCmd.Flags().Var(&getJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -53,12 +50,7 @@ var getCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getJson.Unmarshal(&getReq) - if err != nil { - return err - } - } + getReq.Name = args[0] response, err := w.WorkspaceBindings.Get(ctx, getReq) @@ -73,7 +65,6 @@ var getCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateWorkspaceBindings var updateJson flags.JsonFlag @@ -104,6 +95,7 @@ var updateCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = updateJson.Unmarshal(&updateReq) if err != nil { diff --git a/cmd/workspace/workspace-conf/workspace-conf.go b/cmd/workspace/workspace-conf/workspace-conf.go index 233e3eabb4..f2f0bb7598 100755 --- a/cmd/workspace/workspace-conf/workspace-conf.go +++ b/cmd/workspace/workspace-conf/workspace-conf.go @@ -20,14 +20,11 @@ var Cmd = &cobra.Command{ } // start get-status command - var getStatusReq settings.GetStatusRequest -var getStatusJson flags.JsonFlag func init() { Cmd.AddCommand(getStatusCmd) // TODO: short flags - getStatusCmd.Flags().Var(&getStatusJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -47,12 +44,7 @@ var getStatusCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getStatusJson.Unmarshal(&getStatusReq) - if err != nil { - return err - } - } + getStatusReq.Keys = args[0] response, err := w.WorkspaceConf.GetStatus(ctx, getStatusReq) @@ -67,7 +59,6 @@ var getStatusCmd = &cobra.Command{ } // start set-status command - var setStatusReq settings.WorkspaceConf var setStatusJson flags.JsonFlag @@ -98,6 +89,7 @@ var setStatusCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = setStatusJson.Unmarshal(&setStatusReq) if err != nil { diff --git a/cmd/workspace/workspace/workspace.go b/cmd/workspace/workspace/workspace.go index f20d4b67be..ab9c6aec0f 100755 --- a/cmd/workspace/workspace/workspace.go +++ b/cmd/workspace/workspace/workspace.go @@ -26,7 +26,6 @@ var Cmd = &cobra.Command{ } // start delete command - var deleteReq workspace.Delete var deleteJson flags.JsonFlag @@ -58,6 +57,7 @@ var deleteCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = deleteJson.Unmarshal(&deleteReq) if err != nil { @@ -96,14 +96,11 @@ var deleteCmd = &cobra.Command{ } // start export command - var exportReq workspace.ExportRequest -var exportJson flags.JsonFlag func init() { Cmd.AddCommand(exportCmd) // TODO: short flags - exportCmd.Flags().Var(&exportJson, "json", `either inline JSON string or @path/to/file.json with request body`) exportCmd.Flags().Var(&exportReq.Format, "format", `This specifies the format of the exported file.`) @@ -128,12 +125,7 @@ var exportCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = exportJson.Unmarshal(&exportReq) - if err != nil { - return err - } - } + if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) promptSpinner <- "No PATH argument specified. Loading names for Workspace drop-down." @@ -165,14 +157,11 @@ var exportCmd = &cobra.Command{ } // start get-status command - var getStatusReq workspace.GetStatusRequest -var getStatusJson flags.JsonFlag func init() { Cmd.AddCommand(getStatusCmd) // TODO: short flags - getStatusCmd.Flags().Var(&getStatusJson, "json", `either inline JSON string or @path/to/file.json with request body`) } @@ -193,12 +182,7 @@ var getStatusCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = getStatusJson.Unmarshal(&getStatusReq) - if err != nil { - return err - } - } + getStatusReq.Path = args[0] response, err := w.Workspace.GetStatus(ctx, getStatusReq) @@ -213,7 +197,6 @@ var getStatusCmd = &cobra.Command{ } // start import command - var importReq workspace.Import var importJson flags.JsonFlag @@ -251,6 +234,7 @@ var importCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = importJson.Unmarshal(&importReq) if err != nil { @@ -272,14 +256,11 @@ var importCmd = &cobra.Command{ } // start list command - var listReq workspace.ListWorkspaceRequest -var listJson flags.JsonFlag func init() { Cmd.AddCommand(listCmd) // TODO: short flags - listCmd.Flags().Var(&listJson, "json", `either inline JSON string or @path/to/file.json with request body`) listCmd.Flags().IntVar(&listReq.NotebooksModifiedAfter, "notebooks-modified-after", listReq.NotebooksModifiedAfter, `UTC timestamp in milliseconds.`) @@ -303,12 +284,7 @@ var listCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) - if cmd.Flags().Changed("json") { - err = listJson.Unmarshal(&listReq) - if err != nil { - return err - } - } + listReq.Path = args[0] response, err := w.Workspace.ListAll(ctx, listReq) @@ -323,7 +299,6 @@ var listCmd = &cobra.Command{ } // start mkdirs command - var mkdirsReq workspace.Mkdirs var mkdirsJson flags.JsonFlag @@ -351,6 +326,7 @@ var mkdirsCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) (err error) { ctx := cmd.Context() w := root.WorkspaceClient(ctx) + if cmd.Flags().Changed("json") { err = mkdirsJson.Unmarshal(&mkdirsReq) if err != nil { From 081a9036a3a7859af195925dda7e05c79fc038f2 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Thu, 29 Jun 2023 16:25:18 +0200 Subject: [PATCH 3/5] fix --- .../access-control-proxy.go | 156 ------------------ 1 file changed, 156 deletions(-) delete mode 100755 cmd/workspace/access-control-proxy/access-control-proxy.go diff --git a/cmd/workspace/access-control-proxy/access-control-proxy.go b/cmd/workspace/access-control-proxy/access-control-proxy.go deleted file mode 100755 index 06d3b08fd5..0000000000 --- a/cmd/workspace/access-control-proxy/access-control-proxy.go +++ /dev/null @@ -1,156 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package access_control_proxy - -import ( - "fmt" - - "github.com/databricks/cli/cmd/root" - "github.com/databricks/cli/libs/cmdio" - "github.com/databricks/cli/libs/flags" - "github.com/databricks/databricks-sdk-go/service/iam" - "github.com/spf13/cobra" -) - -var Cmd = &cobra.Command{ - Use: "access-control-proxy", - Short: `These APIs manage access rules on resources in an account.`, - Long: `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. A - workspace must belong to an account for these APIs to work.`, - Annotations: map[string]string{ - "package": "iam", - }, -} - -// start get-assignable-roles-for-resource command -var getAssignableRolesForResourceReq iam.GetAssignableRolesForResourceRequest - -func init() { - Cmd.AddCommand(getAssignableRolesForResourceCmd) - // TODO: short flags - -} - -var getAssignableRolesForResourceCmd = &cobra.Command{ - Use: "get-assignable-roles-for-resource RESOURCE", - Short: `Get assignable roles for a resource.`, - Long: `Get assignable roles for a resource. - - Gets all the roles that can be granted on an account-level resource. A role is - grantable if the rule set on the resource can contain an access rule of the - role.`, - - Annotations: map[string]string{}, - Args: func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(1) - return check(cmd, args) - }, - PreRunE: root.MustWorkspaceClient, - RunE: func(cmd *cobra.Command, args []string) (err error) { - ctx := cmd.Context() - w := root.WorkspaceClient(ctx) - - getAssignableRolesForResourceReq.Resource = args[0] - - response, err := w.AccessControlProxy.GetAssignableRolesForResource(ctx, getAssignableRolesForResourceReq) - if err != nil { - return err - } - return cmdio.Render(ctx, response) - }, - // Disable completions since they are not applicable. - // Can be overridden by manual implementation in `override.go`. - ValidArgsFunction: cobra.NoFileCompletions, -} - -// start get-rule-set command -var getRuleSetReq iam.GetRuleSetRequest - -func init() { - Cmd.AddCommand(getRuleSetCmd) - // TODO: short flags - -} - -var getRuleSetCmd = &cobra.Command{ - Use: "get-rule-set NAME ETAG", - Short: `Get a rule set.`, - Long: `Get a rule set. - - Get a rule set by its name. A rule set is always attached to a resource and - contains a list of access rules on the said resource. Currently only a default - rule set for each resource is supported.`, - - Annotations: map[string]string{}, - Args: func(cmd *cobra.Command, args []string) error { - check := cobra.ExactArgs(2) - return check(cmd, args) - }, - PreRunE: root.MustWorkspaceClient, - RunE: func(cmd *cobra.Command, args []string) (err error) { - ctx := cmd.Context() - w := root.WorkspaceClient(ctx) - - getRuleSetReq.Name = args[0] - getRuleSetReq.Etag = args[1] - - response, err := w.AccessControlProxy.GetRuleSet(ctx, getRuleSetReq) - if err != nil { - return err - } - return cmdio.Render(ctx, response) - }, - // Disable completions since they are not applicable. - // Can be overridden by manual implementation in `override.go`. - ValidArgsFunction: cobra.NoFileCompletions, -} - -// start update-rule-set command -var updateRuleSetReq iam.UpdateRuleSetRequest -var updateRuleSetJson flags.JsonFlag - -func init() { - Cmd.AddCommand(updateRuleSetCmd) - // TODO: short flags - updateRuleSetCmd.Flags().Var(&updateRuleSetJson, "json", `either inline JSON string or @path/to/file.json with request body`) - -} - -var updateRuleSetCmd = &cobra.Command{ - Use: "update-rule-set", - Short: `Update a rule set.`, - Long: `Update a rule set. - - Replace the rules of a rule set. First, use a GET rule set request to read the - current version of the rule set before modifying it. This pattern helps - prevent conflicts between concurrent updates.`, - - Annotations: map[string]string{}, - PreRunE: root.MustWorkspaceClient, - RunE: func(cmd *cobra.Command, args []string) (err error) { - ctx := cmd.Context() - w := root.WorkspaceClient(ctx) - - if cmd.Flags().Changed("json") { - err = updateRuleSetJson.Unmarshal(&updateRuleSetReq) - if err != nil { - return err - } - } else { - return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") - } - - response, err := w.AccessControlProxy.UpdateRuleSet(ctx, updateRuleSetReq) - if err != nil { - return err - } - return cmdio.Render(ctx, response) - }, - // Disable completions since they are not applicable. - // Can be overridden by manual implementation in `override.go`. - ValidArgsFunction: cobra.NoFileCompletions, -} - -// end service AccountAccessControlProxy From 277262171f7cfd2b17519e1e5faf3f416f147700 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Mon, 3 Jul 2023 12:30:00 +0200 Subject: [PATCH 4/5] rebase --- .gitattributes | 1 - cmd/workspace/clusters/clusters.go | 56 +++++++++---------- .../system-schemas/system-schemas.go | 6 +- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/.gitattributes b/.gitattributes index db7560e293..8b95da2070 100755 --- a/.gitattributes +++ b/.gitattributes @@ -23,7 +23,6 @@ cmd/account/users/users.go linguist-generated=true cmd/account/vpc-endpoints/vpc-endpoints.go linguist-generated=true cmd/account/workspace-assignment/workspace-assignment.go linguist-generated=true cmd/account/workspaces/workspaces.go linguist-generated=true -cmd/workspace/access-control-proxy/access-control-proxy.go linguist-generated=true cmd/workspace/alerts/alerts.go linguist-generated=true cmd/workspace/catalogs/catalogs.go linguist-generated=true cmd/workspace/cluster-policies/cluster-policies.go linguist-generated=true diff --git a/cmd/workspace/clusters/clusters.go b/cmd/workspace/clusters/clusters.go index 250fcecc34..bc891eef79 100755 --- a/cmd/workspace/clusters/clusters.go +++ b/cmd/workspace/clusters/clusters.go @@ -18,26 +18,26 @@ var Cmd = &cobra.Command{ 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 delete clusters. - + Databricks maps cluster node instance types to compute units known as DBUs. See the instance type pricing page for a list of the supported instance types and their corresponding DBUs. - + A Databricks cluster is a set of computation resources and configurations on which you run data engineering, data science, and data analytics workloads, such as production ETL pipelines, streaming analytics, ad-hoc analytics, and machine learning. - + You run these workloads as a set of commands in a notebook or as an automated job. Databricks makes a distinction between all-purpose clusters and job clusters. You use all-purpose clusters to analyze data collaboratively using interactive notebooks. You use job clusters to run fast and robust automated jobs. - + You can create an all-purpose cluster using the UI, CLI, or REST API. You can manually terminate and restart an all-purpose cluster. Multiple users can share such clusters to do collaborative interactive analysis. - + IMPORTANT: Databricks retains cluster configuration information for up to 200 all-purpose clusters terminated in the last 30 days and up to 30 job clusters recently terminated by the job scheduler. To keep an all-purpose cluster @@ -63,7 +63,7 @@ var changeOwnerCmd = &cobra.Command{ Use: "change-owner CLUSTER_ID OWNER_USERNAME", Short: `Change cluster owner.`, Long: `Change cluster owner. - + Change the owner of the cluster. You must be an admin to perform this operation.`, @@ -147,12 +147,12 @@ var createCmd = &cobra.Command{ Use: "create SPARK_VERSION", Short: `Create new cluster.`, Long: `Create new cluster. - + Creates a new Spark cluster. This method will acquire new instances from the cloud provider if necessary. Note: Databricks may not be able to acquire some of the requested nodes, due to cloud provider limitations (account limits, spot price, etc.) or transient network issues. - + If Databricks acquires at least 85% of the requested on-demand nodes, cluster creation will succeed. Otherwise the cluster will terminate with an informative error message.`, @@ -223,7 +223,7 @@ var deleteCmd = &cobra.Command{ Use: "delete CLUSTER_ID", Short: `Terminate cluster.`, Long: `Terminate cluster. - + Terminates the Spark cluster with the specified ID. The cluster is removed asynchronously. Once the termination has completed, the cluster will be in a TERMINATED state. If the cluster is already in a TERMINATING or @@ -333,18 +333,18 @@ var editCmd = &cobra.Command{ Use: "edit CLUSTER_ID SPARK_VERSION", Short: `Update cluster configuration.`, Long: `Update cluster configuration. - + Updates the configuration of a cluster to match the provided attributes and size. A cluster can be updated if it is in a RUNNING or TERMINATED state. - + If a cluster is updated while in a RUNNING state, it will be restarted so that the new attributes can take effect. - + If a cluster is updated while in a TERMINATED state, it will remain TERMINATED. The next time it is started using the clusters/start API, the new attributes will take effect. Any attempt to update a cluster in any other state will be rejected with an INVALID_STATE error code. - + Clusters created by the Databricks Jobs service cannot be edited.`, Annotations: map[string]string{}, @@ -415,7 +415,7 @@ var eventsCmd = &cobra.Command{ Use: "events CLUSTER_ID", Short: `List cluster activity events.`, Long: `List cluster activity events. - + Retrieves a list of events about the activity of a cluster. This API is paginated. If there are more events to read, the response includes all the nparameters necessary to request the next page of events.`, @@ -482,7 +482,7 @@ var getCmd = &cobra.Command{ Use: "get CLUSTER_ID", Short: `Get cluster info.`, Long: `Get cluster info. - + Retrieves the information for a cluster given its identifier. Clusters can be described while they are running, or up to 60 days after they are terminated.`, @@ -539,11 +539,11 @@ var listCmd = &cobra.Command{ Use: "list", Short: `List all clusters.`, Long: `List all clusters. - + Return information about all pinned clusters, active clusters, up to 200 of the most recently terminated all-purpose clusters in the past 30 days, and up to 30 of the most recently terminated job clusters in the past 30 days. - + For example, if there is 1 pinned cluster, 4 active clusters, 45 terminated all-purpose clusters in the past 30 days, and 50 terminated job clusters in the past 30 days, then this API returns the 1 pinned cluster, 4 active @@ -593,7 +593,7 @@ var listNodeTypesCmd = &cobra.Command{ Use: "list-node-types", Short: `List node types.`, Long: `List node types. - + Returns a list of supported Spark node types. These node types can be used to launch a cluster.`, @@ -624,7 +624,7 @@ var listZonesCmd = &cobra.Command{ Use: "list-zones", Short: `List availability zones.`, Long: `List availability zones. - + Returns a list of availability zones where clusters can be created in (For example, us-west-2a). These zones can be used to launch a cluster.`, @@ -659,10 +659,10 @@ var permanentDeleteCmd = &cobra.Command{ Use: "permanent-delete CLUSTER_ID", Short: `Permanently delete cluster.`, Long: `Permanently delete cluster. - + Permanently deletes a Spark cluster. This cluster is terminated and resources are asynchronously removed. - + In addition, users will no longer see permanently deleted clusters in the cluster list, and API users can no longer perform any action on permanently deleted clusters.`, @@ -725,7 +725,7 @@ var pinCmd = &cobra.Command{ Use: "pin CLUSTER_ID", Short: `Pin cluster.`, Long: `Pin cluster. - + Pinning a cluster ensures that the cluster will always be returned by the ListClusters API. Pinning a cluster that is already pinned will have no effect. This API can only be called by workspace admins.`, @@ -797,7 +797,7 @@ var resizeCmd = &cobra.Command{ Use: "resize CLUSTER_ID", Short: `Resize cluster.`, Long: `Resize cluster. - + Resizes a cluster to have a desired number of workers. This will fail unless the cluster is in a RUNNING state.`, @@ -879,7 +879,7 @@ var restartCmd = &cobra.Command{ Use: "restart CLUSTER_ID", Short: `Restart cluster.`, Long: `Restart cluster. - + Restarts a Spark cluster with the supplied ID. If the cluster is not currently in a RUNNING state, nothing will happen.`, @@ -949,7 +949,7 @@ var sparkVersionsCmd = &cobra.Command{ Use: "spark-versions", Short: `List available Spark versions.`, Long: `List available Spark versions. - + Returns the list of available Spark versions. These versions can be used to launch a cluster.`, @@ -990,10 +990,10 @@ var startCmd = &cobra.Command{ Use: "start CLUSTER_ID", Short: `Start terminated cluster.`, Long: `Start terminated cluster. - + Starts a terminated Spark cluster with the supplied ID. This works similar to createCluster except: - + * The previous cluster id and attributes are preserved. * The cluster starts with the last specified cluster size. * If the previous cluster was an autoscaling cluster, the current cluster starts with the minimum number of @@ -1070,7 +1070,7 @@ var unpinCmd = &cobra.Command{ Use: "unpin CLUSTER_ID", Short: `Unpin cluster.`, Long: `Unpin cluster. - + Unpinning a cluster will allow the cluster to eventually be removed from the ListClusters API. Unpinning a cluster that is not pinned will have no effect. This API can only be called by workspace admins.`, diff --git a/cmd/workspace/system-schemas/system-schemas.go b/cmd/workspace/system-schemas/system-schemas.go index b492f27450..fed5e5e527 100755 --- a/cmd/workspace/system-schemas/system-schemas.go +++ b/cmd/workspace/system-schemas/system-schemas.go @@ -38,7 +38,7 @@ var disableCmd = &cobra.Command{ Use: "disable METASTORE_ID SCHEMA_NAME", Short: `Disable a system schema.`, Long: `Disable a system schema. - + Disables the system schema and removes it from the system catalog. The caller must be an account admin or a metastore admin.`, @@ -82,7 +82,7 @@ var enableCmd = &cobra.Command{ Use: "enable METASTORE_ID SCHEMA_NAME", Short: `Enable a system schema.`, Long: `Enable a system schema. - + Enables the system schema and adds it to the system catalog. The caller must be an account admin or a metastore admin.`, @@ -126,7 +126,7 @@ var listCmd = &cobra.Command{ Use: "list METASTORE_ID", Short: `List system schemas.`, Long: `List system schemas. - + Gets an array of system schemas for a metastore. The caller must be an account admin or a metastore admin.`, From 92e9d5149e6fe402c21568ee754c7290010ff70b Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Mon, 3 Jul 2023 12:33:32 +0200 Subject: [PATCH 5/5] revert deps update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3294e20257..f0d9060813 100644 --- a/go.mod +++ b/go.mod @@ -56,7 +56,7 @@ require ( golang.org/x/time v0.3.0 // indirect google.golang.org/api v0.129.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230628200519-e449d1ea0e82 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/grpc v1.56.1 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 6e05f14fe0..870d2ab2df 100644 --- a/go.sum +++ b/go.sum @@ -253,8 +253,8 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230628200519-e449d1ea0e82 h1:6b+zGQBiXFlAMpQr+cCarAdrZD4QgXSG7uUZadYysgg= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230628200519-e449d1ea0e82/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc h1:XSJ8Vk1SWuNr8S18z1NZSziL0CPIXLCCMDOEFtHBOFc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=