Skip to content

Move the parseConfig when run is called #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 1 addition & 11 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/golangci/golangci-lint/pkg/result/processors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"golang.org/x/tools/go/loader"
)
Expand Down Expand Up @@ -122,8 +121,6 @@ func (e *Executor) initRun() {
runCmd.Flags().BoolVarP(&ic.Diff, "new", "n", false, "Show only new issues: if there are unstaged changes or untracked files, only those changes are analyzed, else only changes in HEAD~ are analyzed")
runCmd.Flags().StringVar(&ic.DiffFromRevision, "new-from-rev", "", "Show only new issues created after git revision `REV`")
runCmd.Flags().StringVar(&ic.DiffPatchFilePath, "new-from-patch", "", "Show only new issues created in git patch with file path `PATH`")

e.parseConfig(runCmd)
}

func isFullImportNeeded(linters []pkg.Linter) bool {
Expand Down Expand Up @@ -378,6 +375,7 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
}

func (e *Executor) executeRun(cmd *cobra.Command, args []string) {
e.parseConfig(cmd)
logrus.Infof("Concurrency: %d, machine cpus count: %d",
e.cfg.Run.Concurrency, runtime.NumCPU())

Expand Down Expand Up @@ -413,14 +411,6 @@ func (e *Executor) executeRun(cmd *cobra.Command, args []string) {
}

func (e *Executor) parseConfig(cmd *cobra.Command) {
// XXX: hack with double parsing to access "config" option here
if err := cmd.ParseFlags(os.Args); err != nil {
if err == pflag.ErrHelp {
return
}
logrus.Fatalf("Can't parse args: %s", err)
}

if err := viper.BindPFlags(cmd.Flags()); err != nil {
logrus.Fatalf("Can't bind cobra's flags to viper: %s", err)
}
Expand Down