frostfs-node/cmd/frostfs-lens/internal/printers.go
Airat Arifullin 4cb9488a4a
Some checks failed
ci/woodpecker/pr/pre-commit Pipeline was successful
Build / Build Components (1.19) (pull_request) Successful in 2m45s
Build / Build Components (1.20) (pull_request) Successful in 8m1s
Tests and linters / Tests (1.19) (pull_request) Failing after 3m0s
Tests and linters / Tests (1.20) (pull_request) Failing after 3m20s
Tests and linters / Lint (pull_request) Failing after 9m45s
Tests and linters / Tests with -race (pull_request) Failing after 4m38s
Tests and linters / Staticcheck (pull_request) Failing after 9m4s
[#XX] types: Refactor imported SDK and API types
Signed-off-by: Airat Arifullin a.arifullin@yadro.com
2023-07-14 11:20:08 +03:00

65 lines
1.5 KiB
Go

package common
import (
"os"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"github.com/spf13/cobra"
)
// PrintObjectHeader prints passed object's header fields via
// the passed cobra command. Does nothing with the payload.
func PrintObjectHeader(cmd *cobra.Command, h objectSDK.Object) {
cmd.Println("Version:", h.Version())
cmd.Println("Type:", h.Type())
printContainerID(cmd, h.ContainerID)
printObjectID(cmd, h.ID)
cmd.Println("Owner:", h.OwnerID())
cmd.Println("CreatedAt:", h.CreationEpoch())
cmd.Println("PayloadSize:", h.PayloadSize())
cmd.Println("Attributes:")
for _, attr := range h.Attributes() {
cmd.Printf(" %s: %s\n", attr.GetKey(), attr.GetValue())
}
}
func printContainerID(cmd *cobra.Command, recv func() (cid.ID, bool)) {
var val string
id, ok := recv()
if ok {
val = id.String()
} else {
val = "<empty>"
}
cmd.Println("CID:", val)
}
func printObjectID(cmd *cobra.Command, recv func() (oid.ID, bool)) {
var val string
id, ok := recv()
if ok {
val = id.String()
} else {
val = "<empty>"
}
cmd.Println("ID:", val)
}
// WriteObjectToFile writes object to the provided path. Does nothing if
// the path is empty.
func WriteObjectToFile(cmd *cobra.Command, path string, data []byte) {
if path == "" {
return
}
ExitOnErr(cmd, Errf("could not write file: %w",
os.WriteFile(path, data, 0644)))
cmd.Printf("\nSaved payload to '%s' file\n", path)
}