feat: added util formatting for the cil

This commit is contained in:
2021-07-17 09:27:34 +01:00
parent be46695d82
commit b9e06f2310
3 changed files with 36 additions and 0 deletions

30
cli/formatter.go Normal file
View File

@ -0,0 +1,30 @@
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"
}