@@ -29,42 +29,17 @@ import (
29
29
30
30
const defaultFileMode = 0644
31
31
32
+ const defaultTimeout = time .Minute
33
+
32
34
const (
33
35
// envFailOnWarnings value: "1"
34
36
envFailOnWarnings = "FAIL_ON_WARNINGS"
35
37
// envMemLogEvery value: "1"
36
38
envMemLogEvery = "GL_MEM_LOG_EVERY"
37
39
)
38
40
39
- func getDefaultIssueExcludeHelp () string {
40
- parts := []string {color .GreenString ("Use or not use default excludes:" )}
41
- for _ , ep := range config .DefaultExcludePatterns {
42
- parts = append (parts ,
43
- fmt .Sprintf (" # %s %s: %s" , ep .ID , ep .Linter , ep .Why ),
44
- fmt .Sprintf (" - %s" , color .YellowString (ep .Pattern )),
45
- "" ,
46
- )
47
- }
48
- return strings .Join (parts , "\n " )
49
- }
50
-
51
- func getDefaultDirectoryExcludeHelp () string {
52
- parts := []string {color .GreenString ("Use or not use default excluded directories:" )}
53
- for _ , dir := range packages .StdExcludeDirRegexps {
54
- parts = append (parts , fmt .Sprintf (" - %s" , color .YellowString (dir )))
55
- }
56
- parts = append (parts , "" )
57
- return strings .Join (parts , "\n " )
58
- }
59
-
60
- func wh (text string ) string {
61
- return color .GreenString (text )
62
- }
63
-
64
- const defaultTimeout = time .Minute
65
-
66
41
//nolint:funlen,gomnd
67
- func initFlagSet (fs * pflag.FlagSet , cfg * config.Config , m * lintersdb. Manager , isFinalInit bool ) {
42
+ func ( e * Executor ) initFlagSet (fs * pflag.FlagSet , cfg * config.Config , isFinalInit bool ) {
68
43
hideFlag := func (name string ) {
69
44
if err := fs .MarkHidden (name ); err != nil {
70
45
panic (err )
@@ -79,6 +54,10 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
79
54
}
80
55
}
81
56
57
+ // Config file config
58
+ rc := & cfg .Run
59
+ initConfigFileFlagSet (fs , rc )
60
+
82
61
// Output config
83
62
oc := & cfg .Output
84
63
fs .StringVar (& oc .Format , "out-format" ,
@@ -98,7 +77,6 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
98
77
}
99
78
100
79
// Run config
101
- rc := & cfg .Run
102
80
fs .StringVar (& rc .ModulesDownloadMode , "modules-download-mode" , "" ,
103
81
wh ("Modules download mode. If not empty, passed as -mod=<mode> to go tools" ))
104
82
fs .IntVar (& rc .ExitCodeIfIssuesFound , "issues-exit-code" ,
@@ -115,8 +93,6 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
115
93
fs .BoolVar (& rc .AnalyzeTests , "tests" , true , wh ("Analyze tests (*_test.go)" ))
116
94
fs .BoolVar (& rc .PrintResourcesUsage , "print-resources-usage" , false ,
117
95
wh ("Print avg and max memory usage of golangci-lint and total time" ))
118
- fs .StringVarP (& rc .Config , "config" , "c" , "" , wh ("Read config from file path `PATH`" ))
119
- fs .BoolVar (& rc .NoConfig , "no-config" , false , wh ("Don't read config" ))
120
96
fs .StringSliceVar (& rc .SkipDirs , "skip-dirs" , nil , wh ("Regexps of directories to skip" ))
121
97
fs .BoolVar (& rc .UseDefaultSkipDirs , "skip-dirs-use-default" , true , getDefaultDirectoryExcludeHelp ())
122
98
fs .StringSliceVar (& rc .SkipFiles , "skip-files" , nil , wh ("Regexps of files to skip" ))
@@ -200,15 +176,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
200
176
201
177
// Linters config
202
178
lc := & cfg .Linters
203
- fs .StringSliceVarP (& lc .Enable , "enable" , "E" , nil , wh ("Enable specific linter" ))
204
- fs .StringSliceVarP (& lc .Disable , "disable" , "D" , nil , wh ("Disable specific linter" ))
205
- fs .BoolVar (& lc .EnableAll , "enable-all" , false , wh ("Enable all linters" ))
206
-
207
- fs .BoolVar (& lc .DisableAll , "disable-all" , false , wh ("Disable all linters" ))
208
- fs .StringSliceVarP (& lc .Presets , "presets" , "p" , nil ,
209
- wh (fmt .Sprintf ("Enable presets (%s) of linters. Run 'golangci-lint help linters' to see " +
210
- "them. This option implies option --disable-all" , strings .Join (m .AllPresets (), "|" ))))
211
- fs .BoolVar (& lc .Fast , "fast" , false , wh ("Run only fast linters from enabled linters set (first run won't be fast)" ))
179
+ e .initLintersFlagSet (fs , lc )
212
180
213
181
// Issues config
214
182
ic := & cfg .Issues
@@ -241,7 +209,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
241
209
func (e * Executor ) initRunConfiguration (cmd * cobra.Command ) {
242
210
fs := cmd .Flags ()
243
211
fs .SortFlags = false // sort them as they are defined here
244
- initFlagSet (fs , e .cfg , e . DBManager , true )
212
+ e . initFlagSet (fs , e .cfg , true )
245
213
}
246
214
247
215
func (e * Executor ) getConfigForCommandLine () (* config.Config , error ) {
@@ -254,7 +222,7 @@ func (e *Executor) getConfigForCommandLine() (*config.Config, error) {
254
222
// `changed` variable inside string slice vars will be shared.
255
223
// Use another config variable here, not e.cfg, to not
256
224
// affect main parsing by this parsing of only config option.
257
- initFlagSet (fs , & cfg , e . DBManager , false )
225
+ e . initFlagSet (fs , & cfg , false )
258
226
initVersionFlagSet (fs , & cfg )
259
227
260
228
// Parse max options, even force version option: don't want
@@ -639,3 +607,28 @@ func watchResources(ctx context.Context, done chan struct{}, logger logutils.Log
639
607
logger .Infof ("Execution took %s" , time .Since (startedAt ))
640
608
close (done )
641
609
}
610
+
611
+ func getDefaultIssueExcludeHelp () string {
612
+ parts := []string {color .GreenString ("Use or not use default excludes:" )}
613
+ for _ , ep := range config .DefaultExcludePatterns {
614
+ parts = append (parts ,
615
+ fmt .Sprintf (" # %s %s: %s" , ep .ID , ep .Linter , ep .Why ),
616
+ fmt .Sprintf (" - %s" , color .YellowString (ep .Pattern )),
617
+ "" ,
618
+ )
619
+ }
620
+ return strings .Join (parts , "\n " )
621
+ }
622
+
623
+ func getDefaultDirectoryExcludeHelp () string {
624
+ parts := []string {color .GreenString ("Use or not use default excluded directories:" )}
625
+ for _ , dir := range packages .StdExcludeDirRegexps {
626
+ parts = append (parts , fmt .Sprintf (" - %s" , color .YellowString (dir )))
627
+ }
628
+ parts = append (parts , "" )
629
+ return strings .Join (parts , "\n " )
630
+ }
631
+
632
+ func wh (text string ) string {
633
+ return color .GreenString (text )
634
+ }
0 commit comments