From 4574ba646ddb9818684f1bde40caf3986a28dfa0 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 17 Jun 2022 00:40:21 +0300 Subject: [PATCH] [#1513] cli/storagegroup: Fix parsing container and SG flags Read `id` flag with the storage group ID. Prevent NPE-panic if flag is missing. Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/storagegroup/util.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/neofs-cli/modules/storagegroup/util.go b/cmd/neofs-cli/modules/storagegroup/util.go index d80ce9e830..2fefb5ba4e 100644 --- a/cmd/neofs-cli/modules/storagegroup/util.go +++ b/cmd/neofs-cli/modules/storagegroup/util.go @@ -1,6 +1,8 @@ package storagegroup import ( + "fmt" + "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -18,11 +20,25 @@ func readObjectAddress(cmd *cobra.Command, cnr *cid.ID, obj *oid.ID) oid.Address } func readCID(cmd *cobra.Command, id *cid.ID) { - err := id.DecodeString(cmd.Flag("cid").Value.String()) + const flag = "cid" + + f := cmd.Flag(flag) + if f == nil { + common.ExitOnErr(cmd, "", fmt.Errorf("missing container flag (%s)", flag)) + } + + err := id.DecodeString(f.Value.String()) common.ExitOnErr(cmd, "decode container ID string: %w", err) } func readSGID(cmd *cobra.Command, id *oid.ID) { - err := id.DecodeString(cmd.Flag("oid").Value.String()) + const flag = "id" + + f := cmd.Flag(flag) + if f == nil { + common.ExitOnErr(cmd, "", fmt.Errorf("missing storage group flag (%s)", flag)) + } + + err := id.DecodeString(f.Value.String()) common.ExitOnErr(cmd, "decode storage group ID string: %w", err) }