dev: clean up command contructors (#4478)
This commit is contained in:
parent
6fda81008d
commit
05f27abc01
@ -30,10 +30,10 @@ type lintersCommand struct {
|
|||||||
dbManager *lintersdb.Manager
|
dbManager *lintersdb.Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLintersCommand(logger logutils.Log, cfg *config.Config) *lintersCommand {
|
func newLintersCommand(logger logutils.Log) *lintersCommand {
|
||||||
c := &lintersCommand{
|
c := &lintersCommand{
|
||||||
viper: viper.New(),
|
viper: viper.New(),
|
||||||
cfg: cfg,
|
cfg: config.NewDefault(),
|
||||||
log: logger,
|
log: logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,9 +10,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/config"
|
|
||||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||||
"github.com/golangci/golangci-lint/pkg/report"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Execute(info BuildInfo) error {
|
func Execute(info BuildInfo) error {
|
||||||
@ -56,13 +54,12 @@ func newRootCommand(info BuildInfo) *rootCommand {
|
|||||||
|
|
||||||
setupRootPersistentFlags(rootCmd.PersistentFlags(), &c.opts)
|
setupRootPersistentFlags(rootCmd.PersistentFlags(), &c.opts)
|
||||||
|
|
||||||
reportData := &report.Data{}
|
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
|
||||||
log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), reportData)
|
|
||||||
|
|
||||||
// Dedicated configuration for each command to avoid side effects of bindings.
|
// Each command uses a dedicated configuration structure to avoid side effects of bindings.
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
newLintersCommand(log, config.NewDefault()).cmd,
|
newLintersCommand(log).cmd,
|
||||||
newRunCommand(log, config.NewDefault(), reportData, info).cmd,
|
newRunCommand(log, info).cmd,
|
||||||
newCacheCommand().cmd,
|
newCacheCommand().cmd,
|
||||||
newConfigCommand(log).cmd,
|
newConfigCommand(log).cmd,
|
||||||
newVersionCommand(info).cmd,
|
newVersionCommand(info).cmd,
|
||||||
|
@ -98,12 +98,14 @@ type runCommand struct {
|
|||||||
exitCode int
|
exitCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRunCommand(logger logutils.Log, cfg *config.Config, reportData *report.Data, info BuildInfo) *runCommand {
|
func newRunCommand(logger logutils.Log, info BuildInfo) *runCommand {
|
||||||
|
reportData := &report.Data{}
|
||||||
|
|
||||||
c := &runCommand{
|
c := &runCommand{
|
||||||
viper: viper.New(),
|
viper: viper.New(),
|
||||||
log: logger,
|
log: report.NewLogWrapper(logger, reportData),
|
||||||
debugf: logutils.Debug(logutils.DebugKeyExec),
|
debugf: logutils.Debug(logutils.DebugKeyExec),
|
||||||
cfg: cfg,
|
cfg: config.NewDefault(),
|
||||||
reportData: reportData,
|
reportData: reportData,
|
||||||
buildInfo: info,
|
buildInfo: info,
|
||||||
}
|
}
|
||||||
@ -126,7 +128,7 @@ func newRunCommand(logger logutils.Log, cfg *config.Config, reportData *report.D
|
|||||||
|
|
||||||
// Only for testing purpose.
|
// Only for testing purpose.
|
||||||
// Don't add other flags here.
|
// Don't add other flags here.
|
||||||
fs.BoolVar(&cfg.InternalCmdTest, "internal-cmd-test", false,
|
fs.BoolVar(&c.cfg.InternalCmdTest, "internal-cmd-test", false,
|
||||||
color.GreenString("Option is used only for testing golangci-lint command, don't use it"))
|
color.GreenString("Option is used only for testing golangci-lint command, don't use it"))
|
||||||
_ = fs.MarkHidden("internal-cmd-test")
|
_ = fs.MarkHidden("internal-cmd-test")
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type JSON struct {
|
type JSON struct {
|
||||||
rd *report.Data
|
rd *report.Data // TODO(ldez) should be drop in v2. Only use by JSON reporter.
|
||||||
w io.Writer
|
w io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,14 +9,13 @@ import (
|
|||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/fsutils"
|
"github.com/golangci/golangci-lint/pkg/fsutils"
|
||||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||||
"github.com/golangci/golangci-lint/pkg/report"
|
|
||||||
"github.com/golangci/golangci-lint/pkg/result"
|
"github.com/golangci/golangci-lint/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSeverity_multiple(t *testing.T) {
|
func TestSeverity_multiple(t *testing.T) {
|
||||||
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
||||||
files := fsutils.NewFiles(lineCache, "")
|
files := fsutils.NewFiles(lineCache, "")
|
||||||
log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), &report.Data{})
|
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
|
||||||
|
|
||||||
opts := SeverityOptions{
|
opts := SeverityOptions{
|
||||||
Default: "error",
|
Default: "error",
|
||||||
@ -132,7 +131,7 @@ func TestSeverity_pathPrefix(t *testing.T) {
|
|||||||
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
||||||
pathPrefix := path.Join("some", "dir")
|
pathPrefix := path.Join("some", "dir")
|
||||||
files := fsutils.NewFiles(lineCache, pathPrefix)
|
files := fsutils.NewFiles(lineCache, pathPrefix)
|
||||||
log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), &report.Data{})
|
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
|
||||||
|
|
||||||
opts := SeverityOptions{
|
opts := SeverityOptions{
|
||||||
Default: "error",
|
Default: "error",
|
||||||
@ -217,7 +216,7 @@ func TestSeverity_text(t *testing.T) {
|
|||||||
func TestSeverity_onlyDefault(t *testing.T) {
|
func TestSeverity_onlyDefault(t *testing.T) {
|
||||||
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
||||||
files := fsutils.NewFiles(lineCache, "")
|
files := fsutils.NewFiles(lineCache, "")
|
||||||
log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), &report.Data{})
|
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
|
||||||
|
|
||||||
opts := SeverityOptions{
|
opts := SeverityOptions{
|
||||||
Default: "info",
|
Default: "info",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user