Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: use cmd.Context inside custom command #4496

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/golangci-lint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {
info := createBuildInfo()

if err := commands.Execute(info); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "failed executing command with error %v\n", err)
_, _ = fmt.Fprintf(os.Stderr, "Failed executing command with error: %v\n", err)
os.Exit(exitcodes.Failure)
}
}
Expand Down
9 changes: 3 additions & 6 deletions pkg/commands/custom.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package commands

import (
"context"
"fmt"
"log"
"os"
Expand All @@ -27,7 +26,7 @@ func newCustomCommand(logger logutils.Log) *customCommand {

customCmd := &cobra.Command{
Use: "custom",
Short: "Build a version of golangci-lint with custom linters.",
Short: "Build a version of golangci-lint with custom linters",
Args: cobra.NoArgs,
PreRunE: c.preRunE,
RunE: c.runE,
Expand All @@ -54,9 +53,7 @@ func (c *customCommand) preRunE(_ *cobra.Command, _ []string) error {
return nil
}

func (c *customCommand) runE(_ *cobra.Command, _ []string) error {
ctx := context.Background()

func (c *customCommand) runE(cmd *cobra.Command, _ []string) error {
tmp, err := os.MkdirTemp(os.TempDir(), "custom-gcl")
if err != nil {
return fmt.Errorf("create temporary directory: %w", err)
Expand All @@ -72,7 +69,7 @@ func (c *customCommand) runE(_ *cobra.Command, _ []string) error {
_ = os.RemoveAll(tmp)
}()

err = internal.NewBuilder(c.log, c.cfg, tmp).Build(ctx)
err = internal.NewBuilder(c.log, c.cfg, tmp).Build(cmd.Context())
if err != nil {
return fmt.Errorf("build process: %w", err)
}
Expand Down
Loading