[#1402] cli: Add cid flag constant

Also, move common flag constants in `root` file of the `storagegroup`
package.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-06-20 19:33:34 +03:00 committed by fyrchik
parent 6f2363cf31
commit bc5882fc89
6 changed files with 16 additions and 17 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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) {

View file

@ -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)

View file

@ -19,6 +19,12 @@ var Cmd = &cobra.Command{
},
}
const (
sgIDFlag = "id"
sgRawFlag = "raw"
cidFlag = "cid"
)
func init() {
storageGroupChildCommands := []*cobra.Command{
sgPutCmd,

View file

@ -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
}