From 17ed7a317bddc816896d20ac7b1d574d016b10c7 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Mon, 3 Jul 2023 13:20:30 +0200 Subject: [PATCH] Fixed ignoring required positional parameters when --json flag is provided (#535) ## Changes When there are positional required parameters in the command which can't be unmarshalled from JSON, we should require them despite the fact `--json` flag is provided. The reason is that for some of the command, for example, `databricks groups patch ID` these arguments are actually path arguments in API and can't be set as part of `--json` body provided. Original change which introduced this ignore logic is here: https://github.com/databricks/cli/pull/405 Fixes https://github.com/databricks/cli/issues/533, https://github.com/databricks/cli/issues/537 Note: Code generation is based on the change in this PR: https://github.com/databricks/databricks-sdk-go/pull/536 ## Tests 1. Running `cli groups patch 123 --json {...}` works correctly Backward compatibility tests with previous changes from https://github.com/databricks/cli/pull/405 1. `cli clusters events --json '{"cluster_id": "1029-xxxx"}'` - works, returns list of events 2. `cli clusters events 1029-xxxx` - works, returns list of events 3. `cli clusters events` - works, first prompts for Cluster ID and then returns the list of events --- .codegen/service.go.tmpl | 17 +- cmd/account/access-control/access-control.go | 36 +-- cmd/account/billable-usage/billable-usage.go | 19 +- cmd/account/budgets/budgets.go | 82 ++--- cmd/account/credentials/credentials.go | 80 ++--- .../custom-app-integration.go | 42 +-- .../encryption-keys/encryption-keys.go | 34 +- cmd/account/groups/groups.go | 123 +++---- .../ip-access-lists/ip-access-lists.go | 84 ++--- cmd/account/log-delivery/log-delivery.go | 65 ++-- .../metastore-assignments.go | 90 ++---- cmd/account/metastores/metastores.go | 42 +-- cmd/account/networks/networks.go | 80 ++--- .../o-auth-enrollment/o-auth-enrollment.go | 2 +- cmd/account/private-access/private-access.go | 92 ++---- .../published-app-integration.go | 42 +-- .../service-principal-secrets.go | 63 +--- .../service-principals/service-principals.go | 123 +++---- cmd/account/settings/settings.go | 6 +- .../storage-credentials.go | 70 +--- cmd/account/storage/storage.go | 80 ++--- cmd/account/users/users.go | 123 +++---- cmd/account/vpc-endpoints/vpc-endpoints.go | 80 ++--- .../workspace-assignment.go | 70 +--- cmd/account/workspaces/workspaces.go | 139 ++++---- cmd/workspace/alerts/alerts.go | 82 ++--- cmd/workspace/catalogs/catalogs.go | 36 +-- .../cluster-policies/cluster-policies.go | 47 ++- cmd/workspace/clusters/clusters.go | 70 ++-- cmd/workspace/connections/connections.go | 82 ++--- cmd/workspace/dashboards/dashboards.go | 121 +++---- cmd/workspace/experiments/experiments.go | 104 ++---- .../external-locations/external-locations.go | 36 +-- cmd/workspace/functions/functions.go | 137 +++----- .../git-credentials/git-credentials.go | 137 ++++---- .../global-init-scripts.go | 100 ++---- cmd/workspace/grants/grants.go | 60 +--- cmd/workspace/groups/groups.go | 123 +++---- .../instance-pools/instance-pools.go | 45 ++- .../instance-profiles/instance-profiles.go | 6 +- .../ip-access-lists/ip-access-lists.go | 84 ++--- cmd/workspace/jobs/jobs.go | 209 ++++++------ cmd/workspace/libraries/libraries.go | 20 +- cmd/workspace/metastores/metastores.go | 212 +++++-------- .../model-registry/model-registry.go | 228 ++++--------- cmd/workspace/permissions/permissions.go | 56 +--- cmd/workspace/pipelines/pipelines.go | 300 +++++++----------- .../policy-families/policy-families.go | 18 +- cmd/workspace/providers/providers.go | 123 +++---- cmd/workspace/queries/queries.go | 160 ++++------ cmd/workspace/query-history/query-history.go | 2 +- .../recipient-activation.go | 33 +- cmd/workspace/recipients/recipients.go | 145 ++++----- cmd/workspace/repos/overrides.go | 27 +- cmd/workspace/repos/repos.go | 135 ++++---- cmd/workspace/schemas/schemas.go | 135 +++----- cmd/workspace/secrets/secrets.go | 60 +--- .../service-principals/service-principals.go | 123 +++---- .../serving-endpoints/serving-endpoints.go | 106 ++----- cmd/workspace/shares/shares.go | 60 +--- .../storage-credentials.go | 84 ++--- .../system-schemas/system-schemas.go | 61 +--- .../table-constraints/table-constraints.go | 26 +- cmd/workspace/tables/tables.go | 136 +++----- .../token-management/token-management.go | 82 ++--- cmd/workspace/tokens/tokens.go | 4 +- cmd/workspace/users/users.go | 123 +++---- cmd/workspace/volumes/volumes.go | 137 +++----- cmd/workspace/warehouses/warehouses.go | 206 +++++------- .../workspace-bindings/workspace-bindings.go | 24 +- .../workspace-conf/workspace-conf.go | 18 +- cmd/workspace/workspace/workspace.go | 77 ++--- 72 files changed, 2136 insertions(+), 3948 deletions(-) diff --git a/.codegen/service.go.tmpl b/.codegen/service.go.tmpl index bc69ce81..64c80b9a 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 -}} @@ -100,9 +107,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, @@ -110,12 +119,14 @@ 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 } - } else { + }{{end}}{{if $useJsonForAllFields }} else { + {{- end }} {{- if $hasIdPrompt}} if len(args) == 0 { promptSpinner := cmdio.Spinner(ctx) @@ -148,7 +159,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/cmd/account/access-control/access-control.go b/cmd/account/access-control/access-control.go index 72be53c3..5cec69a3 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`) } @@ -47,23 +44,14 @@ 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, 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 - } - } else { - getAssignableRolesForResourceReq.Resource = args[0] - } + + getAssignableRolesForResourceReq.Resource = args[0] response, err := a.AccessControl.GetAssignableRolesForResource(ctx, getAssignableRolesForResourceReq) if err != nil { @@ -77,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`) } @@ -100,24 +85,15 @@ 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, 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 - } - } 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 { @@ -131,7 +107,6 @@ var getRuleSetCmd = &cobra.Command{ } // start update-rule-set command - var updateRuleSetReq iam.UpdateRuleSetRequest var updateRuleSetJson flags.JsonFlag @@ -156,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 c4626773..babc7bc2 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.`) @@ -52,24 +48,15 @@ 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, 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 - } - } 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 e48952de..3e26b181 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,31 +90,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have budget id") - } - 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 { @@ -131,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`) } @@ -155,31 +143,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have budget id") - } - 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 { @@ -224,7 +206,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq billing.WrappedBudget var updateJson flags.JsonFlag @@ -248,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 c46595d5..5a1362d1 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,31 +105,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks account api credential configuration id") - } - 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 { @@ -146,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`) } @@ -170,31 +158,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks account api credential configuration id") - } - 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 4c836a5f..837ac518 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`) } @@ -100,23 +97,14 @@ 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, 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 - } - } else { - deleteReq.IntegrationId = args[0] - } + + deleteReq.IntegrationId = args[0] err = a.CustomAppIntegration.Delete(ctx, deleteReq) if err != nil { @@ -130,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`) } @@ -151,23 +136,14 @@ 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, 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 - } - } else { - getReq.IntegrationId = args[0] - } + + getReq.IntegrationId = args[0] response, err := a.CustomAppIntegration.Get(ctx, getReq) if err != nil { @@ -212,7 +188,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq oauth2.UpdateCustomAppIntegration var updateJson flags.JsonFlag @@ -237,23 +212,20 @@ 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, 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 } - } 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 0e8085f3..0db4af80 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`) } @@ -122,23 +119,14 @@ 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, 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 - } - } else { - deleteReq.CustomerManagedKeyId = args[0] - } + + deleteReq.CustomerManagedKeyId = args[0] err = a.EncryptionKeys.Delete(ctx, deleteReq) if err != nil { @@ -152,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`) } @@ -187,23 +172,14 @@ 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, 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 - } - } 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 1d5073f4..5897ef29 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,31 +108,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks account") - } - 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 { @@ -149,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`) } @@ -172,31 +160,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks account") - } - 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 { @@ -210,7 +192,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListAccountGroupsRequest var listJson flags.JsonFlag @@ -248,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 { @@ -268,7 +250,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -293,31 +274,31 @@ 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 { 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) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks account") - } - patchReq.Id = args[0] } + 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) != 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 { @@ -331,7 +312,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.Group var updateJson flags.JsonFlag @@ -363,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 8eeacbba..7f43ff2a 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,31 +120,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the id for the corresponding ip access list") - } - 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 { @@ -161,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`) } @@ -184,31 +172,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the id for the corresponding ip access list") - } - 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 { @@ -252,7 +234,6 @@ var listCmd = &cobra.Command{ } // start replace command - var replaceReq settings.ReplaceIpAccessList var replaceJson flags.JsonFlag @@ -286,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 { @@ -307,7 +289,6 @@ var replaceCmd = &cobra.Command{ } // start update command - var updateReq settings.UpdateIpAccessList var updateJson flags.JsonFlag @@ -345,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 0429127b..d5ae87b1 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,31 +179,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks log delivery configuration id") - } - 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 { @@ -220,7 +211,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq billing.ListLogDeliveryRequest var listJson flags.JsonFlag @@ -255,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 { @@ -275,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`) } @@ -300,27 +288,18 @@ 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, 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 - } - } 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 63b21893..673bb8f4 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 @@ -46,27 +45,24 @@ 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, 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 } - } 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 { @@ -80,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`) } @@ -103,27 +96,18 @@ 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, 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 - } - } 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 { @@ -137,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`) } @@ -162,25 +143,16 @@ 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, 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 - } - } 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) @@ -195,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`) } @@ -218,23 +187,14 @@ 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, 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 - } - } else { - listReq.MetastoreId = args[0] - } + + listReq.MetastoreId = args[0] response, err := a.MetastoreAssignments.List(ctx, listReq) if err != nil { @@ -248,7 +208,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.AccountsUpdateMetastoreAssignment var updateJson flags.JsonFlag @@ -273,27 +232,24 @@ 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, 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 } - } 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 e270b946..decbb406 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`) } @@ -96,23 +93,14 @@ 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, 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 - } - } else { - deleteReq.MetastoreId = args[0] - } + + deleteReq.MetastoreId = args[0] err = a.Metastores.Delete(ctx, deleteReq) if err != nil { @@ -126,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`) } @@ -148,23 +133,14 @@ 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, 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 - } - } else { - getReq.MetastoreId = args[0] - } + + getReq.MetastoreId = args[0] response, err := a.Metastores.Get(ctx, getReq) if err != nil { @@ -210,7 +186,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.AccountsUpdateMetastore var updateJson flags.JsonFlag @@ -234,23 +209,20 @@ 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, 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 } - } 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 b0214146..331f0869 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,31 +107,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks account api network configuration id") - } - 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 { @@ -148,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`) } @@ -172,31 +160,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks account api network configuration id") - } - 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/o-auth-enrollment/o-auth-enrollment.go b/cmd/account/o-auth-enrollment/o-auth-enrollment.go index 62961da5..a39306a3 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 6c35354f..ebb31dd0 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,31 +119,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks account api private access settings id") - } - 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 { @@ -160,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`) } @@ -190,31 +178,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks account api private access settings id") - } - 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 { @@ -259,7 +241,6 @@ var listCmd = &cobra.Command{ } // start replace command - var replaceReq provisioning.UpsertPrivateAccessSettingsRequest var replaceJson flags.JsonFlag @@ -304,25 +285,22 @@ 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, 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 { 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 6280f5cc..7eb6d4c9 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`) } @@ -104,23 +101,14 @@ 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, 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 - } - } else { - deleteReq.IntegrationId = args[0] - } + + deleteReq.IntegrationId = args[0] err = a.PublishedAppIntegration.Delete(ctx, deleteReq) if err != nil { @@ -134,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`) } @@ -155,23 +140,14 @@ 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, 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 - } - } else { - getReq.IntegrationId = args[0] - } + + getReq.IntegrationId = args[0] response, err := a.PublishedAppIntegration.Get(ctx, getReq) if err != nil { @@ -216,7 +192,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq oauth2.UpdatePublishedAppIntegration var updateJson flags.JsonFlag @@ -240,23 +215,20 @@ 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, 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 } - } 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 5cf5d453..8c4c1fb9 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`) } @@ -55,25 +51,16 @@ 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, 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 - } - } 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) @@ -88,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`) } @@ -109,27 +93,18 @@ 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, 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 - } - } 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 { @@ -143,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`) } @@ -166,25 +138,16 @@ 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, 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 - } - } 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 df969b5e..6ed4a69a 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,31 +106,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks account") - } - 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 { @@ -147,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`) } @@ -171,31 +159,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks account") - } - 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 { @@ -209,7 +191,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListAccountServicePrincipalsRequest var listJson flags.JsonFlag @@ -247,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 { @@ -267,7 +249,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -293,31 +274,31 @@ 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 { 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) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks account") - } - patchReq.Id = args[0] } + 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) != 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 { @@ -331,7 +312,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.ServicePrincipal var updateJson flags.JsonFlag @@ -365,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 0de24b2e..8c507c3f 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 3baabacc..73e328dc 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 @@ -49,23 +48,20 @@ 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, 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 } - } else { - createReq.MetastoreId = args[0] } + createReq.MetastoreId = args[0] response, err := a.StorageCredentials.Create(ctx, createReq) if err != nil { @@ -79,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`) } @@ -101,24 +94,15 @@ 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, 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 - } - } 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 { @@ -132,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`) } @@ -155,24 +136,15 @@ 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, 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 - } - } 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 { @@ -186,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`) } @@ -208,23 +177,14 @@ 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, 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 - } - } else { - listReq.MetastoreId = args[0] - } + + listReq.MetastoreId = args[0] response, err := a.StorageCredentials.List(ctx, listReq) if err != nil { @@ -238,7 +198,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.AccountsUpdateStorageCredential var updateJson flags.JsonFlag @@ -263,24 +222,21 @@ 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, 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 } - } 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 9911d6af..54821d4d 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,31 +101,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks account api storage configuration id") - } - 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 { @@ -142,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`) } @@ -165,31 +153,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks account api storage configuration id") - } - 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 981f143e..8a0b40b8 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,31 +115,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks account") - } - 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 { @@ -156,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`) } @@ -179,31 +167,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks account") - } - 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 { @@ -217,7 +199,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListAccountUsersRequest var listJson flags.JsonFlag @@ -255,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 { @@ -275,7 +257,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -301,31 +282,31 @@ 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 { 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) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks account") - } - patchReq.Id = args[0] } + 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) != 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 { @@ -339,7 +320,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.User var updateJson flags.JsonFlag @@ -373,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 d04559eb..80ed3831 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,31 +117,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks vpc endpoint id") - } - 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 { @@ -158,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`) } @@ -185,31 +173,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have databricks vpc endpoint id") - } - 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 36374961..dab35712 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`) } @@ -45,29 +42,20 @@ 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, 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 - } - } 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) @@ -82,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`) } @@ -103,25 +88,16 @@ 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, 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 - } - } 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) @@ -136,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`) } @@ -158,25 +131,16 @@ 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, 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 - } - } 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) @@ -191,7 +155,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq iam.UpdateWorkspaceAssignments var updateJson flags.JsonFlag @@ -215,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 76189dc4..833d3cc0 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,33 +147,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &deleteReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } + 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) @@ -190,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`) } @@ -226,33 +215,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &getReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } + 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) @@ -301,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 @@ -313,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.`) @@ -446,33 +427,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &updateReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } + 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/alerts/alerts.go b/cmd/workspace/alerts/alerts.go index a926e836..91417c63 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,31 +97,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -138,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`) } @@ -161,31 +149,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -229,7 +211,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq sql.EditAlert var updateJson flags.JsonFlag @@ -254,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 0f3ef061..78b8b149 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.`) @@ -109,23 +106,14 @@ 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, 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.Name = args[0] - } + + deleteReq.Name = args[0] err = w.Catalogs.Delete(ctx, deleteReq) if err != nil { @@ -139,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`) } @@ -162,23 +147,14 @@ 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, 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.Name = args[0] - } + + getReq.Name = args[0] response, err := w.Catalogs.Get(ctx, getReq) if err != nil { @@ -226,7 +202,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateCatalog var updateJson flags.JsonFlag @@ -264,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 5dff6aec..1f1d36c1 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,31 +243,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have canonical unique identifier for the cluster policy") - } - 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 { @@ -284,7 +275,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq compute.ListClusterPoliciesRequest var listJson flags.JsonFlag @@ -317,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 841a4016..bc891eef 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,31 +491,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the cluster about which to retrieve information") - } - 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 { @@ -528,7 +523,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq compute.ListClustersRequest var listJson flags.JsonFlag @@ -568,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 { @@ -650,7 +645,6 @@ var listZonesCmd = &cobra.Command{ } // start permanent-delete command - var permanentDeleteReq compute.PermanentDeleteCluster var permanentDeleteJson flags.JsonFlag @@ -678,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 { @@ -716,7 +711,6 @@ var permanentDeleteCmd = &cobra.Command{ } // start pin command - var pinReq compute.PinCluster var pinJson flags.JsonFlag @@ -741,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 { @@ -779,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 @@ -811,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 { @@ -861,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 @@ -892,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 { @@ -973,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 @@ -1008,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 { @@ -1058,7 +1056,6 @@ var startCmd = &cobra.Command{ } // start unpin command - var unpinReq compute.UnpinCluster var unpinJson flags.JsonFlag @@ -1083,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 2bb459d6..146fdba9 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,31 +108,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the name of the connection to be deleted") - } - 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 { @@ -149,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`) } @@ -172,31 +160,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have name of the connection") - } - 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 { @@ -240,7 +222,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateConnection var updateJson flags.JsonFlag @@ -263,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 26c8b299..b18ddff8 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,31 +101,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -142,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`) } @@ -166,31 +154,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -204,7 +186,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq sql.ListDashboardsRequest var listJson flags.JsonFlag @@ -239,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 { @@ -259,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`) } @@ -282,31 +261,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 5ab5b94e..738c0240 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`) } @@ -333,23 +330,14 @@ 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, 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 - } - } else { - getByNameReq.ExperimentName = args[0] - } + + getByNameReq.ExperimentName = args[0] response, err := w.Experiments.GetByName(ctx, getByNameReq) if err != nil { @@ -363,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`) } @@ -384,23 +369,14 @@ 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, 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 - } - } else { - getExperimentReq.ExperimentId = args[0] - } + + getExperimentReq.ExperimentId = args[0] response, err := w.Experiments.GetExperiment(ctx, getExperimentReq) if err != nil { @@ -414,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.`) @@ -440,23 +413,14 @@ 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, 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 - } - } else { - getHistoryReq.MetricKey = args[0] - } + + getHistoryReq.MetricKey = args[0] response, err := w.Experiments.GetHistory(ctx, getHistoryReq) if err != nil { @@ -470,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.`) @@ -498,23 +459,14 @@ 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, 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 - } - } else { - getRunReq.RunId = args[0] - } + + getRunReq.RunId = args[0] response, err := w.Experiments.GetRun(ctx, getRunReq) if err != nil { @@ -528,7 +480,6 @@ var getRunCmd = &cobra.Command{ } // start list-artifacts command - var listArtifactsReq ml.ListArtifactsRequest var listArtifactsJson flags.JsonFlag @@ -564,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 { @@ -584,7 +536,6 @@ var listArtifactsCmd = &cobra.Command{ } // start list-experiments command - var listExperimentsReq ml.ListExperimentsRequest var listExperimentsJson flags.JsonFlag @@ -618,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 { @@ -638,7 +590,6 @@ var listExperimentsCmd = &cobra.Command{ } // start log-batch command - var logBatchReq ml.LogBatch var logBatchJson flags.JsonFlag @@ -709,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 { @@ -729,7 +681,6 @@ var logBatchCmd = &cobra.Command{ } // start log-inputs command - var logInputsReq ml.LogInputs var logInputsJson flags.JsonFlag @@ -763,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 { @@ -783,7 +735,6 @@ var logInputsCmd = &cobra.Command{ } // start log-metric command - var logMetricReq ml.LogMetric var logMetricJson flags.JsonFlag @@ -819,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 { @@ -848,7 +800,6 @@ var logMetricCmd = &cobra.Command{ } // start log-model command - var logModelReq ml.LogModel var logModelJson flags.JsonFlag @@ -882,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 { @@ -902,7 +854,6 @@ var logModelCmd = &cobra.Command{ } // start log-param command - var logParamReq ml.LogParam var logParamJson flags.JsonFlag @@ -938,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 { @@ -960,7 +912,6 @@ var logParamCmd = &cobra.Command{ } // start restore-experiment command - var restoreExperimentReq ml.RestoreExperiment var restoreExperimentJson flags.JsonFlag @@ -995,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 { @@ -1016,7 +968,6 @@ var restoreExperimentCmd = &cobra.Command{ } // start restore-run command - var restoreRunReq ml.RestoreRun var restoreRunJson flags.JsonFlag @@ -1046,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 { @@ -1067,7 +1019,6 @@ var restoreRunCmd = &cobra.Command{ } // start search-experiments command - var searchExperimentsReq ml.SearchExperiments var searchExperimentsJson flags.JsonFlag @@ -1103,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 { @@ -1123,7 +1075,6 @@ var searchExperimentsCmd = &cobra.Command{ } // start search-runs command - var searchRunsReq ml.SearchRuns var searchRunsJson flags.JsonFlag @@ -1162,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 { @@ -1182,7 +1134,6 @@ var searchRunsCmd = &cobra.Command{ } // start set-experiment-tag command - var setExperimentTagReq ml.SetExperimentTag var setExperimentTagJson flags.JsonFlag @@ -1212,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 { @@ -1235,7 +1187,6 @@ var setExperimentTagCmd = &cobra.Command{ } // start set-tag command - var setTagReq ml.SetTag var setTagJson flags.JsonFlag @@ -1269,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 { @@ -1291,7 +1243,6 @@ var setTagCmd = &cobra.Command{ } // start update-experiment command - var updateExperimentReq ml.UpdateExperiment var updateExperimentJson flags.JsonFlag @@ -1323,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 { @@ -1344,7 +1296,6 @@ var updateExperimentCmd = &cobra.Command{ } // start update-run command - var updateRunReq ml.UpdateRun var updateRunJson flags.JsonFlag @@ -1379,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 91696ef4..a739c931 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.`) @@ -115,23 +112,14 @@ 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, 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.Name = args[0] - } + + deleteReq.Name = args[0] err = w.ExternalLocations.Delete(ctx, deleteReq) if err != nil { @@ -145,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`) } @@ -168,23 +153,14 @@ 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, 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.Name = args[0] - } + + getReq.Name = args[0] response, err := w.ExternalLocations.Get(ctx, getReq) if err != nil { @@ -231,7 +207,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateExternalLocation var updateJson flags.JsonFlag @@ -271,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 c90d0807..9ce3f2fa 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,31 +108,25 @@ 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 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 } - } 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) != 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] + 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 { @@ -149,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`) } @@ -178,31 +166,25 @@ 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 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 } - } 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) != 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] + 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 { @@ -216,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`) } @@ -243,24 +222,15 @@ 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, 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 - } - } 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 { @@ -274,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.`) @@ -306,31 +273,25 @@ 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 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 } - } 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) != 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] + 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 c2f1fece..f75ed83e 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,33 +104,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &deleteReq.CredentialId) - if err != nil { - return fmt.Errorf("invalid CREDENTIAL_ID: %s", args[0]) - } + 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) @@ -148,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`) } @@ -171,33 +159,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &getReq.CredentialId) - if err != nil { - return fmt.Errorf("invalid CREDENTIAL_ID: %s", args[0]) - } + 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) @@ -243,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.`) @@ -270,33 +249,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &updateReq.CredentialId) - if err != nil { - return fmt.Errorf("invalid CREDENTIAL_ID: %s", args[0]) - } + 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 ddc0ff73..b63338f6 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,31 +105,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the id of the global init script") - } - 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 { @@ -146,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`) } @@ -169,31 +157,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the id of the global init script") - } - 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 { @@ -240,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.`) @@ -265,25 +244,16 @@ 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, 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 - } - } 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 bd3e2ee2..1cc97387 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.`) @@ -55,27 +52,18 @@ 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, 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 { - _, 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 { @@ -89,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.`) @@ -112,27 +97,18 @@ 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, 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 - } - } 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 { @@ -146,7 +122,6 @@ var getEffectiveCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdatePermissions var updateJson flags.JsonFlag @@ -169,27 +144,24 @@ 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, 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 } - } 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 c00bd9ff..bdadd112 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,31 +108,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks workspace") - } - 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 { @@ -149,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`) } @@ -172,31 +160,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks workspace") - } - 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 { @@ -210,7 +192,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListGroupsRequest var listJson flags.JsonFlag @@ -248,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 { @@ -268,7 +250,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -293,31 +274,31 @@ 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 { 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) != 1 { - return fmt.Errorf("expected to have unique id for a group in the databricks workspace") - } - patchReq.Id = args[0] } + 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) != 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 { @@ -331,7 +312,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.Group var updateJson flags.JsonFlag @@ -363,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 88ce13e2..80c091e2 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,31 +252,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the canonical unique identifier for the instance pool") - } - 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/instance-profiles/instance-profiles.go b/cmd/workspace/instance-profiles/instance-profiles.go index 8b7e957d..ee2d9280 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 e6224d78..94bd110d 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,31 +121,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the id for the corresponding ip access list to modify") - } - 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 { @@ -162,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`) } @@ -185,31 +173,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the id for the corresponding ip access list to modify") - } - 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 { @@ -253,7 +235,6 @@ var listCmd = &cobra.Command{ } // start replace command - var replaceReq settings.ReplaceIpAccessList var replaceJson flags.JsonFlag @@ -289,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 { @@ -310,7 +292,6 @@ var replaceCmd = &cobra.Command{ } // start update command - var updateReq settings.UpdateIpAccessList var updateJson flags.JsonFlag @@ -350,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 802328b4..1dfb065b 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,33 +414,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &exportRunReq.RunId) - if err != nil { - return fmt.Errorf("invalid RUN_ID: %s", args[0]) - } + 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) @@ -457,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`) } @@ -480,33 +469,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &getReq.JobId) - if err != nil { - return fmt.Errorf("invalid JOB_ID: %s", args[0]) - } + 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) @@ -521,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 @@ -533,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.`) @@ -551,33 +532,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &getRunReq.RunId) - if err != nil { - return fmt.Errorf("invalid RUN_ID: %s", args[0]) - } + 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) @@ -592,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`) } @@ -624,33 +596,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &getRunOutputReq.RunId) - if err != nil { - return fmt.Errorf("invalid RUN_ID: %s", args[0]) - } + 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) @@ -665,7 +631,6 @@ var getRunOutputCmd = &cobra.Command{ } // start list command - var listReq jobs.ListJobsRequest var listJson flags.JsonFlag @@ -701,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 { @@ -721,7 +687,6 @@ var listCmd = &cobra.Command{ } // start list-runs command - var listRunsReq jobs.ListRunsRequest var listRunsJson flags.JsonFlag @@ -762,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 { @@ -782,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 @@ -825,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 { @@ -885,7 +852,6 @@ var repairRunCmd = &cobra.Command{ } // start reset command - var resetReq jobs.ResetJob var resetJson flags.JsonFlag @@ -909,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 { @@ -930,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 @@ -969,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 { @@ -1029,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 @@ -1076,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 { @@ -1115,7 +1084,6 @@ var submitCmd = &cobra.Command{ } // start update command - var updateReq jobs.UpdateJob var updateJson flags.JsonFlag @@ -1142,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 16fce733..70b5584a 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`) } @@ -108,23 +105,14 @@ 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, 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 - } - } else { - clusterStatusReq.ClusterId = args[0] - } + + clusterStatusReq.ClusterId = args[0] response, err := w.Libraries.ClusterStatus(ctx, clusterStatusReq) if err != nil { @@ -138,7 +126,6 @@ var clusterStatusCmd = &cobra.Command{ } // start install command - var installReq compute.InstallLibraries var installJson flags.JsonFlag @@ -166,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 { @@ -187,7 +175,6 @@ var installCmd = &cobra.Command{ } // start uninstall command - var uninstallReq compute.UninstallLibraries var uninstallJson flags.JsonFlag @@ -212,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 71e2d122..e16f74ff 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`) } @@ -57,27 +54,18 @@ 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, 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 - } - } 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) @@ -92,7 +80,6 @@ var assignCmd = &cobra.Command{ } // start create command - var createReq catalog.CreateMetastore var createJson flags.JsonFlag @@ -124,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 { @@ -176,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.`) @@ -201,31 +186,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id of the metastore") - } - 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 { @@ -239,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`) } @@ -263,31 +239,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id of the metastore") - } - 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 { @@ -333,7 +303,6 @@ var listCmd = &cobra.Command{ } // start maintenance command - var maintenanceReq catalog.UpdateAutoMaintenance var maintenanceJson flags.JsonFlag @@ -366,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 { @@ -422,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,27 +410,18 @@ 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, 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 - } - } 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 { @@ -477,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.`) @@ -509,31 +464,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id of the metastore") - } - 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 { @@ -547,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.`) @@ -576,33 +522,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &updateAssignmentReq.WorkspaceId) - if err != nil { - return fmt.Errorf("invalid WORKSPACE_ID: %s", args[0]) - } + 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 8088d47d..ce7f4806 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`) } @@ -385,23 +382,14 @@ 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, 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 - } - } else { - deleteCommentReq.Id = args[0] - } + + deleteCommentReq.Id = args[0] err = w.ModelRegistry.DeleteComment(ctx, deleteCommentReq) if err != nil { @@ -415,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`) } @@ -436,23 +421,14 @@ 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, 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 - } - } else { - deleteModelReq.Name = args[0] - } + + deleteModelReq.Name = args[0] err = w.ModelRegistry.DeleteModel(ctx, deleteModelReq) if err != nil { @@ -466,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`) } @@ -487,24 +460,15 @@ 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, 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 - } - } 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 { @@ -518,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`) } @@ -539,24 +500,15 @@ 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, 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 - } - } 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 { @@ -570,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`) } @@ -591,25 +540,16 @@ 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, 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 - } - } 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 { @@ -623,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.`) @@ -646,29 +583,20 @@ 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, 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 - } - } 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 { @@ -682,7 +610,6 @@ var deleteTransitionRequestCmd = &cobra.Command{ } // start delete-webhook command - var deleteWebhookReq ml.DeleteWebhookRequest var deleteWebhookJson flags.JsonFlag @@ -716,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 { @@ -736,7 +664,6 @@ var deleteWebhookCmd = &cobra.Command{ } // start get-latest-versions command - var getLatestVersionsReq ml.GetLatestVersionsRequest var getLatestVersionsJson flags.JsonFlag @@ -768,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 { @@ -789,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`) } @@ -814,23 +739,14 @@ 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, 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 - } - } else { - getModelReq.Name = args[0] - } + + getModelReq.Name = args[0] response, err := w.ModelRegistry.GetModel(ctx, getModelReq) if err != nil { @@ -844,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`) } @@ -865,24 +778,15 @@ 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, 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 - } - } 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 { @@ -896,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`) } @@ -917,24 +818,15 @@ 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, 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 - } - } 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 { @@ -948,7 +840,6 @@ var getModelVersionDownloadUriCmd = &cobra.Command{ } // start list-models command - var listModelsReq ml.ListModelsRequest var listModelsJson flags.JsonFlag @@ -982,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 { @@ -1002,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`) } @@ -1023,24 +912,15 @@ 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, 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 - } - } 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 { @@ -1054,7 +934,6 @@ var listTransitionRequestsCmd = &cobra.Command{ } // start list-webhooks command - var listWebhooksReq ml.ListWebhooksRequest var listWebhooksJson flags.JsonFlag @@ -1090,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 { @@ -1110,7 +990,6 @@ var listWebhooksCmd = &cobra.Command{ } // start reject-transition-request command - var rejectTransitionRequestReq ml.RejectTransitionRequest var rejectTransitionRequestJson flags.JsonFlag @@ -1142,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 { @@ -1168,7 +1048,6 @@ var rejectTransitionRequestCmd = &cobra.Command{ } // start rename-model command - var renameModelReq ml.RenameModelRequest var renameModelJson flags.JsonFlag @@ -1200,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 { @@ -1221,7 +1101,6 @@ var renameModelCmd = &cobra.Command{ } // start search-model-versions command - var searchModelVersionsReq ml.SearchModelVersionsRequest var searchModelVersionsJson flags.JsonFlag @@ -1256,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 { @@ -1276,7 +1156,6 @@ var searchModelVersionsCmd = &cobra.Command{ } // start search-models command - var searchModelsReq ml.SearchModelsRequest var searchModelsJson flags.JsonFlag @@ -1311,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 { @@ -1331,7 +1211,6 @@ var searchModelsCmd = &cobra.Command{ } // start set-model-tag command - var setModelTagReq ml.SetModelTagRequest var setModelTagJson flags.JsonFlag @@ -1361,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 { @@ -1384,7 +1264,6 @@ var setModelTagCmd = &cobra.Command{ } // start set-model-version-tag command - var setModelVersionTagReq ml.SetModelVersionTagRequest var setModelVersionTagJson flags.JsonFlag @@ -1414,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 { @@ -1438,7 +1318,6 @@ var setModelVersionTagCmd = &cobra.Command{ } // start test-registry-webhook command - var testRegistryWebhookReq ml.TestRegistryWebhookRequest var testRegistryWebhookJson flags.JsonFlag @@ -1472,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 { @@ -1493,7 +1373,6 @@ var testRegistryWebhookCmd = &cobra.Command{ } // start transition-stage command - var transitionStageReq ml.TransitionModelVersionStageDatabricks var transitionStageJson flags.JsonFlag @@ -1529,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 { @@ -1559,7 +1439,6 @@ var transitionStageCmd = &cobra.Command{ } // start update-comment command - var updateCommentReq ml.UpdateComment var updateCommentJson flags.JsonFlag @@ -1589,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 { @@ -1611,7 +1491,6 @@ var updateCommentCmd = &cobra.Command{ } // start update-model command - var updateModelReq ml.UpdateModelRequest var updateModelJson flags.JsonFlag @@ -1643,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 { @@ -1664,7 +1544,6 @@ var updateModelCmd = &cobra.Command{ } // start update-model-version command - var updateModelVersionReq ml.UpdateModelVersionRequest var updateModelVersionJson flags.JsonFlag @@ -1696,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 { @@ -1718,7 +1598,6 @@ var updateModelVersionCmd = &cobra.Command{ } // start update-webhook command - var updateWebhookReq ml.UpdateRegistryWebhook var updateWebhookJson flags.JsonFlag @@ -1756,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 f34a7ac7..c9250120 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`) } @@ -43,24 +40,15 @@ 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, 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.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 { @@ -74,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`) } @@ -95,24 +80,15 @@ 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, 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 - } - } 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 { @@ -126,7 +102,6 @@ var getPermissionLevelsCmd = &cobra.Command{ } // start set command - var setReq iam.PermissionsRequest var setJson flags.JsonFlag @@ -150,24 +125,21 @@ 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, 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 { 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 { @@ -181,7 +153,6 @@ var setCmd = &cobra.Command{ } // start update command - var updateReq iam.PermissionsRequest var updateJson flags.JsonFlag @@ -204,24 +175,21 @@ 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, 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 } - } 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 ebf484b6..8d6ffff1 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,31 +126,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -167,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 @@ -179,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`) } @@ -193,31 +182,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -231,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`) } @@ -252,24 +232,15 @@ 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, 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 - } - } 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 { @@ -283,7 +254,6 @@ var getUpdateCmd = &cobra.Command{ } // start list-pipeline-events command - var listPipelineEventsReq pipelines.ListPipelineEventsRequest var listPipelineEventsJson flags.JsonFlag @@ -311,31 +281,31 @@ 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 { 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) != 1 { - return fmt.Errorf("expected to have ") - } - listPipelineEventsReq.PipelineId = args[0] } + 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) != 1 { + return fmt.Errorf("expected to have ") + } + listPipelineEventsReq.PipelineId = args[0] response, err := w.Pipelines.ListPipelineEventsAll(ctx, listPipelineEventsReq) if err != nil { @@ -349,7 +319,6 @@ var listPipelineEventsCmd = &cobra.Command{ } // start list-pipelines command - var listPipelinesReq pipelines.ListPipelinesRequest var listPipelinesJson flags.JsonFlag @@ -384,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 { @@ -404,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.`) @@ -431,31 +398,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the pipeline to return updates for") - } - 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 { @@ -469,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 @@ -481,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`) } @@ -497,31 +456,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -547,7 +500,6 @@ var resetCmd = &cobra.Command{ } // start start-update command - var startUpdateReq pipelines.StartUpdate var startUpdateJson flags.JsonFlag @@ -575,31 +527,31 @@ 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 { 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) != 1 { - return fmt.Errorf("expected to have ") - } - startUpdateReq.PipelineId = args[0] } + 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) != 1 { + return fmt.Errorf("expected to have ") + } + startUpdateReq.PipelineId = args[0] response, err := w.Pipelines.StartUpdate(ctx, startUpdateReq) if err != nil { @@ -613,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 @@ -625,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`) } @@ -641,31 +591,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -691,7 +635,6 @@ var stopCmd = &cobra.Command{ } // start update command - var updateReq pipelines.EditPipeline var updateJson flags.JsonFlag @@ -734,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 d12572df..37b45c8e 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`) } @@ -45,23 +42,14 @@ 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, 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.PolicyFamilyId = args[0] - } + + getReq.PolicyFamilyId = args[0] response, err := w.PolicyFamilies.Get(ctx, getReq) if err != nil { @@ -75,7 +63,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq compute.ListPolicyFamiliesRequest var listJson flags.JsonFlag @@ -104,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 daf153e8..58ed3395 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,31 +102,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have name of the provider") - } - 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 { @@ -143,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`) } @@ -168,31 +156,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have name of the provider") - } - 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 { @@ -206,7 +188,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq sharing.ListProvidersRequest var listJson flags.JsonFlag @@ -241,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 { @@ -261,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`) } @@ -286,31 +265,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have name of the provider in which to list shares") - } - 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 { @@ -324,7 +297,6 @@ var listSharesCmd = &cobra.Command{ } // start update command - var updateReq sharing.UpdateProvider var updateJson flags.JsonFlag @@ -355,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 2db5855a..3f7e8ca3 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,31 +112,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -153,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`) } @@ -177,31 +165,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -215,7 +197,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq sql.ListQueriesRequest var listJson flags.JsonFlag @@ -251,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 { @@ -271,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`) } @@ -295,31 +274,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - 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 { @@ -333,7 +306,6 @@ var restoreCmd = &cobra.Command{ } // start update command - var updateReq sql.QueryEditContent var updateJson flags.JsonFlag @@ -364,31 +336,31 @@ 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 } - } 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) != 1 { - return fmt.Errorf("expected to have ") - } - updateReq.QueryId = args[0] } + 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) != 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/query-history/query-history.go b/cmd/workspace/query-history/query-history.go index 1ed8a488..5b1e86d0 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 f0af854b..33bc54ef 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`) } @@ -41,23 +37,14 @@ 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, 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 - } - } else { - getActivationUrlInfoReq.ActivationUrl = args[0] - } + + getActivationUrlInfoReq.ActivationUrl = args[0] err = w.RecipientActivation.GetActivationUrlInfo(ctx, getActivationUrlInfoReq) if err != nil { @@ -71,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`) } @@ -93,23 +77,14 @@ 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, 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 - } - } 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 98d8fb08..bb8f9b17 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,31 +107,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have name of the recipient") - } - 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 { @@ -148,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`) } @@ -173,31 +161,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have name of the recipient") - } - 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 { @@ -211,7 +193,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq sharing.ListRecipientsRequest var listJson flags.JsonFlag @@ -246,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 { @@ -266,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`) } @@ -288,27 +267,18 @@ 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, 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 - } - } 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 { @@ -322,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`) } @@ -346,31 +313,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the name of the recipient") - } - 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 { @@ -384,7 +345,6 @@ var sharePermissionsCmd = &cobra.Command{ } // start update command - var updateReq sharing.UpdateRecipient var updateJson flags.JsonFlag @@ -415,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 44d9dca4..127a794a 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 7070493a..fdd9556d 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,33 +108,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &deleteReq.RepoId) - if err != nil { - return fmt.Errorf("invalid REPO_ID: %s", args[0]) - } + 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) @@ -152,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`) } @@ -175,33 +163,27 @@ 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 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &getReq.RepoId) - if err != nil { - return fmt.Errorf("invalid REPO_ID: %s", args[0]) - } + 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) @@ -216,7 +198,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq workspace.ListReposRequest var listJson flags.JsonFlag @@ -250,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 { @@ -270,7 +252,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq workspace.UpdateRepo var updateJson flags.JsonFlag @@ -298,33 +279,33 @@ 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 } - } 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") - } - _, err = fmt.Sscan(args[0], &updateReq.RepoId) + } + 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("invalid REPO_ID: %s", args[0]) + 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") + } + _, 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 65737f40..4a6eb33b 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,31 +105,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have full name of the schema") - } - 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 { @@ -146,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`) } @@ -171,31 +159,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have full name of the schema") - } - 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 { @@ -209,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`) } @@ -234,23 +213,14 @@ 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, 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 - } - } else { - listReq.CatalogName = args[0] - } + + listReq.CatalogName = args[0] response, err := w.Schemas.ListAll(ctx, listReq) if err != nil { @@ -264,7 +234,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateSchema var updateJson flags.JsonFlag @@ -296,31 +265,31 @@ 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 } - } 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) != 1 { - return fmt.Errorf("expected to have full name of the schema") - } - updateReq.FullName = args[0] } + 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) != 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 5a8a8d60..fada4d1f 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`) } @@ -285,24 +282,15 @@ 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, 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 - } - } 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 { @@ -316,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`) } @@ -342,23 +327,14 @@ 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, 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 - } - } else { - listAclsReq.Scope = args[0] - } + + listAclsReq.Scope = args[0] response, err := w.Secrets.ListAclsAll(ctx, listAclsReq) if err != nil { @@ -405,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`) } @@ -433,23 +406,14 @@ 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, 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 - } - } else { - listSecretsReq.Scope = args[0] - } + + listSecretsReq.Scope = args[0] response, err := w.Secrets.ListSecretsAll(ctx, listSecretsReq) if err != nil { @@ -463,7 +427,6 @@ var listSecretsCmd = &cobra.Command{ } // start put-acl command - var putAclReq workspace.PutAcl var putAclJson flags.JsonFlag @@ -518,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 71760a55..7dfc390f 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,31 +106,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks workspace") - } - 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 { @@ -147,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`) } @@ -171,31 +159,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks workspace") - } - 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 { @@ -209,7 +191,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListServicePrincipalsRequest var listJson flags.JsonFlag @@ -247,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 { @@ -267,7 +249,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -293,31 +274,31 @@ 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 { 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) != 1 { - return fmt.Errorf("expected to have unique id for a service principal in the databricks workspace") - } - patchReq.Id = args[0] } + 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) != 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 { @@ -331,7 +312,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.ServicePrincipal var updateJson flags.JsonFlag @@ -365,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 eb0df68a..46c830eb 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`) } @@ -57,24 +54,15 @@ 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, 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 - } - } 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 { @@ -88,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 @@ -114,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 { @@ -148,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`) } @@ -167,23 +153,14 @@ 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, 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.Name = args[0] - } + + deleteReq.Name = args[0] err = w.ServingEndpoints.Delete(ctx, deleteReq) if err != nil { @@ -197,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`) } @@ -219,23 +193,14 @@ 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, 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 - } - } else { - exportMetricsReq.Name = args[0] - } + + exportMetricsReq.Name = args[0] err = w.ServingEndpoints.ExportMetrics(ctx, exportMetricsReq) if err != nil { @@ -249,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`) } @@ -270,23 +232,14 @@ 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, 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.Name = args[0] - } + + getReq.Name = args[0] response, err := w.ServingEndpoints.Get(ctx, getReq) if err != nil { @@ -328,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`) } @@ -350,24 +300,15 @@ 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, 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 - } - } 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 { @@ -381,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`) } @@ -400,23 +338,14 @@ 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, 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 - } - } else { - queryReq.Name = args[0] - } + + queryReq.Name = args[0] response, err := w.ServingEndpoints.Query(ctx, queryReq) if err != nil { @@ -430,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 @@ -463,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 c9c6734d..2580b060 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`) } @@ -97,23 +94,14 @@ 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, 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.Name = args[0] - } + + deleteReq.Name = args[0] err = w.Shares.Delete(ctx, deleteReq) if err != nil { @@ -127,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.`) @@ -151,23 +136,14 @@ 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, 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.Name = args[0] - } + + getReq.Name = args[0] response, err := w.Shares.Get(ctx, getReq) if err != nil { @@ -213,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`) } @@ -235,23 +208,14 @@ 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, 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 - } - } else { - sharePermissionsReq.Name = args[0] - } + + sharePermissionsReq.Name = args[0] response, err := w.Shares.SharePermissions(ctx, sharePermissionsReq) if err != nil { @@ -265,7 +229,6 @@ var sharePermissionsCmd = &cobra.Command{ } // start update command - var updateReq sharing.UpdateShare var updateJson flags.JsonFlag @@ -313,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 { @@ -334,7 +298,6 @@ var updateCmd = &cobra.Command{ } // start update-permissions command - var updatePermissionsReq sharing.UpdateSharePermissions var updatePermissionsJson flags.JsonFlag @@ -361,23 +324,20 @@ 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, 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 { 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 ffec9078..bbd7dd58 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,31 +123,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have name of the storage credential") - } - 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 { @@ -164,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`) } @@ -189,31 +177,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have name of the storage credential") - } - 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 { @@ -261,7 +243,6 @@ var listCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateStorageCredential var updateJson flags.JsonFlag @@ -297,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 { @@ -335,7 +317,6 @@ var updateCmd = &cobra.Command{ } // start validate command - var validateReq catalog.ValidateStorageCredential var validateJson flags.JsonFlag @@ -385,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 66a9fe5a..fed5e5e5 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`) } @@ -49,26 +45,17 @@ var disableCmd = &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, 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 - } - } 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) @@ -83,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`) } @@ -105,26 +89,17 @@ var enableCmd = &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, 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 - } - } 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) @@ -139,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`) } @@ -161,23 +133,14 @@ 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, 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 - } - } 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 800e4333..d9588b8f 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`) } @@ -116,27 +113,18 @@ 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, 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.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 17c26359..9ff653b9 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,31 +53,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have full name of the table") - } - 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 { @@ -95,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.`) @@ -124,31 +111,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have full name of the table") - } - 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 { @@ -162,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).`) @@ -192,24 +170,15 @@ 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, 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 - } - } 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 { @@ -223,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).`) @@ -261,31 +227,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have name of parent catalog for tables of interest") - } - 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 749dbdb0..b5cc542c 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,31 +101,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the id of the token to get") - } - 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 { @@ -142,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`) } @@ -165,31 +153,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the id of the token to get") - } - 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 { @@ -203,7 +185,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq settings.ListTokenManagementRequest var listJson flags.JsonFlag @@ -236,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 e0fc5a9b..c121793b 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 0a2ced7b..570a8f79 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,31 +115,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks workspace") - } - 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 { @@ -156,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`) } @@ -179,31 +167,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks workspace") - } - 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 { @@ -217,7 +199,6 @@ var getCmd = &cobra.Command{ } // start list command - var listReq iam.ListUsersRequest var listJson flags.JsonFlag @@ -255,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 { @@ -275,7 +257,6 @@ var listCmd = &cobra.Command{ } // start patch command - var patchReq iam.PartialUpdate var patchJson flags.JsonFlag @@ -301,31 +282,31 @@ 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 { 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) != 1 { - return fmt.Errorf("expected to have unique id for a user in the databricks workspace") - } - patchReq.Id = args[0] } + 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) != 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 { @@ -339,7 +320,6 @@ var patchCmd = &cobra.Command{ } // start update command - var updateReq iam.User var updateJson flags.JsonFlag @@ -373,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 d1400f52..e020700a 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,31 +133,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the three-level (fully qualified) name of the volume") - } - 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 { @@ -174,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`) } @@ -205,24 +193,15 @@ 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, 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 - } - } 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 { @@ -236,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`) } @@ -264,31 +240,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the three-level (fully qualified) name of the volume") - } - 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 { @@ -302,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.`) @@ -336,31 +303,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the three-level (fully qualified) name of the volume") - } - 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 9b2a5c00..a29c4031 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,31 +134,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have required") - } - 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 { @@ -174,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 @@ -216,31 +208,31 @@ 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 { 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) != 1 { - return fmt.Errorf("expected to have required") - } - editReq.Id = args[0] } + 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) != 1 { + return fmt.Errorf("expected to have required") + } + editReq.Id = args[0] wait, err := w.Warehouses.Edit(ctx, editReq) if err != nil { @@ -273,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 @@ -285,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`) } @@ -301,31 +291,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have required") - } - 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 { @@ -370,7 +354,6 @@ var getWorkspaceWarehouseConfigCmd = &cobra.Command{ } // start list command - var listReq sql.ListWarehousesRequest var listJson flags.JsonFlag @@ -402,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 { @@ -422,7 +406,6 @@ var listCmd = &cobra.Command{ } // start set-workspace-warehouse-config command - var setWorkspaceWarehouseConfigReq sql.SetWorkspaceWarehouseConfigRequest var setWorkspaceWarehouseConfigJson flags.JsonFlag @@ -463,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 { @@ -483,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 @@ -495,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`) } @@ -511,31 +493,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have required") - } - 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 { @@ -568,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 @@ -580,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`) } @@ -596,31 +570,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have required") - } - 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 4c05f60b..8780106b 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`) } @@ -47,23 +44,14 @@ 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, 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.Name = args[0] - } + + getReq.Name = args[0] response, err := w.WorkspaceBindings.Get(ctx, getReq) if err != nil { @@ -77,7 +65,6 @@ var getCmd = &cobra.Command{ } // start update command - var updateReq catalog.UpdateWorkspaceBindings var updateJson flags.JsonFlag @@ -102,23 +89,20 @@ 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, 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 } - } 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 0a0a48fd..f2f0bb75 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`) } @@ -41,23 +38,14 @@ 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, 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 - } - } else { - getStatusReq.Keys = args[0] - } + + getStatusReq.Keys = args[0] response, err := w.WorkspaceConf.GetStatus(ctx, getStatusReq) if err != nil { @@ -71,7 +59,6 @@ var getStatusCmd = &cobra.Command{ } // start set-status command - var setStatusReq settings.WorkspaceConf var setStatusJson flags.JsonFlag @@ -102,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 6a51c471..ab9c6aec 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,31 +125,25 @@ 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 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 } - } 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) != 1 { - return fmt.Errorf("expected to have the absolute path of the object or directory") - } - 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 { @@ -166,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`) } @@ -188,23 +176,14 @@ 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, 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 - } - } else { - getStatusReq.Path = args[0] - } + + getStatusReq.Path = args[0] response, err := w.Workspace.GetStatus(ctx, getStatusReq) if err != nil { @@ -218,7 +197,6 @@ var getStatusCmd = &cobra.Command{ } // start import command - var importReq workspace.Import var importJson flags.JsonFlag @@ -256,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 { @@ -277,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.`) @@ -302,23 +278,14 @@ 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, 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 - } - } else { - listReq.Path = args[0] - } + + listReq.Path = args[0] response, err := w.Workspace.ListAll(ctx, listReq) if err != nil { @@ -332,7 +299,6 @@ var listCmd = &cobra.Command{ } // start mkdirs command - var mkdirsReq workspace.Mkdirs var mkdirsJson flags.JsonFlag @@ -360,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 {