diff --git a/internal/cli/config.go b/internal/cli/config.go index 0713bce..d8e1cb1 100644 --- a/internal/cli/config.go +++ b/internal/cli/config.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/spf13/cobra" @@ -36,9 +37,10 @@ func newConfigInitCmd() *cobra.Command { if err := os.WriteFile(path, []byte(config.Example), 0o644); err != nil { return err } - fmt.Fprintf(cmd.OutOrStdout(), "wrote example config to %s\n", path) - fmt.Fprintln(cmd.OutOrStdout(), "edit it, then create the referenced tea config files with `tea logins add`.") - return nil + _, err := fmt.Fprintf(cmd.OutOrStdout(), + "wrote example config to %s\nedit it, then create the referenced tea config files with `tea logins add`.\n", + path) + return err }, } cmd.Flags().BoolVar(&force, "force", false, "overwrite an existing config file") @@ -54,30 +56,32 @@ func newConfigShowCmd() *cobra.Command { if err != nil { return err } - out := cmd.OutOrStdout() - fmt.Fprintf(out, "config: %s\n", configPath) - fmt.Fprintf(out, "gitea_url: %s\n", cfg.GiteaURL) - fmt.Fprintf(out, "state_dir: %s\n", cfg.StateDirOrDefault()) - fmt.Fprintf(out, "poll_interval: %s\n", cfg.PollInterval) - fmt.Fprintf(out, "job_timeout: %s\n", cfg.JobTimeout) - fmt.Fprintf(out, "max_concurrent: %d\n", cfg.MaxConcurrent) - fmt.Fprintf(out, "job_image: %s\n", cfg.JobImage) - fmt.Fprintf(out, "claude_config: %s\n", cfg.ClaudeConfigDir) + lines := []string{ + fmt.Sprintf("config: %s", configPath), + fmt.Sprintf("gitea_url: %s", cfg.GiteaURL), + fmt.Sprintf("state_dir: %s", cfg.StateDirOrDefault()), + fmt.Sprintf("poll_interval: %s", cfg.PollInterval), + fmt.Sprintf("job_timeout: %s", cfg.JobTimeout), + fmt.Sprintf("max_concurrent: %d", cfg.MaxConcurrent), + fmt.Sprintf("job_image: %s", cfg.JobImage), + fmt.Sprintf("claude_config: %s", cfg.ClaudeConfigDir), + } if cfg.AnthropicBaseURL != "" { - fmt.Fprintf(out, "anthropic_base_url: %s\n", cfg.AnthropicBaseURL) + lines = append(lines, "anthropic_base_url: "+cfg.AnthropicBaseURL) } if cfg.AnthropicAPIKey != "" { - fmt.Fprintf(out, "anthropic_api_key: (set)\n") + lines = append(lines, "anthropic_api_key: (set)") } - fmt.Fprintf(out, "repos:\n") + lines = append(lines, "repos:") for _, r := range cfg.Repos { - fmt.Fprintf(out, " - %s\n", r) + lines = append(lines, " - "+r) } - fmt.Fprintf(out, "personalities:\n") + lines = append(lines, "personalities:") for _, p := range cfg.Personalities { - fmt.Fprintf(out, " - %s (role=%s, login=%s)\n", p.Name, p.Role, p.Login) + lines = append(lines, fmt.Sprintf(" - %s (role=%s, login=%s)", p.Name, p.Role, p.Login)) } - return nil + _, err = fmt.Fprintln(cmd.OutOrStdout(), strings.Join(lines, "\n")) + return err }, } } diff --git a/internal/docker/docker.go b/internal/docker/docker.go index 47f8f75..90a5b88 100644 --- a/internal/docker/docker.go +++ b/internal/docker/docker.go @@ -69,7 +69,7 @@ func (r *DockerRunner) Run(ctx context.Context, job Job) (Result, error) { if err != nil { return Result{}, err } - defer os.RemoveAll(jobDir) + defer func() { _ = os.RemoveAll(jobDir) }() if job.Timeout > 0 { var cancel context.CancelFunc @@ -233,7 +233,7 @@ func copyFile(src, dst string) error { if err != nil { return err } - defer in.Close() + defer func() { _ = in.Close() }() if err := os.MkdirAll(filepath.Dir(dst), 0o700); err != nil { return err } @@ -241,11 +241,12 @@ func copyFile(src, dst string) error { if err != nil { return err } - defer out.Close() if _, err := io.Copy(out, in); err != nil { + _ = out.Close() return err } - return nil + // Close explicitly (not deferred) so a flush error surfaces to the caller. + return out.Close() } // copyTree recursively copies a directory tree (regular files, dirs, and diff --git a/internal/gitea/client.go b/internal/gitea/client.go index ceee259..3fb664f 100644 --- a/internal/gitea/client.go +++ b/internal/gitea/client.go @@ -47,7 +47,7 @@ func (c *Client) get(ctx context.Context, path string, query url.Values, out any if err != nil { return fmt.Errorf("GET %s: %w", path, err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) if resp.StatusCode < 200 || resp.StatusCode >= 300 { return fmt.Errorf("GET %s: status %d: %s", path, resp.StatusCode, strings.TrimSpace(string(body))) @@ -194,7 +194,7 @@ func (c *Client) GetPullDiff(ctx context.Context, repo string, index int64) (str if err != nil { return "", err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) if resp.StatusCode < 200 || resp.StatusCode >= 300 { return "", fmt.Errorf("GET pull diff: status %d", resp.StatusCode)