Skip to content

Commit 0635d01

Browse files
committed
feat: add some flags to the custom command
1 parent 7255b2c commit 0635d01

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pkg/commands/custom.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log"
66
"os"
77

8+
"github.com/fatih/color"
89
"github.com/spf13/cobra"
910

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

1415
const envKeepTempFiles = "CUSTOM_GCL_KEEP_TEMP_FILES"
1516

17+
type customOptions struct {
18+
version string
19+
name string
20+
destination string
21+
}
22+
1623
type customCommand struct {
1724
cmd *cobra.Command
1825

1926
cfg *internal.Configuration
2027

28+
opts customOptions
29+
2130
log logutils.Log
2231
}
2332

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

45+
flagSet := customCmd.PersistentFlags()
46+
flagSet.SortFlags = false // sort them as they are defined here
47+
48+
flagSet.StringVar(&c.opts.version, "version", "", color.GreenString("The golangci-lint version used to build the custom binary"))
49+
flagSet.StringVar(&c.opts.name, "name", "", color.GreenString("The name of the custom binary"))
50+
flagSet.StringVar(&c.opts.destination, "destination", "", color.GreenString("The directory path used to store the custom binary"))
51+
3652
c.cmd = customCmd
3753

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

63+
if c.opts.version != "" {
64+
cfg.Version = c.opts.version
65+
}
66+
67+
if c.opts.name != "" {
68+
cfg.Name = c.opts.name
69+
}
70+
71+
if c.opts.destination != "" {
72+
cfg.Destination = c.opts.destination
73+
}
74+
4775
err = cfg.Validate()
4876
if err != nil {
4977
return err

0 commit comments

Comments
 (0)