[#1233] neofs-cli: Respect format flags for SplitInfo
output
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
5c5279688b
commit
5eef0f46c5
1 changed files with 28 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -1096,7 +1097,7 @@ func printSplitInfoErr(cmd *cobra.Command, err error) bool {
|
||||||
ok := errors.As(err, &errSplitInfo)
|
ok := errors.As(err, &errSplitInfo)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
cmd.Println("Object is complex, split information received.")
|
cmd.PrintErrln("Object is complex, split information received.")
|
||||||
printSplitInfo(cmd, errSplitInfo.SplitInfo())
|
printSplitInfo(cmd, errSplitInfo.SplitInfo())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1104,15 +1105,33 @@ func printSplitInfoErr(cmd *cobra.Command, err error) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func printSplitInfo(cmd *cobra.Command, info *object.SplitInfo) {
|
func printSplitInfo(cmd *cobra.Command, info *object.SplitInfo) {
|
||||||
if splitID := info.SplitID(); splitID != nil {
|
bs, err := marshalSplitInfo(cmd, info)
|
||||||
cmd.Println("Split ID:", splitID)
|
exitOnErr(cmd, fmt.Errorf("can't marshal split info: %w", err))
|
||||||
}
|
|
||||||
|
|
||||||
if link := info.Link(); link != nil {
|
cmd.Println(string(bs))
|
||||||
cmd.Println("Linking object:", link)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if last := info.LastPart(); last != nil {
|
func marshalSplitInfo(cmd *cobra.Command, info *object.SplitInfo) ([]byte, error) {
|
||||||
cmd.Println("Last object:", last)
|
toJSON, _ := cmd.Flags().GetBool("json")
|
||||||
|
toProto, _ := cmd.Flags().GetBool("proto")
|
||||||
|
switch {
|
||||||
|
case toJSON && toProto:
|
||||||
|
return nil, errors.New("'--json' and '--proto' flags are mutually exclusive")
|
||||||
|
case toJSON:
|
||||||
|
return info.MarshalJSON()
|
||||||
|
case toProto:
|
||||||
|
return info.Marshal()
|
||||||
|
default:
|
||||||
|
b := bytes.NewBuffer(nil)
|
||||||
|
if splitID := info.SplitID(); splitID != nil {
|
||||||
|
b.WriteString("Split ID: " + splitID.String() + "\n")
|
||||||
|
}
|
||||||
|
if link := info.Link(); link != nil {
|
||||||
|
b.WriteString("Linking object: " + link.String() + "\n")
|
||||||
|
}
|
||||||
|
if last := info.LastPart(); last != nil {
|
||||||
|
b.WriteString("Last object: " + last.String() + "\n")
|
||||||
|
}
|
||||||
|
return b.Bytes(), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue