abra/cli/formatter.go

31 lines
677 B
Go
Raw Normal View History

package cli
import (
"fmt"
"strings"
"time"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/go-units"
)
func shortenID(str string) string {
return str[:12]
}
func truncate(str string) string {
return fmt.Sprintf(`"%s"`, formatter.Ellipsis(str, 19))
}
// removeSha remove image sha from a string that are added in some docker outputs
func removeSha(str string) string {
return strings.Split(str, "@")[0]
}
// humanDuration from docker/cli RunningFor() to be accessable outside of the class
func humanDuration(timestamp int64) string {
date := time.Unix(timestamp, 0)
now := time.Now().UTC()
return units.HumanDuration(now.Sub(date)) + " ago"
}