forked from coop-cloud/abra
39 lines
868 B
Go
39 lines
868 B
Go
package formatter
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/docker/cli/cli/command/formatter"
|
|
"github.com/docker/go-units"
|
|
"github.com/olekukonko/tablewriter"
|
|
)
|
|
|
|
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 accessible 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"
|
|
}
|
|
|
|
func CreateTable(columns []string) *tablewriter.Table {
|
|
table := tablewriter.NewWriter(os.Stdout)
|
|
table.SetHeader(columns)
|
|
return table
|
|
}
|