From fee27d249d7813b921b6a213609a61ca241c8c76 Mon Sep 17 00:00:00 2001 From: Lukas Schwab Date: Sun, 2 Feb 2025 20:34:09 -0800 Subject: [PATCH] Add -o // --output flag to golangci-custom 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