From 63249f6419dfadd5dc302771e5e5ca7524606b30 Mon Sep 17 00:00:00 2001 From: Aneesh Rao <73494487+rao-aneesh@users.noreply.github.com> Date: Wed, 10 Jul 2024 18:52:20 +0530 Subject: [PATCH 1/2] Update get.go --- pkg/app/get.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/app/get.go b/pkg/app/get.go index 6af813c4..f6b8e335 100644 --- a/pkg/app/get.go +++ b/pkg/app/get.go @@ -102,6 +102,9 @@ func (a *App) GetRequest(ctx context.Context, tc *types.TargetConfig) { a.logError(fmt.Errorf("target %q Get request failed: %v", tc.Name, err)) return } + if response == nil { + return + } err = a.PrintMsg(tc.Name, "Get Response:", response) if err != nil { a.logError(fmt.Errorf("target %q: %v", tc.Name, err)) @@ -123,12 +126,15 @@ func (a *App) getRequest(ctx context.Context, tc *types.TargetConfig, req *gnmi. xreq.UseModels = append(xreq.UseModels, m) } } - if a.Config.PrintRequest { + if a.Config.PrintRequest || a.Config.GetDryRun { err := a.PrintMsg(tc.Name, "Get Request:", req) if err != nil { a.logError(fmt.Errorf("target %q Get Request printing failed: %v", tc.Name, err)) } } + if a.Config.GetDryRun { + return nil, nil + } a.Logger.Printf("sending gNMI GetRequest: prefix='%v', path='%v', type='%v', encoding='%v', models='%+v', extension='%+v' to %s", xreq.Prefix, xreq.Path, xreq.Type, xreq.Encoding, xreq.UseModels, xreq.Extension, tc.Name) @@ -176,6 +182,7 @@ func (a *App) InitGetFlags(cmd *cobra.Command) { cmd.Flags().BoolVarP(&a.Config.LocalFlags.GetValuesOnly, "values-only", "", false, "print GetResponse values only") cmd.Flags().StringArrayVarP(&a.Config.LocalFlags.GetProcessor, "processor", "", []string{}, "list of processor names to run") cmd.Flags().Uint32VarP(&a.Config.LocalFlags.GetDepth, "depth", "", 0, "depth extension value") + cmd.Flags().BoolVarP(&a.Config.LocalFlags.GetDryRun, "dry-run", "", false, "prints the get request without initiating a gRPC connection") cmd.LocalFlags().VisitAll(func(flag *pflag.Flag) { a.Config.FileConfig.BindPFlag(fmt.Sprintf("%s-%s", cmd.Name(), flag.Name), flag) From 0acf71a73011452652d3ea2e164cfb60b87591f9 Mon Sep 17 00:00:00 2001 From: Aneesh Rao <73494487+rao-aneesh@users.noreply.github.com> Date: Wed, 10 Jul 2024 18:52:50 +0530 Subject: [PATCH 2/2] Update config.go --- pkg/config/config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/config/config.go b/pkg/config/config.go index f2f0d359..1f4a02af 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -135,6 +135,7 @@ type LocalFlags struct { GetValuesOnly bool `mapstructure:"get-values-only,omitempty" json:"get-values-only,omitempty" yaml:"get-values-only,omitempty"` GetProcessor []string `mapstructure:"get-processor,omitempty" json:"get-processor,omitempty" yaml:"get-processor,omitempty"` GetDepth uint32 `mapstructure:"get-depth,omitempty" yaml:"get-depth,omitempty" json:"get-depth,omitempty"` + GetDryRun bool `mapstructure:"get-dry-run,omitempty" json:"get-dry-run,omitempty" yaml:"get-dry-run,omitempty"` // Set SetPrefix string `mapstructure:"set-prefix,omitempty" json:"set-prefix,omitempty" yaml:"set-prefix,omitempty"` SetDelete []string `mapstructure:"set-delete,omitempty" json:"set-delete,omitempty" yaml:"set-delete,omitempty"`