Skip to content

Commit

Permalink
Simplify printer
Browse files Browse the repository at this point in the history
  • Loading branch information
aidansteele committed May 29, 2019
1 parent 054b725 commit 323f258
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 38 deletions.
9 changes: 1 addition & 8 deletions cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ var downCmd = &cobra.Command{
region := viper.GetString("region")
profile := viper.GetString("profile")
stackName := viper.GetString("stack-name")
showTimestamps := !viper.GetBool("no-timestamps")
showColor := !viper.GetBool("no-color")
printer := stackit.NewTailPrinterWithOptions(showTimestamps, showColor, cmd.OutOrStderr())
printer := stackit.NewTailPrinter(cmd.OutOrStderr())

events := make(chan stackit.TailStackEvent)

Expand Down Expand Up @@ -63,9 +61,4 @@ var downCmd = &cobra.Command{

func init() {
RootCmd.AddCommand(downCmd)

downCmd.PersistentFlags().Bool("no-timestamps", false, "")
downCmd.PersistentFlags().Bool("no-color", false, "")
viper.BindPFlags(downCmd.PersistentFlags())

}
2 changes: 1 addition & 1 deletion cmd/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func executeChangeSet(ctx context.Context, region, profile, stackName, changeSet
sess := awsSession(profile, region)
sit := stackit.NewStackit(cloudformation.New(sess), sts.New(sess))
events := make(chan stackit.TailStackEvent)
printer := stackit.NewTailPrinterWithOptions(true, true, writer)
printer := stackit.NewTailPrinter(writer)

printerCtx, printerCancel := context.WithCancel(ctx)
defer printerCancel()
Expand Down
2 changes: 1 addition & 1 deletion cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func packageTemplate(ctx context.Context, region, profile, stackName, templatePa
packager := stackit.NewPackager(s3api, sts.New(sess), region)

events := make(chan stackit.TailStackEvent)
printer := stackit.NewTailPrinterWithOptions(true, true, writer)
printer := stackit.NewTailPrinter(writer)

printerCtx, printerCancel := context.WithCancel(ctx)
defer printerCancel()
Expand Down
4 changes: 1 addition & 3 deletions cmd/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ var tailCmd = &cobra.Command{
region := viper.GetString("region")
profile := viper.GetString("profile")
stackName := viper.GetString("stack-name")
showTimestamps := !viper.GetBool("no-timestamps")
showColor := !viper.GetBool("no-color")
printer := stackit.NewTailPrinterWithOptions(showTimestamps, showColor, cmd.OutOrStderr())
printer := stackit.NewTailPrinter(cmd.OutOrStderr())

sess := awsSession(profile, region)
sit := stackit.NewStackit(cloudformation.New(sess), sts.New(sess))
Expand Down
7 changes: 1 addition & 6 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ var upCmd = &cobra.Command{
previousTemplate := viper.GetBool("previous-template")
alwaysSucceed := viper.GetBool("always-succeed")

showTimestamps := !viper.GetBool("no-timestamps")
showColor := !viper.GetBool("no-color")
printer := stackit.NewTailPrinterWithOptions(showTimestamps, showColor, cmd.OutOrStderr())

parsed := parseCLIInput(
serviceRole,
stackPolicy,
Expand All @@ -72,6 +68,7 @@ var upCmd = &cobra.Command{

ctx := context.Background()

printer := stackit.NewTailPrinter(cmd.OutOrStderr())
printerCtx, printerCancel := context.WithCancel(ctx)
defer printerCancel()

Expand Down Expand Up @@ -203,8 +200,6 @@ func init() {
upCmd.PersistentFlags().StringArrayVar(&tags, "tag", []string{}, "")
upCmd.PersistentFlags().StringArrayVar(&notificationArns, "notification-arn", []string{}, "")
upCmd.PersistentFlags().Bool("previous-template", false, "")
upCmd.PersistentFlags().Bool("no-timestamps", false, "")
upCmd.PersistentFlags().Bool("no-color", false, "")
upCmd.PersistentFlags().Bool("always-succeed", false, "Typically stackit will return a nonzero exit code on failure. This disables that.")

viper.BindPFlags(upCmd.PersistentFlags())
Expand Down
22 changes: 3 additions & 19 deletions pkg/stackit/tail_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/fatih/color"
"io"
"os"
"strings"
)

Expand All @@ -14,25 +13,10 @@ type TailPrinter struct {
writer io.Writer
}

func NewTailPrinter() TailPrinter {
return NewTailPrinterWithOptions(true, true, os.Stderr)
}

func NewTailPrinterWithOptions(showTimestamp, showColors bool, writer io.Writer) TailPrinter {
format := ""
if showTimestamp {
format = "[03:04:05]"
}

failureColor := color.New(color.FgRed)

if !showColors {
failureColor = nil
}

func NewTailPrinter(writer io.Writer) TailPrinter {
return TailPrinter{
timestampFormat: format,
failureColor: failureColor,
timestampFormat: "[03:04:05]",
failureColor: color.New(color.FgRed),
writer: writer,
}
}
Expand Down

0 comments on commit 323f258

Please sign in to comment.