Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
feat: add -o, --output flag to golangci-custom (#1)
Browse files Browse the repository at this point in the history
> [!NOTE]
> `golangci-lint` maintainer [refuses to consider this change](golangci#5369 (comment)).

Confirmed the help output is as expected:

```
Build a version of golangci-lint with custom linters

Usage:
  golangci-lint custom [flags]

Flags:
  -o, --output string   Path to output file

Global Flags:
      --color string   Use color when printing; can be 'always', 'auto', or 'never' (default "auto")
  -h, --help           Help for a command
  -v, --verbose        Verbose output
```
  • Loading branch information
lukasschwab committed Feb 3, 2025
1 parent a2ef9ee commit c2e7faf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/commands/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"fmt"
"log"
"os"
"path"

"github.com/fatih/color"
"github.com/spf13/cobra"

"github.com/golangci/golangci-lint/pkg/commands/internal"
Expand All @@ -13,6 +15,10 @@ import (

const envKeepTempFiles = "CUSTOM_GCL_KEEP_TEMP_FILES"

var (
outputArgument = ""
)

type customCommand struct {
cmd *cobra.Command

Expand All @@ -33,6 +39,8 @@ func newCustomCommand(logger logutils.Log) *customCommand {
SilenceUsage: true,
}

customCmd.Flags().StringVarP(&outputArgument, "output", "o", "", color.GreenString("Path to output file"))

c.cmd = customCmd

return c
Expand All @@ -44,6 +52,12 @@ func (c *customCommand) preRunE(_ *cobra.Command, _ []string) error {
return err
}

if outputArgument != "" {
directory, name := path.Split(outputArgument)
cfg.Destination = directory
cfg.Name = name
}

err = cfg.Validate()
if err != nil {
return err
Expand Down

0 comments on commit c2e7faf

Please sign in to comment.