mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-13 06:48:43 -04:00
dev: clean code arround CLI args usage (#4557)
This commit is contained in:
parent
dffe901d13
commit
c5f13bac2a
10 changed files with 234 additions and 114 deletions
pkg/commands
|
@ -77,7 +77,7 @@ func newConfigCommand(log logutils.Log, info BuildInfo) *configCommand {
|
|||
return c
|
||||
}
|
||||
|
||||
func (c *configCommand) preRunE(cmd *cobra.Command, _ []string) error {
|
||||
func (c *configCommand) preRunE(cmd *cobra.Command, args []string) error {
|
||||
// The command doesn't depend on the real configuration.
|
||||
// It only needs to know the path of the configuration file.
|
||||
cfg := config.NewDefault()
|
||||
|
@ -89,7 +89,7 @@ func (c *configCommand) preRunE(cmd *cobra.Command, _ []string) error {
|
|||
// TODO(ldez) add an option (check deprecation) to `Loader.Load()` but this require a dedicated PR.
|
||||
cfg.Run.UseDefaultSkipDirs = true
|
||||
|
||||
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts, cfg)
|
||||
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts, cfg, args)
|
||||
|
||||
if err := loader.Load(); err != nil {
|
||||
return fmt.Errorf("can't load config: %w", err)
|
||||
|
|
|
@ -58,7 +58,7 @@ func newLintersCommand(logger logutils.Log) *lintersCommand {
|
|||
return c
|
||||
}
|
||||
|
||||
func (c *lintersCommand) preRunE(cmd *cobra.Command, _ []string) error {
|
||||
func (c *lintersCommand) preRunE(cmd *cobra.Command, args []string) error {
|
||||
// Hack to hide deprecation messages related to `--skip-dirs-use-default`:
|
||||
// Flags are not bound then the default values, defined only through flags, are not applied.
|
||||
// In this command, linters information are the only requirements, i.e. it don't need flag values.
|
||||
|
@ -66,7 +66,7 @@ func (c *lintersCommand) preRunE(cmd *cobra.Command, _ []string) error {
|
|||
// TODO(ldez) add an option (check deprecation) to `Loader.Load()` but this require a dedicated PR.
|
||||
c.cfg.Run.UseDefaultSkipDirs = true
|
||||
|
||||
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg)
|
||||
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
|
||||
|
||||
if err := loader.Load(); err != nil {
|
||||
return fmt.Errorf("can't load config: %w", err)
|
||||
|
|
|
@ -147,12 +147,12 @@ func newRunCommand(logger logutils.Log, info BuildInfo) *runCommand {
|
|||
return c
|
||||
}
|
||||
|
||||
func (c *runCommand) persistentPreRunE(cmd *cobra.Command, _ []string) error {
|
||||
func (c *runCommand) persistentPreRunE(cmd *cobra.Command, args []string) error {
|
||||
if err := c.startTracing(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg)
|
||||
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
|
||||
|
||||
if err := loader.Load(); err != nil {
|
||||
return fmt.Errorf("can't load config: %w", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue