Skip to content

Commit 5117034

Browse files
committed
chore: remove configuration fields for commands when a command doesn't depend on the real configuration
1 parent 020b032 commit 5117034

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

pkg/commands/config.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ type configCommand struct {
1717
viper *viper.Viper
1818
cmd *cobra.Command
1919

20-
cfg *config.Config
21-
2220
log logutils.Log
2321
}
2422

25-
func newConfigCommand(log logutils.Log, cfg *config.Config) *configCommand {
23+
func newConfigCommand(log logutils.Log) *configCommand {
2624
c := &configCommand{
2725
viper: viper.New(),
2826
log: log,
29-
cfg: cfg,
3027
}
3128

3229
configCmd := &cobra.Command{
@@ -55,7 +52,9 @@ func newConfigCommand(log logutils.Log, cfg *config.Config) *configCommand {
5552
}
5653

5754
func (c *configCommand) preRunE(_ *cobra.Command, _ []string) error {
58-
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, config.LoaderOptions{}, c.cfg)
55+
// The command doesn't depend on the real configuration.
56+
// It only needs to know the path of the configuration file.
57+
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, config.LoaderOptions{}, config.NewDefault())
5958

6059
if err := loader.Load(); err != nil {
6160
return fmt.Errorf("can't load config: %w", err)

pkg/commands/help.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ import (
1717
type helpCommand struct {
1818
cmd *cobra.Command
1919

20-
cfg *config.Config
21-
2220
dbManager *lintersdb.Manager
2321

2422
log logutils.Log
2523
}
2624

27-
func newHelpCommand(logger logutils.Log, cfg *config.Config) *helpCommand {
28-
c := &helpCommand{log: logger, cfg: cfg}
25+
func newHelpCommand(logger logutils.Log) *helpCommand {
26+
c := &helpCommand{log: logger}
2927

3028
helpCmd := &cobra.Command{
3129
Use: "help",
@@ -53,7 +51,9 @@ func newHelpCommand(logger logutils.Log, cfg *config.Config) *helpCommand {
5351
}
5452

5553
func (c *helpCommand) preRun(_ *cobra.Command, _ []string) {
56-
c.dbManager = lintersdb.NewManager(c.cfg, c.log)
54+
// The command doesn't depend on the real configuration.
55+
// It just needs the list of all plugins and all presets.
56+
c.dbManager = lintersdb.NewManager(config.NewDefault(), c.log)
5757
}
5858

5959
func (c *helpCommand) execute(_ *cobra.Command, _ []string) {

pkg/commands/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ func newRootCommand(info BuildInfo) *rootCommand {
6464
newLintersCommand(log, config.NewDefault()).cmd,
6565
newRunCommand(log, config.NewDefault(), reportData, info).cmd,
6666
newCacheCommand().cmd,
67-
newConfigCommand(log, config.NewDefault()).cmd,
67+
newConfigCommand(log).cmd,
6868
newVersionCommand(info).cmd,
6969
)
7070

71-
rootCmd.SetHelpCommand(newHelpCommand(log, config.NewDefault()).cmd)
71+
rootCmd.SetHelpCommand(newHelpCommand(log).cmd)
7272

7373
c.log = log
7474
c.cmd = rootCmd

0 commit comments

Comments
 (0)