From 91e1da0f52077c5e29d24ebf9fc6007cdc063baa Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Mon, 19 Jun 2023 16:45:56 +0200 Subject: [PATCH] Added more commands --- .codegen/service.go.tmpl | 4 ++-- cmd/account/groups/groups.go | 9 +-------- .../service-principals/service-principals.go | 10 +--------- cmd/account/users/users.go | 12 +---------- cmd/workspace/dashboards/dashboards.go | 6 +----- cmd/workspace/groups/groups.go | 9 +-------- cmd/workspace/pipelines/pipelines.go | 20 +------------------ cmd/workspace/queries/queries.go | 8 +------- .../service-principals/service-principals.go | 10 +--------- cmd/workspace/users/users.go | 12 +---------- 10 files changed, 11 insertions(+), 89 deletions(-) diff --git a/.codegen/service.go.tmpl b/.codegen/service.go.tmpl index bc8d4eb0..d9bfebd4 100644 --- a/.codegen/service.go.tmpl +++ b/.codegen/service.go.tmpl @@ -58,7 +58,7 @@ func init() { {{if .Request}}// TODO: short flags {{.CamelName}}Cmd.Flags().Var(&{{.CamelName}}Json, "json", `either inline JSON string or @path/to/file.json with request body`) {{$method := .}} - {{ if not .OnlyPayload }} + {{ if not .JsonOnly }} {{range .Request.Fields -}} {{- if not .Required -}} {{if .Entity.IsObject }}// TODO: complex arg: {{.Name}} @@ -135,7 +135,7 @@ var {{.CamelName}}Cmd = &cobra.Command{ } {{- end -}} {{$method := .}} - {{- if and .Request.IsAllRequiredFieldsPrimitive (not .OnlyPayload) -}} + {{- if and .Request.IsAllRequiredFieldsPrimitive (not .JsonOnly) -}} {{- range $arg, $field := .Request.RequiredFields}} {{if not $field.Entity.IsString -}} _, err = fmt.Sscan(args[{{$arg}}], &{{$method.CamelName}}Req.{{$field.PascalName}}) diff --git a/cmd/account/groups/groups.go b/cmd/account/groups/groups.go index 58d8d9d1..b2149b84 100755 --- a/cmd/account/groups/groups.go +++ b/cmd/account/groups/groups.go @@ -37,14 +37,6 @@ func init() { // TODO: short flags createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) - createCmd.Flags().StringVar(&createReq.DisplayName, "display-name", createReq.DisplayName, `String that represents a human-readable group name.`) - // TODO: array: entitlements - createCmd.Flags().StringVar(&createReq.ExternalId, "external-id", createReq.ExternalId, ``) - // TODO: array: groups - createCmd.Flags().StringVar(&createReq.Id, "id", createReq.Id, `Databricks group ID.`) - // TODO: array: members - // TODO: array: roles - } var createCmd = &cobra.Command{ @@ -73,6 +65,7 @@ var createCmd = &cobra.Command{ return err } } else { + return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") } response, err := a.Groups.Create(ctx, createReq) diff --git a/cmd/account/service-principals/service-principals.go b/cmd/account/service-principals/service-principals.go index df969b5e..31008f5d 100755 --- a/cmd/account/service-principals/service-principals.go +++ b/cmd/account/service-principals/service-principals.go @@ -36,15 +36,6 @@ func init() { // TODO: short flags createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) - createCmd.Flags().BoolVar(&createReq.Active, "active", createReq.Active, `If this user is active.`) - createCmd.Flags().StringVar(&createReq.ApplicationId, "application-id", createReq.ApplicationId, `UUID relating to the service principal.`) - createCmd.Flags().StringVar(&createReq.DisplayName, "display-name", createReq.DisplayName, `String that represents a concatenation of given and family names.`) - // TODO: array: entitlements - createCmd.Flags().StringVar(&createReq.ExternalId, "external-id", createReq.ExternalId, ``) - // TODO: array: groups - createCmd.Flags().StringVar(&createReq.Id, "id", createReq.Id, `Databricks service principal ID.`) - // TODO: array: roles - } var createCmd = &cobra.Command{ @@ -72,6 +63,7 @@ var createCmd = &cobra.Command{ return err } } else { + return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") } response, err := a.ServicePrincipals.Create(ctx, createReq) diff --git a/cmd/account/users/users.go b/cmd/account/users/users.go index 981f143e..d4efe50d 100755 --- a/cmd/account/users/users.go +++ b/cmd/account/users/users.go @@ -41,17 +41,6 @@ func init() { // TODO: short flags createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) - createCmd.Flags().BoolVar(&createReq.Active, "active", createReq.Active, `If this user is active.`) - createCmd.Flags().StringVar(&createReq.DisplayName, "display-name", createReq.DisplayName, `String that represents a concatenation of given and family names.`) - // TODO: array: emails - // TODO: array: entitlements - createCmd.Flags().StringVar(&createReq.ExternalId, "external-id", createReq.ExternalId, ``) - // TODO: array: groups - createCmd.Flags().StringVar(&createReq.Id, "id", createReq.Id, `Databricks user ID.`) - // TODO: complex arg: name - // TODO: array: roles - createCmd.Flags().StringVar(&createReq.UserName, "user-name", createReq.UserName, `Email address of the Databricks user.`) - } var createCmd = &cobra.Command{ @@ -80,6 +69,7 @@ var createCmd = &cobra.Command{ return err } } else { + return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") } response, err := a.Users.Create(ctx, createReq) diff --git a/cmd/workspace/dashboards/dashboards.go b/cmd/workspace/dashboards/dashboards.go index 26c8b299..a7c6cf23 100755 --- a/cmd/workspace/dashboards/dashboards.go +++ b/cmd/workspace/dashboards/dashboards.go @@ -36,11 +36,6 @@ func init() { // TODO: short flags createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) - createCmd.Flags().BoolVar(&createReq.IsFavorite, "is-favorite", createReq.IsFavorite, `Indicates whether this query object should appear in the current user's favorites list.`) - createCmd.Flags().StringVar(&createReq.Name, "name", createReq.Name, `The title of this dashboard that appears in list views and at the top of the dashboard page.`) - createCmd.Flags().StringVar(&createReq.Parent, "parent", createReq.Parent, `The identifier of the workspace folder containing the dashboard.`) - // TODO: array: tags - } var createCmd = &cobra.Command{ @@ -66,6 +61,7 @@ var createCmd = &cobra.Command{ return err } } else { + return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") } response, err := w.Dashboards.Create(ctx, createReq) diff --git a/cmd/workspace/groups/groups.go b/cmd/workspace/groups/groups.go index d8c76b8a..d738de54 100755 --- a/cmd/workspace/groups/groups.go +++ b/cmd/workspace/groups/groups.go @@ -37,14 +37,6 @@ func init() { // TODO: short flags createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) - createCmd.Flags().StringVar(&createReq.DisplayName, "display-name", createReq.DisplayName, `String that represents a human-readable group name.`) - // TODO: array: entitlements - createCmd.Flags().StringVar(&createReq.ExternalId, "external-id", createReq.ExternalId, ``) - // TODO: array: groups - createCmd.Flags().StringVar(&createReq.Id, "id", createReq.Id, `Databricks group ID.`) - // TODO: array: members - // TODO: array: roles - } var createCmd = &cobra.Command{ @@ -73,6 +65,7 @@ var createCmd = &cobra.Command{ return err } } else { + return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") } response, err := w.Groups.Create(ctx, createReq) diff --git a/cmd/workspace/pipelines/pipelines.go b/cmd/workspace/pipelines/pipelines.go index ebf484b6..a4e53da9 100755 --- a/cmd/workspace/pipelines/pipelines.go +++ b/cmd/workspace/pipelines/pipelines.go @@ -45,25 +45,6 @@ func init() { // TODO: short flags createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) - createCmd.Flags().BoolVar(&createReq.AllowDuplicateNames, "allow-duplicate-names", createReq.AllowDuplicateNames, `If false, deployment will fail if name conflicts with that of another pipeline.`) - createCmd.Flags().StringVar(&createReq.Catalog, "catalog", createReq.Catalog, `A catalog in Unity Catalog to publish data from this pipeline to.`) - createCmd.Flags().StringVar(&createReq.Channel, "channel", createReq.Channel, `DLT Release Channel that specifies which version to use.`) - // TODO: array: clusters - // TODO: map via StringToStringVar: configuration - createCmd.Flags().BoolVar(&createReq.Continuous, "continuous", createReq.Continuous, `Whether the pipeline is continuous or triggered.`) - createCmd.Flags().BoolVar(&createReq.Development, "development", createReq.Development, `Whether the pipeline is in Development mode.`) - createCmd.Flags().BoolVar(&createReq.DryRun, "dry-run", createReq.DryRun, ``) - createCmd.Flags().StringVar(&createReq.Edition, "edition", createReq.Edition, `Pipeline product edition.`) - // TODO: complex arg: filters - createCmd.Flags().StringVar(&createReq.Id, "id", createReq.Id, `Unique identifier for this pipeline.`) - // TODO: array: libraries - createCmd.Flags().StringVar(&createReq.Name, "name", createReq.Name, `Friendly identifier for this pipeline.`) - createCmd.Flags().BoolVar(&createReq.Photon, "photon", createReq.Photon, `Whether Photon is enabled for this pipeline.`) - createCmd.Flags().BoolVar(&createReq.Serverless, "serverless", createReq.Serverless, `Whether serverless compute is enabled for this pipeline.`) - createCmd.Flags().StringVar(&createReq.Storage, "storage", createReq.Storage, `DBFS root directory for storing checkpoints and tables.`) - createCmd.Flags().StringVar(&createReq.Target, "target", createReq.Target, `Target schema (database) to add tables in this pipeline to.`) - // TODO: complex arg: trigger - } var createCmd = &cobra.Command{ @@ -92,6 +73,7 @@ var createCmd = &cobra.Command{ return err } } else { + return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") } response, err := w.Pipelines.Create(ctx, createReq) diff --git a/cmd/workspace/queries/queries.go b/cmd/workspace/queries/queries.go index 2db5855a..7d815dbd 100755 --- a/cmd/workspace/queries/queries.go +++ b/cmd/workspace/queries/queries.go @@ -34,13 +34,6 @@ func init() { // TODO: short flags createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) - createCmd.Flags().StringVar(&createReq.DataSourceId, "data-source-id", createReq.DataSourceId, `The ID of the data source / SQL warehouse where this query will run.`) - createCmd.Flags().StringVar(&createReq.Description, "description", createReq.Description, `General description that can convey additional information about this query such as usage notes.`) - createCmd.Flags().StringVar(&createReq.Name, "name", createReq.Name, `The name or title of this query to display in list views.`) - // TODO: any: options - createCmd.Flags().StringVar(&createReq.Parent, "parent", createReq.Parent, `The identifier of the workspace folder containing the query.`) - createCmd.Flags().StringVar(&createReq.Query, "query", createReq.Query, `The text of the query.`) - } var createCmd = &cobra.Command{ @@ -76,6 +69,7 @@ var createCmd = &cobra.Command{ return err } } else { + return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") } response, err := w.Queries.Create(ctx, createReq) diff --git a/cmd/workspace/service-principals/service-principals.go b/cmd/workspace/service-principals/service-principals.go index 71760a55..0e7d3255 100755 --- a/cmd/workspace/service-principals/service-principals.go +++ b/cmd/workspace/service-principals/service-principals.go @@ -36,15 +36,6 @@ func init() { // TODO: short flags createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) - createCmd.Flags().BoolVar(&createReq.Active, "active", createReq.Active, `If this user is active.`) - createCmd.Flags().StringVar(&createReq.ApplicationId, "application-id", createReq.ApplicationId, `UUID relating to the service principal.`) - createCmd.Flags().StringVar(&createReq.DisplayName, "display-name", createReq.DisplayName, `String that represents a concatenation of given and family names.`) - // TODO: array: entitlements - createCmd.Flags().StringVar(&createReq.ExternalId, "external-id", createReq.ExternalId, ``) - // TODO: array: groups - createCmd.Flags().StringVar(&createReq.Id, "id", createReq.Id, `Databricks service principal ID.`) - // TODO: array: roles - } var createCmd = &cobra.Command{ @@ -72,6 +63,7 @@ var createCmd = &cobra.Command{ return err } } else { + return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") } response, err := w.ServicePrincipals.Create(ctx, createReq) diff --git a/cmd/workspace/users/users.go b/cmd/workspace/users/users.go index 0a2ced7b..359a4001 100755 --- a/cmd/workspace/users/users.go +++ b/cmd/workspace/users/users.go @@ -41,17 +41,6 @@ func init() { // TODO: short flags createCmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`) - createCmd.Flags().BoolVar(&createReq.Active, "active", createReq.Active, `If this user is active.`) - createCmd.Flags().StringVar(&createReq.DisplayName, "display-name", createReq.DisplayName, `String that represents a concatenation of given and family names.`) - // TODO: array: emails - // TODO: array: entitlements - createCmd.Flags().StringVar(&createReq.ExternalId, "external-id", createReq.ExternalId, ``) - // TODO: array: groups - createCmd.Flags().StringVar(&createReq.Id, "id", createReq.Id, `Databricks user ID.`) - // TODO: complex arg: name - // TODO: array: roles - createCmd.Flags().StringVar(&createReq.UserName, "user-name", createReq.UserName, `Email address of the Databricks user.`) - } var createCmd = &cobra.Command{ @@ -80,6 +69,7 @@ var createCmd = &cobra.Command{ return err } } else { + return fmt.Errorf("please provide command input in JSON format by specifying the --json flag") } response, err := w.Users.Create(ctx, createReq)