mirror of https://github.com/databricks/cli.git
fix overrides
This commit is contained in:
parent
1280428f25
commit
75948368a3
|
@ -185,10 +185,16 @@ func newUpdate() *cobra.Command {
|
|||
a := root.AccountClient(ctx)
|
||||
|
||||
if cmd.Flags().Changed("json") {
|
||||
err = updateJson.Unmarshal(&updateReq)
|
||||
diags := updateJson.Unmarshal(&updateReq)
|
||||
if diags.HasError() {
|
||||
return diags.Error()
|
||||
}
|
||||
if len(diags) > 0 {
|
||||
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
|
||||
}
|
||||
|
|
|
@ -187,10 +187,16 @@ func newUpdate() *cobra.Command {
|
|||
w := root.WorkspaceClient(ctx)
|
||||
|
||||
if cmd.Flags().Changed("json") {
|
||||
err = updateJson.Unmarshal(&updateReq)
|
||||
diags := updateJson.Unmarshal(&updateReq)
|
||||
if diags.HasError() {
|
||||
return diags.Error()
|
||||
}
|
||||
if len(diags) > 0 {
|
||||
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
|
||||
}
|
||||
|
|
|
@ -34,10 +34,18 @@ func createOverride(createCmd *cobra.Command, createReq *workspace.CreateRepoReq
|
|||
createJson := createCmd.Flag("json").Value.(*flags.JsonFlag)
|
||||
createCmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
|
||||
ctx := cmd.Context()
|
||||
var diags diag.Diagnostics
|
||||
w := root.WorkspaceClient(ctx)
|
||||
if cmd.Flags().Changed("json") {
|
||||
diags = createJson.Unmarshal(createReq)
|
||||
diags := createJson.Unmarshal(createReq)
|
||||
if diags.HasError() {
|
||||
return diags.Error()
|
||||
}
|
||||
if len(diags) > 0 {
|
||||
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
createReq.Url = args[0]
|
||||
if len(args) > 1 {
|
||||
|
@ -54,7 +62,7 @@ func createOverride(createCmd *cobra.Command, createReq *workspace.CreateRepoReq
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cmdio.RenderWithDiagnostics(ctx, response, diags)
|
||||
return cmdio.Render(ctx, response)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,6 +112,15 @@ func updateOverride(updateCmd *cobra.Command, updateReq *workspace.UpdateRepoReq
|
|||
w := root.WorkspaceClient(ctx)
|
||||
if cmd.Flags().Changed("json") {
|
||||
diags = updateJson.Unmarshal(&updateReq)
|
||||
if diags.HasError() {
|
||||
return diags.Error()
|
||||
}
|
||||
if len(diags) > 0 {
|
||||
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
updateReq.RepoId, err = repoArgumentToRepoID(ctx, w, args)
|
||||
if err != nil {
|
||||
|
@ -115,7 +132,7 @@ func updateOverride(updateCmd *cobra.Command, updateReq *workspace.UpdateRepoReq
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return diags.Error()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,6 +75,12 @@ func newPutSecret() *cobra.Command {
|
|||
if diags.HasError() {
|
||||
return diags.Error()
|
||||
}
|
||||
if len(diags) > 0 {
|
||||
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
putSecretReq.Scope = args[0]
|
||||
putSecretReq.Key = args[1]
|
||||
|
|
|
@ -868,11 +868,17 @@ func newPutAiGateway() *cobra.Command {
|
|||
w := root.WorkspaceClient(ctx)
|
||||
|
||||
if cmd.Flags().Changed("json") {
|
||||
err = putAiGatewayJson.Unmarshal(&putAiGatewayReq)
|
||||
diags := putAiGatewayJson.Unmarshal(&putAiGatewayReq)
|
||||
if diags.HasError() {
|
||||
return diags.Error()
|
||||
}
|
||||
if len(diags) > 0 {
|
||||
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
putAiGatewayReq.Name = args[0]
|
||||
|
||||
response, err := w.ServingEndpoints.PutAiGateway(ctx, putAiGatewayReq)
|
||||
|
|
|
@ -94,11 +94,17 @@ func newGenerateTemporaryTableCredentials() *cobra.Command {
|
|||
w := root.WorkspaceClient(ctx)
|
||||
|
||||
if cmd.Flags().Changed("json") {
|
||||
err = generateTemporaryTableCredentialsJson.Unmarshal(&generateTemporaryTableCredentialsReq)
|
||||
diags := generateTemporaryTableCredentialsJson.Unmarshal(&generateTemporaryTableCredentialsReq)
|
||||
if diags.HasError() {
|
||||
return diags.Error()
|
||||
}
|
||||
if len(diags) > 0 {
|
||||
err := cmdio.RenderDiagnosticsToErrorOut(ctx, diags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response, err := w.TemporaryTableCredentials.GenerateTemporaryTableCredentials(ctx, generateTemporaryTableCredentialsReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -443,6 +443,20 @@ const warningTemplate = `{{ "Warning" | yellow }}: {{ .Summary }}
|
|||
|
||||
`
|
||||
|
||||
const recommendationTemplate = `{{ "Recommendation" | blue }}: {{ .Summary }}
|
||||
{{- range $index, $element := .Paths }}
|
||||
{{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.String | green }}
|
||||
{{- end }}
|
||||
{{- range $index, $element := .Locations }}
|
||||
{{ if eq $index 0 }}in {{else}} {{ end}}{{ $element.String | cyan }}
|
||||
{{- end }}
|
||||
{{- if .Detail }}
|
||||
|
||||
{{ .Detail }}
|
||||
{{- end }}
|
||||
|
||||
`
|
||||
|
||||
func RenderDiagnosticsToErrorOut(ctx context.Context, diags diag.Diagnostics) error {
|
||||
c := fromContext(ctx)
|
||||
return RenderDiagnostics(c.err, diags)
|
||||
|
@ -451,6 +465,7 @@ func RenderDiagnosticsToErrorOut(ctx context.Context, diags diag.Diagnostics) er
|
|||
func RenderDiagnostics(out io.Writer, diags diag.Diagnostics) error {
|
||||
errorT := template.Must(template.New("error").Funcs(renderFuncMap).Parse(errorTemplate))
|
||||
warningT := template.Must(template.New("warning").Funcs(renderFuncMap).Parse(warningTemplate))
|
||||
recommendationT := template.Must(template.New("recommendation").Funcs(renderFuncMap).Parse(recommendationTemplate))
|
||||
|
||||
// Print errors and warnings.
|
||||
for _, d := range diags {
|
||||
|
@ -460,6 +475,8 @@ func RenderDiagnostics(out io.Writer, diags diag.Diagnostics) error {
|
|||
t = errorT
|
||||
case diag.Warning:
|
||||
t = warningT
|
||||
case diag.Recommendation:
|
||||
t = recommendationT
|
||||
}
|
||||
|
||||
// Render the diagnostic with the appropriate template.
|
||||
|
|
Loading…
Reference in New Issue