From c2e7faf11eb808f02afbb499535ecf6ea0641249 Mon Sep 17 00:00:00 2001 From: Lukas Schwab Date: Sun, 2 Feb 2025 20:34:09 -0800 Subject: [PATCH] feat: add `-o`, `--output` flag to golangci-custom (#1) > [!NOTE] > `golangci-lint` maintainer [refuses to consider this change](https://github.com/golangci/golangci-lint/issues/5369#issuecomment-2629898971). 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 ``` --- pkg/commands/custom.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/commands/custom.go b/pkg/commands/custom.go index 1bc9f9014615..27117cb1ee4d 100644 --- a/pkg/commands/custom.go +++ b/pkg/commands/custom.go @@ -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" @@ -13,6 +15,10 @@ import ( const envKeepTempFiles = "CUSTOM_GCL_KEEP_TEMP_FILES" +var ( + outputArgument = "" +) + type customCommand struct { cmd *cobra.Command @@ -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 @@ -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