Move util.NewTabWriter to common.NewTabWriter

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-06 00:04:10 -04:00
parent 1830fea7b7
commit 7589f97105
5 changed files with 20 additions and 18 deletions

View File

@ -53,7 +53,7 @@ var endpointListCmd = &cobra.Command{
} }
} else { } else {
// Print all endpoint fields as a table // Print all endpoint fields as a table
writer, err := util.NewTabWriter([]string{ writer, err := common.NewTabWriter([]string{
"ENDPOINT ID", "ENDPOINT ID",
"NAME", "NAME",
"TYPE", "TYPE",

View File

@ -43,7 +43,7 @@ var stackListCmd = &cobra.Command{
} }
} else { } else {
// Print all stack fields as a table // Print all stack fields as a table
writer, err := util.NewTabWriter([]string{ writer, err := common.NewTabWriter([]string{
"STACK ID", "STACK ID",
"NAME", "NAME",
"TYPE", "TYPE",

View File

@ -5,8 +5,6 @@ import (
"os" "os"
"text/template" "text/template"
"github.com/greenled/portainer-stack-utils/util"
"github.com/greenled/portainer-stack-utils/common" "github.com/greenled/portainer-stack-utils/common"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -32,7 +30,7 @@ var statusCmd = &cobra.Command{
fmt.Println() fmt.Println()
} else { } else {
// Print status fields as a table // Print status fields as a table
writer, newTabWriterErr := util.NewTabWriter([]string{ writer, newTabWriterErr := common.NewTabWriter([]string{
"VERSION", "VERSION",
"AUTHENTICATION", "AUTHENTICATION",
"ENDPOINT MANAGEMENT", "ENDPOINT MANAGEMENT",

17
common/printing.go Normal file
View File

@ -0,0 +1,17 @@
package common
import (
"fmt"
"os"
"strings"
"text/tabwriter"
)
func NewTabWriter(headers []string) (*tabwriter.Writer, error) {
writer := tabwriter.NewWriter(os.Stdout, 20, 2, 3, ' ', 0)
_, err := fmt.Fprintln(writer, strings.Join(headers, "\t"))
if err != nil {
return &tabwriter.Writer{}, err
}
return writer, nil
}

View File

@ -1,11 +1,7 @@
package util package util
import ( import (
"fmt"
"log" "log"
"os"
"strings"
"text/tabwriter"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -21,12 +17,3 @@ func PrintDebug(a ...interface{}) {
log.Println(a) log.Println(a)
} }
} }
func NewTabWriter(headers []string) (*tabwriter.Writer, error) {
writer := tabwriter.NewWriter(os.Stdout, 20, 2, 3, ' ', 0)
_, err := fmt.Fprintln(writer, strings.Join(headers, "\t"))
if err != nil {
return &tabwriter.Writer{}, err
}
return writer, nil
}