refactor: Moved table function to fornatter

Makes more sense for it to be in there
This commit is contained in:
Roxie Gibson 2021-07-18 03:24:48 +01:00
parent 2134f57dd0
commit d1f7e8011d
Signed by untrusted user: roxxers
GPG Key ID: 5D0140EDEE123F4D
2 changed files with 22 additions and 23 deletions

View File

@ -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
}

View File

@ -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
}