Skip to content
Open
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
28 changes: 28 additions & 0 deletions pkg/commands/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"

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

"github.com/golangci/golangci-lint/v2/pkg/commands/internal"
Expand All @@ -13,11 +14,19 @@ import (

const envKeepTempFiles = "CUSTOM_GCL_KEEP_TEMP_FILES"

type customOptions struct {
version string
name string
destination string
}

type customCommand struct {
cmd *cobra.Command

cfg *internal.Configuration

opts customOptions

log logutils.Log
}

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

flagSet := customCmd.PersistentFlags()
flagSet.SortFlags = false // sort them as they are defined here

flagSet.StringVar(&c.opts.version, "version", "", color.GreenString("The golangci-lint version used to build the custom binary"))
flagSet.StringVar(&c.opts.name, "name", "", color.GreenString("The name of the custom binary"))
flagSet.StringVar(&c.opts.destination, "destination", "", color.GreenString("The directory path used to store the custom binary"))

c.cmd = customCmd

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

if c.opts.version != "" {
cfg.Version = c.opts.version
}

if c.opts.name != "" {
cfg.Name = c.opts.name
}

if c.opts.destination != "" {
cfg.Destination = c.opts.destination
}

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