From e0cf86f4b1754a453c3b4b7d78288e80696cff8d Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Wed, 15 Nov 2023 15:15:07 +0100 Subject: [PATCH] fix(cmd/driver): avoid nil pointer deref. Signed-off-by: Federico Di Pierro --- cmd/driver/config/config.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/driver/config/config.go b/cmd/driver/config/config.go index b1d556ba5..825a0a15b 100644 --- a/cmd/driver/config/config.go +++ b/cmd/driver/config/config.go @@ -43,7 +43,7 @@ const ( type driverConfigOptions struct { *options.Common - Type options.DriverTypes + Type *options.DriverTypes Version string Repos []string Name string @@ -57,6 +57,7 @@ type driverConfigOptions struct { func NewDriverConfigCmd(ctx context.Context, opt *options.Common) *cobra.Command { o := driverConfigOptions{ Common: opt, + Type: options.NewDriverTypes(), } cmd := &cobra.Command{ @@ -69,7 +70,7 @@ func NewDriverConfigCmd(ctx context.Context, opt *options.Common) *cobra.Command }, } - cmd.Flags().Var(&o.Type, "type", "Driver type to be configured "+o.Type.Allowed()) + cmd.Flags().Var(o.Type, "type", "Driver type to be configured "+o.Type.Allowed()) cmd.Flags().StringVar(&o.Version, "version", config.DefaultDriver.Version, "Driver version to be configured.") cmd.Flags().StringSliceVar(&o.Repos, "repo", config.DefaultDriver.Repos, "Driver repo to be configured.") cmd.Flags().StringVar(&o.Name, "name", config.DefaultDriver.Name, "Driver name to be configured.") @@ -124,7 +125,7 @@ func (o *driverConfigOptions) RunDriverConfig(ctx context.Context, cmd *cobra.Co if f := cmd.Flags().Lookup("type"); f != nil && f.Changed { loggerArgs = append(loggerArgs, pterm.LoggerArgument{ Key: "driver type", - Value: o.Type, + Value: o.Type.String(), }) if o.Type.String() != "auto" { // Ok driver type was enforced by the user