@@ -29,42 +29,17 @@ import (
2929
3030const defaultFileMode = 0644
3131
32+ const defaultTimeout = time .Minute
33+
3234const (
3335 // envFailOnWarnings value: "1"
3436 envFailOnWarnings = "FAIL_ON_WARNINGS"
3537 // envMemLogEvery value: "1"
3638 envMemLogEvery = "GL_MEM_LOG_EVERY"
3739)
3840
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-
6641//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 ) {
6843 hideFlag := func (name string ) {
6944 if err := fs .MarkHidden (name ); err != nil {
7045 panic (err )
@@ -79,6 +54,10 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
7954 }
8055 }
8156
57+ // Config file config
58+ rc := & cfg .Run
59+ initConfigFileFlagSet (fs , rc )
60+
8261 // Output config
8362 oc := & cfg .Output
8463 fs .StringVar (& oc .Format , "out-format" ,
@@ -98,7 +77,6 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
9877 }
9978
10079 // Run config
101- rc := & cfg .Run
10280 fs .StringVar (& rc .ModulesDownloadMode , "modules-download-mode" , "" ,
10381 wh ("Modules download mode. If not empty, passed as -mod=<mode> to go tools" ))
10482 fs .IntVar (& rc .ExitCodeIfIssuesFound , "issues-exit-code" ,
@@ -115,8 +93,6 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
11593 fs .BoolVar (& rc .AnalyzeTests , "tests" , true , wh ("Analyze tests (*_test.go)" ))
11694 fs .BoolVar (& rc .PrintResourcesUsage , "print-resources-usage" , false ,
11795 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" ))
12096 fs .StringSliceVar (& rc .SkipDirs , "skip-dirs" , nil , wh ("Regexps of directories to skip" ))
12197 fs .BoolVar (& rc .UseDefaultSkipDirs , "skip-dirs-use-default" , true , getDefaultDirectoryExcludeHelp ())
12298 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
200176
201177 // Linters config
202178 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 )
212180
213181 // Issues config
214182 ic := & cfg .Issues
@@ -241,7 +209,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
241209func (e * Executor ) initRunConfiguration (cmd * cobra.Command ) {
242210 fs := cmd .Flags ()
243211 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 )
245213}
246214
247215func (e * Executor ) getConfigForCommandLine () (* config.Config , error ) {
@@ -254,7 +222,7 @@ func (e *Executor) getConfigForCommandLine() (*config.Config, error) {
254222 // `changed` variable inside string slice vars will be shared.
255223 // Use another config variable here, not e.cfg, to not
256224 // affect main parsing by this parsing of only config option.
257- initFlagSet (fs , & cfg , e . DBManager , false )
225+ e . initFlagSet (fs , & cfg , false )
258226 initVersionFlagSet (fs , & cfg )
259227
260228 // 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
639607 logger .Infof ("Execution took %s" , time .Since (startedAt ))
640608 close (done )
641609}
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