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)
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 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)
}
if err := v.Set(id); err != nil {
return err
}
return nil
return v.Set(id)
})
}

View File

@ -171,12 +171,14 @@ func RenderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics,
if err != nil {
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
}
}
trailer := buildTrailer(diags)
if _, err := io.WriteString(out, trailer); err != nil {
_, err = io.WriteString(out, trailer)
if err != nil {
return err
}
}

View File

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

View File

@ -60,19 +60,13 @@ For more information about filesystem mirrors, see the Terraform documentation:
}
switch root.OutputType(cmd) {
case flags.OutputText:
err := cmdio.Render(cmd.Context(), dependencies.Terraform)
if err != nil {
return err
}
_ = cmdio.Render(cmd.Context(), dependencies.Terraform)
case flags.OutputJSON:
buf, err := json.MarshalIndent(dependencies, "", " ")
if err != nil {
return err
}
_, err = cmd.OutOrStdout().Write(buf)
if err != nil {
return err
}
_, _ = cmd.OutOrStdout().Write(buf)
default:
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 {
return err
}
if _, err := cmd.OutOrStdout().Write([]byte(resultString)); err != nil {
_, err = cmd.OutOrStdout().Write([]byte(resultString))
if err != nil {
return err
}
case flags.OutputJSON:
@ -167,7 +168,8 @@ task or a Python wheel task, the second example applies.
if err != nil {
return err
}
if _, err := cmd.OutOrStdout().Write(b); err != nil {
_, err = cmd.OutOrStdout().Write(b)
if err != nil {
return err
}
default:

View File

@ -37,9 +37,7 @@ func (e ErrNoAccountProfiles) Error() string {
func initProfileFlag(cmd *cobra.Command) {
cmd.PersistentFlags().StringP("profile", "p", "", "~/.databrickscfg profile")
if err := cmd.RegisterFlagCompletionFunc("profile", profile.ProfileCompletion); err != nil {
panic(err)
}
_ = cmd.RegisterFlagCompletionFunc("profile", profile.ProfileCompletion)
}
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) {
// 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)")
if err := cmd.RegisterFlagCompletionFunc("target", targetCompletion); err != nil {
panic(err)
}
_ = cmd.RegisterFlagCompletionFunc("target", targetCompletion)
}
// DEPRECATED flag
func initEnvironmentFlag(cmd *cobra.Command) {
// 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)")
if err := cmd.PersistentFlags().MarkDeprecated("environment", "use --target flag instead"); err != nil {
panic(err)
}
if err := cmd.RegisterFlagCompletionFunc("environment", targetCompletion); err != nil {
panic(err)
}
_ = cmd.PersistentFlags().MarkDeprecated("environment", "use --target flag instead")
_ = cmd.RegisterFlagCompletionFunc("environment", targetCompletion)
}

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) {
if f.debug {
if err := f.level.Set("debug"); err != nil {
panic(err)
err := f.level.Set("debug")
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.
// If the provided value is invalid it is ignored.
if v, ok := env.Lookup(cmd.Context(), envProgressFormat); ok {
if err := f.ProgressLogFormat.Set(v); err != nil {
panic(err)
}
_ = f.ProgressLogFormat.Set(v)
}
flags := cmd.PersistentFlags()
flags.Var(&f.ProgressLogFormat, "progress-format", "format for progress logs (append, inplace, json)")
if err := flags.MarkHidden("progress-format"); err != nil {
panic(err)
}
_ = flags.MarkHidden("progress-format")
_ = cmd.RegisterFlagCompletionFunc("progress-format", f.ProgressLogFormat.Complete)
return &f
}

View File

@ -148,17 +148,20 @@ func (s *processStub) run(cmd *exec.Cmd) error {
if !re.MatchString(norm) {
continue
}
err := resp.err
if resp.stdout != "" {
if _, err := cmd.Stdout.Write([]byte(resp.stdout)); err != nil {
return err
_, err1 := cmd.Stdout.Write([]byte(resp.stdout))
if err == nil {
err = err1
}
}
if resp.stderr != "" {
if _, err := cmd.Stderr.Write([]byte(resp.stderr)); err != nil {
return err
_, err1 := cmd.Stderr.Write([]byte(resp.stderr))
if err == nil {
err = err1
}
}
return resp.err
return err
}
if s.callback != nil {
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.
// Sync events produce an empty string if nothing happened.
if str := e.String(); str != "" {
_, err := bw.WriteString(str)
if err != nil {
panic(err)
}
_, err = bw.WriteString("\n")
if err != nil {
panic(err)
}
err = bw.Flush()
if err != nil {
panic(err)
}
_, _ = bw.WriteString(str)
_, _ = bw.WriteString("\n")
_ = bw.Flush()
}
}
}