forked from TrueCloudLab/frostfs-node
[#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 <leonard@nspcc.ru>
This commit is contained in:
parent
820acebb7d
commit
4574ba646d
1 changed files with 18 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
||||||
package storagegroup
|
package storagegroup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/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) {
|
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)
|
common.ExitOnErr(cmd, "decode container ID string: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readSGID(cmd *cobra.Command, id *oid.ID) {
|
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)
|
common.ExitOnErr(cmd, "decode storage group ID string: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue