Move tabwriter to package util
This offloads the "magic numbers" that are used when creating a tabwriter
This commit is contained in:
parent
33fecc360b
commit
be2a61047c
@ -3,11 +3,11 @@ package workflow
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"text/tabwriter"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
|
"github.com/ian-howell/airshipctl/pkg/util"
|
||||||
"github.com/ian-howell/airshipctl/pkg/environment"
|
"github.com/ian-howell/airshipctl/pkg/environment"
|
||||||
wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment"
|
wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment"
|
||||||
)
|
)
|
||||||
@ -29,7 +29,7 @@ func NewWorkflowListCommand(out io.Writer, rootSettings *environment.AirshipCTLS
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(out, 0, 0, 5, ' ', 0)
|
w := util.NewTabWriter(out)
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
fmt.Fprintf(w, "%s\t%s\n", "NAME", "PHASE")
|
fmt.Fprintf(w, "%s\t%s\n", "NAME", "PHASE")
|
||||||
for _, wf := range wflist.Items {
|
for _, wf := range wflist.Items {
|
||||||
|
19
pkg/util/tabwriter.go
Normal file
19
pkg/util/tabwriter.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"text/tabwriter"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
tabwriterMinWidth = 6
|
||||||
|
tabwriterWidth = 4
|
||||||
|
tabwriterPadding = 3
|
||||||
|
tabwriterPadChar = ' '
|
||||||
|
tabwriterFlags = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewTabWriter returns a tabwriter that translates tabbed columns in input into properly aligned text.
|
||||||
|
func NewTabWriter(out io.Writer) *tabwriter.Writer {
|
||||||
|
return tabwriter.NewWriter(out, tabwriterMinWidth, tabwriterWidth, tabwriterPadding, tabwriterPadChar, tabwriterFlags)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user