2022-05-23 15:48:01 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2022-06-01 12:42:28 +00:00
|
|
|
"encoding/hex"
|
2022-05-26 06:41:17 +00:00
|
|
|
"strconv"
|
|
|
|
"time"
|
2022-05-23 15:48:01 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/checksum"
|
2022-06-01 12:42:28 +00:00
|
|
|
"github.com/spf13/cobra"
|
2022-05-23 15:48:01 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PrintVerbose prints to the stdout if the commonflags.Verbose flag is on.
|
2023-02-21 11:42:45 +00:00
|
|
|
func PrintVerbose(cmd *cobra.Command, format string, a ...any) {
|
2022-05-23 15:48:01 +00:00
|
|
|
if viper.GetBool(commonflags.Verbose) {
|
2022-12-27 09:36:30 +00:00
|
|
|
cmd.Printf(format+"\n", a...)
|
2022-05-23 15:48:01 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-26 06:41:17 +00:00
|
|
|
|
|
|
|
// PrettyPrintUnixTime interprets s as unix timestamp and prints it as
|
|
|
|
// a date. Is s is invalid, "malformed" is returned.
|
|
|
|
func PrettyPrintUnixTime(s string) string {
|
|
|
|
unixTime, err := strconv.ParseInt(s, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return "malformed"
|
|
|
|
}
|
|
|
|
|
|
|
|
timestamp := time.Unix(unixTime, 0)
|
|
|
|
|
|
|
|
return timestamp.String()
|
|
|
|
}
|
2022-06-01 12:42:28 +00:00
|
|
|
|
|
|
|
// PrintChecksum prints checksum.
|
|
|
|
func PrintChecksum(cmd *cobra.Command, name string, recv func() (checksum.Checksum, bool)) {
|
|
|
|
var strVal string
|
|
|
|
|
|
|
|
cs, csSet := recv()
|
|
|
|
if csSet {
|
|
|
|
strVal = hex.EncodeToString(cs.Value())
|
|
|
|
} else {
|
|
|
|
strVal = "<empty>"
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Printf("%s: %s\n", name, strVal)
|
|
|
|
}
|