dev: clean code arround CLI args usage ()

This commit is contained in:
Ludovic Fernandez 2024-03-28 20:48:43 +01:00 committed by GitHub
parent dffe901d13
commit c5f13bac2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 234 additions and 114 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)