Skip to content

Commit 2a1afc1

Browse files
authored
dev: use cmd.Context inside custom command (#4496)
1 parent b923d0f commit 2a1afc1

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

cmd/golangci-lint/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func main() {
2222
info := createBuildInfo()
2323

2424
if err := commands.Execute(info); err != nil {
25-
_, _ = fmt.Fprintf(os.Stderr, "failed executing command with error %v\n", err)
25+
_, _ = fmt.Fprintf(os.Stderr, "Failed executing command with error: %v\n", err)
2626
os.Exit(exitcodes.Failure)
2727
}
2828
}

pkg/commands/custom.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package commands
22

33
import (
4-
"context"
54
"fmt"
65
"log"
76
"os"
@@ -27,7 +26,7 @@ func newCustomCommand(logger logutils.Log) *customCommand {
2726

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

57-
func (c *customCommand) runE(_ *cobra.Command, _ []string) error {
58-
ctx := context.Background()
59-
56+
func (c *customCommand) runE(cmd *cobra.Command, _ []string) error {
6057
tmp, err := os.MkdirTemp(os.TempDir(), "custom-gcl")
6158
if err != nil {
6259
return fmt.Errorf("create temporary directory: %w", err)
@@ -72,7 +69,7 @@ func (c *customCommand) runE(_ *cobra.Command, _ []string) error {
7269
_ = os.RemoveAll(tmp)
7370
}()
7471

75-
err = internal.NewBuilder(c.log, c.cfg, tmp).Build(ctx)
72+
err = internal.NewBuilder(c.log, c.cfg, tmp).Build(cmd.Context())
7673
if err != nil {
7774
return fmt.Errorf("build process: %w", err)
7875
}

0 commit comments

Comments
 (0)