From de9b376add4d4fd25b878250a713e7e00f3d212a Mon Sep 17 00:00:00 2001 From: Michelangelo Mori Date: Fri, 3 Jan 2025 12:49:17 +0100 Subject: [PATCH] Fix options reading in `history purge` command. (#5243) The added code makes it easier to read CLI options. It's probably a good idea to refactor that in a function wrapper. --- cmd/server/app/history_purge.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/server/app/history_purge.go b/cmd/server/app/history_purge.go index e17b0aaad4..ff177c76f0 100644 --- a/cmd/server/app/history_purge.go +++ b/cmd/server/app/history_purge.go @@ -28,14 +28,19 @@ var historyPurgeCmd = &cobra.Command{ } func historyPurgeCommand(cmd *cobra.Command, _ []string) error { - batchSize := viper.GetUint("batch-size") - dryRun := viper.GetBool("dry-run") - + // TODO: This statement and the following could be refactored + // in a function similar to `GRPCClientWrapRunE` + if err := viper.BindPFlags(cmd.Flags()); err != nil { + return fmt.Errorf("error binding flags: %s", err) + } cfg, err := config.ReadConfigFromViper[serverconfig.Config](viper.GetViper()) if err != nil { cliErrorf(cmd, "unable to read config: %s", err) } + batchSize := viper.GetUint("batch-size") + dryRun := viper.GetBool("dry-run") + ctx := serverconfig.LoggerFromConfigFlags(cfg.LoggingConfig).WithContext(context.Background()) // instantiate `db.Store` so we can run queries