[#1323] neofs-cli: Reuse JSON flag for multiple commands

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-23 16:52:47 +03:00 committed by fyrchik
parent e812d78672
commit 9816d59ec0
12 changed files with 17 additions and 13 deletions

View file

@ -0,0 +1,3 @@
package commonflags
const JSON = "json"

View file

@ -28,7 +28,7 @@ const (
expireAtFlag = "expire-at"
ownerFlag = "owner"
outFlag = "out"
jsonFlag = "json"
jsonFlag = commonflags.JSON
)
var createCmd = &cobra.Command{

View file

@ -80,7 +80,7 @@ func initContainerInfoCmd() {
flags.StringVar(&containerID, "cid", "", "container ID")
flags.StringVar(&containerPathTo, "to", "", "path to dump encoded container")
flags.StringVar(&containerPathFrom, "from", "", "path to file with encoded container")
flags.BoolVar(&containerJSON, "json", false, "print or dump container in JSON format")
flags.BoolVar(&containerJSON, commonflags.JSON, false, "print or dump container in JSON format")
}
type stringWriter cobra.Command

View file

@ -59,5 +59,5 @@ func initContainerGetEACLCmd() {
flags.StringVar(&containerID, "cid", "", "container ID")
flags.StringVar(&containerPathTo, "to", "", "path to dump encoded container (default: binary encoded)")
flags.BoolVar(&containerJSON, "json", false, "encode EACL table in json format")
flags.BoolVar(&containerJSON, commonflags.JSON, false, "encode EACL table in json format")
}

View file

@ -11,7 +11,7 @@ import (
)
const (
netmapSnapshotJSONFlag = "json"
netmapSnapshotJSONFlag = commonflags.JSON
)
var snapshotCmd = &cobra.Command{

View file

@ -11,7 +11,7 @@ import (
"github.com/spf13/cobra"
)
const nodeInfoJSONFlag = "json"
const nodeInfoJSONFlag = commonflags.JSON
var nodeInfoCmd = &cobra.Command{
Use: "nodeinfo",

View file

@ -115,7 +115,7 @@ func getObject(cmd *cobra.Command, _ []string) {
}
func strictOutput(cmd *cobra.Command) bool {
toJSON, _ := cmd.Flags().GetBool("json")
toJSON, _ := cmd.Flags().GetBool(commonflags.JSON)
toProto, _ := cmd.Flags().GetBool("proto")
return toJSON || toProto
}

View file

@ -40,7 +40,7 @@ func initObjectHeadCmd() {
flags.String("file", "", "File to write header to. Default: stdout.")
flags.Bool("main-only", false, "Return only main fields")
flags.Bool("json", false, "Marshal output in JSON")
flags.Bool(commonflags.JSON, false, "Marshal output in JSON")
flags.Bool("proto", false, "Marshal output in Protobuf")
flags.Bool(rawFlag, false, rawFlagDesc)
}
@ -96,7 +96,7 @@ func saveAndPrintHeader(cmd *cobra.Command, obj *object.Object, filename string)
}
func marshalHeader(cmd *cobra.Command, hdr *object.Object) ([]byte, error) {
toJSON, _ := cmd.Flags().GetBool("json")
toJSON, _ := cmd.Flags().GetBool(commonflags.JSON)
toProto, _ := cmd.Flags().GetBool("proto")
switch {
case toJSON && toProto:

View file

@ -120,7 +120,7 @@ func printSplitInfo(cmd *cobra.Command, info *object.SplitInfo) {
}
func marshalSplitInfo(cmd *cobra.Command, info *object.SplitInfo) ([]byte, error) {
toJSON, _ := cmd.Flags().GetBool("json")
toJSON, _ := cmd.Flags().GetBool(commonflags.JSON)
toProto, _ := cmd.Flags().GetBool("proto")
switch {
case toJSON && toProto:

View file

@ -19,7 +19,7 @@ import (
const (
lifetimeFlag = "lifetime"
outFlag = "out"
jsonFlag = "json"
jsonFlag = commonflags.JSON
)
const defaultLifetime = 10

View file

@ -6,6 +6,7 @@ import (
"os"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/spf13/cobra"
)
@ -23,13 +24,13 @@ func initConvertEACLCmd() {
_ = convertEACLCmd.MarkFlagRequired("from")
flags.String("to", "", "File to dump extended ACL table (default: binary encoded)")
flags.Bool("json", false, "Dump extended ACL table in JSON encoding")
flags.Bool(commonflags.JSON, false, "Dump extended ACL table in JSON encoding")
}
func convertEACLTable(cmd *cobra.Command, _ []string) {
pathFrom := cmd.Flag("from").Value.String()
to := cmd.Flag("to").Value.String()
jsonFlag, _ := cmd.Flags().GetBool("json")
jsonFlag, _ := cmd.Flags().GetBool(commonflags.JSON)
table := common.ReadEACL(cmd, pathFrom)

View file

@ -10,7 +10,7 @@ import (
)
const (
signBearerJSONFlag = "json"
signBearerJSONFlag = commonflags.JSON
)
var signBearerCmd = &cobra.Command{