This commit is contained in:
Denis Bilenko 2024-12-09 13:12:03 +01:00
parent d075b6c22e
commit 583f6f2ac1
12 changed files with 35 additions and 55 deletions

View File

@ -32,7 +32,8 @@ func (m *initializeURLs) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn
} }
orgId := strconv.FormatInt(workspaceId, 10) orgId := strconv.FormatInt(workspaceId, 10)
host := b.WorkspaceClient().Config.CanonicalHostName() host := b.WorkspaceClient().Config.CanonicalHostName()
if err := initializeForWorkspace(b, orgId, host); err != nil { err = initializeForWorkspace(b, orgId, host)
if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
return nil return nil

View File

@ -36,10 +36,7 @@ func (m *resolveResourceReferences) Apply(ctx context.Context, b *bundle.Bundle)
return fmt.Errorf("failed to resolve %s, err: %w", v.Lookup, err) return fmt.Errorf("failed to resolve %s, err: %w", v.Lookup, err)
} }
if err := v.Set(id); err != nil { return v.Set(id)
return err
}
return nil
}) })
} }

View File

@ -171,12 +171,14 @@ func RenderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics,
if err != nil { if err != nil {
return fmt.Errorf("failed to render summary: %w", err) return fmt.Errorf("failed to render summary: %w", err)
} }
if _, err := io.WriteString(out, "\n"); err != nil { _, err = io.WriteString(out, "\n")
if err != nil {
return err return err
} }
} }
trailer := buildTrailer(diags) trailer := buildTrailer(diags)
if _, err := io.WriteString(out, trailer); err != nil { _, err = io.WriteString(out, trailer)
if err != nil {
return err return err
} }
} }

View File

@ -141,7 +141,8 @@ func render(ctx context.Context, cmd *cobra.Command, status *authStatus, templat
if err != nil { if err != nil {
return err return err
} }
if _, err := cmd.OutOrStdout().Write(buf); err != nil { _, err = cmd.OutOrStdout().Write(buf)
if err != nil {
return err return err
} }
default: default:

View File

@ -60,19 +60,13 @@ For more information about filesystem mirrors, see the Terraform documentation:
} }
switch root.OutputType(cmd) { switch root.OutputType(cmd) {
case flags.OutputText: case flags.OutputText:
err := cmdio.Render(cmd.Context(), dependencies.Terraform) _ = cmdio.Render(cmd.Context(), dependencies.Terraform)
if err != nil {
return err
}
case flags.OutputJSON: case flags.OutputJSON:
buf, err := json.MarshalIndent(dependencies, "", " ") buf, err := json.MarshalIndent(dependencies, "", " ")
if err != nil { if err != nil {
return err return err
} }
_, err = cmd.OutOrStdout().Write(buf) _, _ = cmd.OutOrStdout().Write(buf)
if err != nil {
return err
}
default: default:
return fmt.Errorf("unknown output type %s", root.OutputType(cmd)) return fmt.Errorf("unknown output type %s", root.OutputType(cmd))
} }

View File

@ -159,7 +159,8 @@ task or a Python wheel task, the second example applies.
if err != nil { if err != nil {
return err return err
} }
if _, err := cmd.OutOrStdout().Write([]byte(resultString)); err != nil { _, err = cmd.OutOrStdout().Write([]byte(resultString))
if err != nil {
return err return err
} }
case flags.OutputJSON: case flags.OutputJSON:
@ -167,7 +168,8 @@ task or a Python wheel task, the second example applies.
if err != nil { if err != nil {
return err return err
} }
if _, err := cmd.OutOrStdout().Write(b); err != nil { _, err = cmd.OutOrStdout().Write(b)
if err != nil {
return err return err
} }
default: default:

View File

@ -37,9 +37,7 @@ func (e ErrNoAccountProfiles) Error() string {
func initProfileFlag(cmd *cobra.Command) { func initProfileFlag(cmd *cobra.Command) {
cmd.PersistentFlags().StringP("profile", "p", "", "~/.databrickscfg profile") cmd.PersistentFlags().StringP("profile", "p", "", "~/.databrickscfg profile")
if err := cmd.RegisterFlagCompletionFunc("profile", profile.ProfileCompletion); err != nil { _ = cmd.RegisterFlagCompletionFunc("profile", profile.ProfileCompletion)
panic(err)
}
} }
func profileFlagValue(cmd *cobra.Command) (string, bool) { func profileFlagValue(cmd *cobra.Command) (string, bool) {

View File

@ -146,19 +146,13 @@ func targetCompletion(cmd *cobra.Command, args []string, toComplete string) ([]s
func initTargetFlag(cmd *cobra.Command) { func initTargetFlag(cmd *cobra.Command) {
// To operate in the context of a bundle, all commands must take an "target" parameter. // To operate in the context of a bundle, all commands must take an "target" parameter.
cmd.PersistentFlags().StringP("target", "t", "", "bundle target to use (if applicable)") cmd.PersistentFlags().StringP("target", "t", "", "bundle target to use (if applicable)")
if err := cmd.RegisterFlagCompletionFunc("target", targetCompletion); err != nil { _ = cmd.RegisterFlagCompletionFunc("target", targetCompletion)
panic(err)
}
} }
// DEPRECATED flag // DEPRECATED flag
func initEnvironmentFlag(cmd *cobra.Command) { func initEnvironmentFlag(cmd *cobra.Command) {
// To operate in the context of a bundle, all commands must take an "environment" parameter. // To operate in the context of a bundle, all commands must take an "environment" parameter.
cmd.PersistentFlags().StringP("environment", "e", "", "bundle target to use (if applicable)") cmd.PersistentFlags().StringP("environment", "e", "", "bundle target to use (if applicable)")
if err := cmd.PersistentFlags().MarkDeprecated("environment", "use --target flag instead"); err != nil { _ = cmd.PersistentFlags().MarkDeprecated("environment", "use --target flag instead")
panic(err) _ = cmd.RegisterFlagCompletionFunc("environment", targetCompletion)
}
if err := cmd.RegisterFlagCompletionFunc("environment", targetCompletion); err != nil {
panic(err)
}
} }

View File

@ -45,8 +45,9 @@ func (f *logFlags) makeLogHandler(opts slog.HandlerOptions) (slog.Handler, error
func (f *logFlags) initializeContext(ctx context.Context) (context.Context, error) { func (f *logFlags) initializeContext(ctx context.Context) (context.Context, error) {
if f.debug { if f.debug {
if err := f.level.Set("debug"); err != nil { err := f.level.Set("debug")
panic(err) if err != nil {
return nil, err
} }
} }

View File

@ -59,16 +59,12 @@ func initProgressLoggerFlag(cmd *cobra.Command, logFlags *logFlags) *progressLog
// Configure defaults from environment, if applicable. // Configure defaults from environment, if applicable.
// If the provided value is invalid it is ignored. // If the provided value is invalid it is ignored.
if v, ok := env.Lookup(cmd.Context(), envProgressFormat); ok { if v, ok := env.Lookup(cmd.Context(), envProgressFormat); ok {
if err := f.ProgressLogFormat.Set(v); err != nil { _ = f.ProgressLogFormat.Set(v)
panic(err)
}
} }
flags := cmd.PersistentFlags() flags := cmd.PersistentFlags()
flags.Var(&f.ProgressLogFormat, "progress-format", "format for progress logs (append, inplace, json)") flags.Var(&f.ProgressLogFormat, "progress-format", "format for progress logs (append, inplace, json)")
if err := flags.MarkHidden("progress-format"); err != nil { _ = flags.MarkHidden("progress-format")
panic(err)
}
_ = cmd.RegisterFlagCompletionFunc("progress-format", f.ProgressLogFormat.Complete) _ = cmd.RegisterFlagCompletionFunc("progress-format", f.ProgressLogFormat.Complete)
return &f return &f
} }

View File

@ -148,17 +148,20 @@ func (s *processStub) run(cmd *exec.Cmd) error {
if !re.MatchString(norm) { if !re.MatchString(norm) {
continue continue
} }
err := resp.err
if resp.stdout != "" { if resp.stdout != "" {
if _, err := cmd.Stdout.Write([]byte(resp.stdout)); err != nil { _, err1 := cmd.Stdout.Write([]byte(resp.stdout))
return err if err == nil {
err = err1
} }
} }
if resp.stderr != "" { if resp.stderr != "" {
if _, err := cmd.Stderr.Write([]byte(resp.stderr)); err != nil { _, err1 := cmd.Stderr.Write([]byte(resp.stderr))
return err if err == nil {
err = err1
} }
} }
return resp.err return err
} }
if s.callback != nil { if s.callback != nil {
return s.callback(cmd) return s.callback(cmd)

View File

@ -43,18 +43,9 @@ func TextOutput(ctx context.Context, ch <-chan Event, w io.Writer) {
// Log only if something actually happened. // Log only if something actually happened.
// Sync events produce an empty string if nothing happened. // Sync events produce an empty string if nothing happened.
if str := e.String(); str != "" { if str := e.String(); str != "" {
_, err := bw.WriteString(str) _, _ = bw.WriteString(str)
if err != nil { _, _ = bw.WriteString("\n")
panic(err) _ = bw.Flush()
}
_, err = bw.WriteString("\n")
if err != nil {
panic(err)
}
err = bw.Flush()
if err != nil {
panic(err)
}
} }
} }
} }