diff --git a/cli/common.go b/cli/common.go index b52776e0..13a877b5 100644 --- a/cli/common.go +++ b/cli/common.go @@ -1,9 +1,6 @@ package cli import ( - "os" - - "github.com/olekukonko/tablewriter" "github.com/urfave/cli/v2" ) @@ -187,23 +184,3 @@ var ContextFlag = &cli.StringFlag{ Aliases: []string{"c"}, Destination: &Context, } - -func createTable(columns []string) *tablewriter.Table { - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader(columns) - - // Settings to create very bare tab padded table - table.SetAutoWrapText(false) - table.SetAutoFormatHeaders(true) - table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) - table.SetAlignment(tablewriter.ALIGN_LEFT) - table.SetCenterSeparator("") - table.SetColumnSeparator("") - table.SetRowSeparator("") - table.SetHeaderLine(false) - table.SetBorder(false) - table.SetTablePadding("\t") // pad with tabs - table.SetNoWhiteSpace(true) - table.SetColWidth(1) - return table -} diff --git a/cli/formatter.go b/cli/formatter.go index 32497c79..4a2d0941 100644 --- a/cli/formatter.go +++ b/cli/formatter.go @@ -2,11 +2,13 @@ package cli 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 { @@ -28,3 +30,23 @@ func humanDuration(timestamp int64) string { 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) + + // Settings to create very bare tab padded table + table.SetAutoWrapText(false) + table.SetAutoFormatHeaders(true) + table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) + table.SetAlignment(tablewriter.ALIGN_LEFT) + table.SetCenterSeparator("") + table.SetColumnSeparator("") + table.SetRowSeparator("") + table.SetHeaderLine(false) + table.SetBorder(false) + table.SetTablePadding("\t") // pad with tabs + table.SetNoWhiteSpace(true) + table.SetColWidth(1) + return table +}