Allow configure module download mode

This commit is contained in:
Nicolae Vartolomei 2018-12-06 22:43:18 +00:00 committed by Isaev Denis
parent 7dfb9cff3d
commit b693037af0
4 changed files with 10 additions and 0 deletions

View File

@ -432,6 +432,7 @@ Flags:
--print-linter-name Print linter name in issue line (default true)
--issues-exit-code int Exit code when issues were found (default 1)
--build-tags strings Build tags
--mod string module download mode to use: readonly or vendor (passed to go list)
--deadline duration Deadline for total work (default 1m0s)
--tests Analyze tests (*_test.go) (default true)
--print-resources-usage Print avg and max memory usage of golangci-lint and total time

View File

@ -63,6 +63,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager) {
fs.IntVar(&rc.ExitCodeIfIssuesFound, "issues-exit-code",
exitcodes.IssuesFound, wh("Exit code when issues were found"))
fs.StringSliceVar(&rc.BuildTags, "build-tags", nil, wh("Build tags"))
fs.StringVar(&rc.Mod, "mod", "", wh("module download mode to use: readonly or vendor (passed to go list)"))
fs.DurationVar(&rc.Deadline, "deadline", time.Minute, wh("Deadline for total work"))
fs.BoolVar(&rc.AnalyzeTests, "tests", true, wh("Analyze tests (*_test.go)"))
fs.BoolVar(&rc.PrintResourcesUsage, "print-resources-usage", false,

View File

@ -110,6 +110,7 @@ type Run struct {
Args []string
BuildTags []string `mapstructure:"build-tags"`
Mod string `mapstructure:"mod"`
ExitCodeIfIssuesFound int `mapstructure:"issues-exit-code"`
AnalyzeTests bool `mapstructure:"tests"`

View File

@ -201,10 +201,17 @@ func (cl ContextLoader) loadPackages(ctx context.Context, loadMode packages.Load
cl.prepareBuildContext()
var buildFlags []string
if len(cl.cfg.Run.BuildTags) != 0 {
// go help build
buildFlags = []string{"-tags", strings.Join(cl.cfg.Run.BuildTags, " ")}
}
if cl.cfg.Run.Mod != "" {
// go help module
buildFlags = append(buildFlags, fmt.Sprintf("-mod=%s", cl.cfg.Run.Mod))
}
conf := &packages.Config{
Mode: loadMode,
Tests: cl.cfg.Run.AnalyzeTests,