forked from TrueCloudLab/frostfs-node
[#1323] neofs-cli: Reuse JSON flag for multiple commands
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
e812d78672
commit
9816d59ec0
12 changed files with 17 additions and 13 deletions
3
cmd/neofs-cli/internal/commonflags/json.go
Normal file
3
cmd/neofs-cli/internal/commonflags/json.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
package commonflags
|
||||||
|
|
||||||
|
const JSON = "json"
|
|
@ -28,7 +28,7 @@ const (
|
||||||
expireAtFlag = "expire-at"
|
expireAtFlag = "expire-at"
|
||||||
ownerFlag = "owner"
|
ownerFlag = "owner"
|
||||||
outFlag = "out"
|
outFlag = "out"
|
||||||
jsonFlag = "json"
|
jsonFlag = commonflags.JSON
|
||||||
)
|
)
|
||||||
|
|
||||||
var createCmd = &cobra.Command{
|
var createCmd = &cobra.Command{
|
||||||
|
|
|
@ -80,7 +80,7 @@ func initContainerInfoCmd() {
|
||||||
flags.StringVar(&containerID, "cid", "", "container ID")
|
flags.StringVar(&containerID, "cid", "", "container ID")
|
||||||
flags.StringVar(&containerPathTo, "to", "", "path to dump encoded container")
|
flags.StringVar(&containerPathTo, "to", "", "path to dump encoded container")
|
||||||
flags.StringVar(&containerPathFrom, "from", "", "path to file with 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
|
type stringWriter cobra.Command
|
||||||
|
|
|
@ -59,5 +59,5 @@ func initContainerGetEACLCmd() {
|
||||||
|
|
||||||
flags.StringVar(&containerID, "cid", "", "container ID")
|
flags.StringVar(&containerID, "cid", "", "container ID")
|
||||||
flags.StringVar(&containerPathTo, "to", "", "path to dump encoded container (default: binary encoded)")
|
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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
netmapSnapshotJSONFlag = "json"
|
netmapSnapshotJSONFlag = commonflags.JSON
|
||||||
)
|
)
|
||||||
|
|
||||||
var snapshotCmd = &cobra.Command{
|
var snapshotCmd = &cobra.Command{
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
const nodeInfoJSONFlag = "json"
|
const nodeInfoJSONFlag = commonflags.JSON
|
||||||
|
|
||||||
var nodeInfoCmd = &cobra.Command{
|
var nodeInfoCmd = &cobra.Command{
|
||||||
Use: "nodeinfo",
|
Use: "nodeinfo",
|
||||||
|
|
|
@ -115,7 +115,7 @@ func getObject(cmd *cobra.Command, _ []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func strictOutput(cmd *cobra.Command) bool {
|
func strictOutput(cmd *cobra.Command) bool {
|
||||||
toJSON, _ := cmd.Flags().GetBool("json")
|
toJSON, _ := cmd.Flags().GetBool(commonflags.JSON)
|
||||||
toProto, _ := cmd.Flags().GetBool("proto")
|
toProto, _ := cmd.Flags().GetBool("proto")
|
||||||
return toJSON || toProto
|
return toJSON || toProto
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ func initObjectHeadCmd() {
|
||||||
|
|
||||||
flags.String("file", "", "File to write header to. Default: stdout.")
|
flags.String("file", "", "File to write header to. Default: stdout.")
|
||||||
flags.Bool("main-only", false, "Return only main fields")
|
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("proto", false, "Marshal output in Protobuf")
|
||||||
flags.Bool(rawFlag, false, rawFlagDesc)
|
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) {
|
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")
|
toProto, _ := cmd.Flags().GetBool("proto")
|
||||||
switch {
|
switch {
|
||||||
case toJSON && toProto:
|
case toJSON && toProto:
|
||||||
|
|
|
@ -120,7 +120,7 @@ func printSplitInfo(cmd *cobra.Command, info *object.SplitInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalSplitInfo(cmd *cobra.Command, info *object.SplitInfo) ([]byte, error) {
|
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")
|
toProto, _ := cmd.Flags().GetBool("proto")
|
||||||
switch {
|
switch {
|
||||||
case toJSON && toProto:
|
case toJSON && toProto:
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
const (
|
const (
|
||||||
lifetimeFlag = "lifetime"
|
lifetimeFlag = "lifetime"
|
||||||
outFlag = "out"
|
outFlag = "out"
|
||||||
jsonFlag = "json"
|
jsonFlag = commonflags.JSON
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultLifetime = 10
|
const defaultLifetime = 10
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
"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"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,13 +24,13 @@ func initConvertEACLCmd() {
|
||||||
_ = convertEACLCmd.MarkFlagRequired("from")
|
_ = convertEACLCmd.MarkFlagRequired("from")
|
||||||
|
|
||||||
flags.String("to", "", "File to dump extended ACL table (default: binary encoded)")
|
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) {
|
func convertEACLTable(cmd *cobra.Command, _ []string) {
|
||||||
pathFrom := cmd.Flag("from").Value.String()
|
pathFrom := cmd.Flag("from").Value.String()
|
||||||
to := cmd.Flag("to").Value.String()
|
to := cmd.Flag("to").Value.String()
|
||||||
jsonFlag, _ := cmd.Flags().GetBool("json")
|
jsonFlag, _ := cmd.Flags().GetBool(commonflags.JSON)
|
||||||
|
|
||||||
table := common.ReadEACL(cmd, pathFrom)
|
table := common.ReadEACL(cmd, pathFrom)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
signBearerJSONFlag = "json"
|
signBearerJSONFlag = commonflags.JSON
|
||||||
)
|
)
|
||||||
|
|
||||||
var signBearerCmd = &cobra.Command{
|
var signBearerCmd = &cobra.Command{
|
||||||
|
|
Loading…
Reference in a new issue