frostfs-node/cmd/neofs-lens/internal/common.go
Leonard Lyubich 4d7915a366 [] neofs-lens: Implement object listing
Implement `list` command for object listing. Support listing of the objects
from write-cache and blobovnicza.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-10-05 10:51:10 +03:00

31 lines
606 B
Go

package common
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
// Errf returns formatted error in errFmt format if err is not nil.
func Errf(errFmt string, err error) error {
if err == nil {
return nil
}
return fmt.Errorf(errFmt, err)
}
// ExitOnErr calls exitOnErrCode with code 1.
func ExitOnErr(cmd *cobra.Command, err error) {
exitOnErrCode(cmd, err, 1)
}
// exitOnErrCode prints error via cmd and calls os.Exit with passed exit code.
// Does nothing if err is nil.
func exitOnErrCode(cmd *cobra.Command, err error, code int) {
if err != nil {
cmd.PrintErrln(err)
os.Exit(code)
}
}