From c6080afcd90885908c90331a1cbdac1ab0b18f06 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Thu, 21 Dec 2023 09:29:36 +0000 Subject: [PATCH] runner: use default value if flag is not set Signed-off-by: Wei Fu --- cmd/kperf/commands/runner/runner.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/kperf/commands/runner/runner.go b/cmd/kperf/commands/runner/runner.go index c2ab3f9..0acea61 100644 --- a/cmd/kperf/commands/runner/runner.go +++ b/cmd/kperf/commands/runner/runner.go @@ -95,11 +95,15 @@ func loadConfig(cliCtx *cli.Context) (*types.LoadProfile, error) { } // override value by flags - // - // TODO(weifu): do not override if flag is not set - profileCfg.Spec.Rate = cliCtx.Int("rate") - profileCfg.Spec.Conns = cliCtx.Int("conns") - profileCfg.Spec.Total = cliCtx.Int("total") + if v := "rate"; cliCtx.IsSet(v) { + profileCfg.Spec.Rate = cliCtx.Int(v) + } + if v := "conns"; cliCtx.IsSet(v) || profileCfg.Spec.Conns == 0 { + profileCfg.Spec.Conns = cliCtx.Int(v) + } + if v := "total"; cliCtx.IsSet(v) || profileCfg.Spec.Total == 0 { + profileCfg.Spec.Total = cliCtx.Int(v) + } if err := profileCfg.Validate(); err != nil { return nil, err