From bc5882fc890f28334027d7f2a2ce9adfa38de518 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 20 Jun 2022 19:33:34 +0300 Subject: [PATCH] [#1402] cli: Add `cid` flag constant Also, move common flag constants in `root` file of the `storagegroup` package. Signed-off-by: Pavel Karpy --- cmd/neofs-cli/modules/storagegroup/delete.go | 4 ++-- cmd/neofs-cli/modules/storagegroup/get.go | 9 ++------- cmd/neofs-cli/modules/storagegroup/list.go | 4 ++-- cmd/neofs-cli/modules/storagegroup/put.go | 4 ++-- cmd/neofs-cli/modules/storagegroup/root.go | 6 ++++++ cmd/neofs-cli/modules/storagegroup/util.go | 6 ++---- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/cmd/neofs-cli/modules/storagegroup/delete.go b/cmd/neofs-cli/modules/storagegroup/delete.go index c03ac4831..8ae5d8000 100644 --- a/cmd/neofs-cli/modules/storagegroup/delete.go +++ b/cmd/neofs-cli/modules/storagegroup/delete.go @@ -24,8 +24,8 @@ func initSGDeleteCmd() { flags := sgDelCmd.Flags() - flags.String("cid", "", "Container ID") - _ = sgDelCmd.MarkFlagRequired("cid") + flags.String(cidFlag, "", "Container ID") + _ = sgDelCmd.MarkFlagRequired(cidFlag) flags.StringVarP(&sgID, sgIDFlag, "", "", "storage group identifier") _ = sgDelCmd.MarkFlagRequired(sgIDFlag) diff --git a/cmd/neofs-cli/modules/storagegroup/get.go b/cmd/neofs-cli/modules/storagegroup/get.go index 6db023f97..6f6509bf3 100644 --- a/cmd/neofs-cli/modules/storagegroup/get.go +++ b/cmd/neofs-cli/modules/storagegroup/get.go @@ -15,11 +15,6 @@ import ( "github.com/spf13/cobra" ) -const ( - sgIDFlag = "id" - sgRawFlag = "raw" -) - var sgID string var sgGetCmd = &cobra.Command{ @@ -34,8 +29,8 @@ func initSGGetCmd() { flags := sgGetCmd.Flags() - flags.String("cid", "", "Container ID") - _ = sgGetCmd.MarkFlagRequired("cid") + flags.String(cidFlag, "", "Container ID") + _ = sgGetCmd.MarkFlagRequired(cidFlag) flags.StringVarP(&sgID, sgIDFlag, "", "", "storage group identifier") _ = sgGetCmd.MarkFlagRequired(sgIDFlag) diff --git a/cmd/neofs-cli/modules/storagegroup/list.go b/cmd/neofs-cli/modules/storagegroup/list.go index 23c1fa1ea..e24211dd2 100644 --- a/cmd/neofs-cli/modules/storagegroup/list.go +++ b/cmd/neofs-cli/modules/storagegroup/list.go @@ -22,8 +22,8 @@ var sgListCmd = &cobra.Command{ func initSGListCmd() { commonflags.Init(sgListCmd) - sgListCmd.Flags().String("cid", "", "Container ID") - _ = sgListCmd.MarkFlagRequired("cid") + sgListCmd.Flags().String(cidFlag, "", "Container ID") + _ = sgListCmd.MarkFlagRequired(cidFlag) } func listSG(cmd *cobra.Command, _ []string) { diff --git a/cmd/neofs-cli/modules/storagegroup/put.go b/cmd/neofs-cli/modules/storagegroup/put.go index e754030ce..d70398883 100644 --- a/cmd/neofs-cli/modules/storagegroup/put.go +++ b/cmd/neofs-cli/modules/storagegroup/put.go @@ -36,8 +36,8 @@ func initSGPutCmd() { flags := sgPutCmd.Flags() - flags.String("cid", "", "Container ID") - _ = sgPutCmd.MarkFlagRequired("cid") + flags.String(cidFlag, "", "Container ID") + _ = sgPutCmd.MarkFlagRequired(cidFlag) flags.StringSliceVarP(&sgMembers, sgMembersFlag, "m", nil, "ID list of storage group members") _ = sgPutCmd.MarkFlagRequired(sgMembersFlag) diff --git a/cmd/neofs-cli/modules/storagegroup/root.go b/cmd/neofs-cli/modules/storagegroup/root.go index 0d97e6e68..534bbffe0 100644 --- a/cmd/neofs-cli/modules/storagegroup/root.go +++ b/cmd/neofs-cli/modules/storagegroup/root.go @@ -19,6 +19,12 @@ var Cmd = &cobra.Command{ }, } +const ( + sgIDFlag = "id" + sgRawFlag = "raw" + cidFlag = "cid" +) + func init() { storageGroupChildCommands := []*cobra.Command{ sgPutCmd, diff --git a/cmd/neofs-cli/modules/storagegroup/util.go b/cmd/neofs-cli/modules/storagegroup/util.go index 4fd4c2f0b..3e9093d8d 100644 --- a/cmd/neofs-cli/modules/storagegroup/util.go +++ b/cmd/neofs-cli/modules/storagegroup/util.go @@ -20,11 +20,9 @@ func readObjectAddress(cmd *cobra.Command, cnr *cid.ID, obj *oid.ID) oid.Address } func readCID(cmd *cobra.Command, id *cid.ID) { - const flag = "cid" - - f := cmd.Flag(flag) + f := cmd.Flag(cidFlag) if f == nil { - common.ExitOnErr(cmd, "", fmt.Errorf("missing container flag (%s)", flag)) + common.ExitOnErr(cmd, "", fmt.Errorf("missing container flag (%s)", cidFlag)) return }