Skip to content

Commit

Permalink
use iostreams.ColorScheme() instead of aurora to avoid metachars in t…
Browse files Browse the repository at this point in the history
…erms that do not support them
  • Loading branch information
tvdfly authored and dangra committed Jan 25, 2023
1 parent c1cbd1d commit f637ae8
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions internal/command/deploy/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/Khan/genqlient/graphql"
"github.com/jpillora/backoff"
"github.com/logrusorgru/aurora"
"github.com/morikuni/aec"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/client"
Expand Down Expand Up @@ -45,6 +44,7 @@ type machineDeployment struct {
gqlClient graphql.Client
flapsClient *flaps.Client
io *iostreams.IOStreams
colorize *iostreams.ColorScheme
app *api.AppCompact
appConfig *app.Config
img *imgsrc.DeploymentImage
Expand Down Expand Up @@ -87,6 +87,7 @@ type LeasableMachine interface {
type leasableMachine struct {
flapsClient *flaps.Client
io *iostreams.IOStreams
colorize *iostreams.ColorScheme

lock sync.RWMutex
machine *api.Machine
Expand All @@ -98,6 +99,7 @@ func NewLeasableMachine(flapsClient *flaps.Client, io *iostreams.IOStreams, mach
return &leasableMachine{
flapsClient: flapsClient,
io: io,
colorize: io.ColorScheme(),
machine: machine,
}
}
Expand Down Expand Up @@ -133,13 +135,13 @@ func (lm *leasableMachine) logClearLinesAbove(count int) {
}

func (lm *leasableMachine) logStatus(desired, current string) {
cur := aurora.Green(current)
cur := lm.colorize.Green(current)
if desired != current {
cur = aurora.Yellow(current)
cur = lm.colorize.Yellow(current)
}
fmt.Fprintf(lm.io.ErrOut, " Waiting for %s to have state %s, currently: %s\n",
aurora.Bold(lm.Machine().ID),
aurora.Green(desired),
lm.colorize.Bold(lm.Machine().ID),
lm.colorize.Green(desired),
cur,
)
}
Expand All @@ -148,12 +150,12 @@ func (lm *leasableMachine) logHealthCheckStatus(status *api.HealthCheckStatus) {
if status == nil {
return
}
resColor := aurora.Green
resColor := lm.colorize.Green
if status.Passing != status.Total {
resColor = aurora.Yellow
resColor = lm.colorize.Yellow
}
fmt.Fprintf(lm.io.ErrOut, " Waiting for %s to become healthy: %s\n",
aurora.Bold(lm.Machine().ID),
lm.colorize.Bold(lm.Machine().ID),
resColor(fmt.Sprintf("%d/%d", status.Passing, status.Total)),
)
}
Expand Down Expand Up @@ -263,8 +265,8 @@ func (lm *leasableMachine) WaitForEventTypeAfterType(ctx context.Context, eventT
}
lm.logClearLinesAbove(1)
fmt.Fprintf(lm.io.ErrOut, " Waiting for %s to get %s event\n",
aurora.Bold(lm.Machine().ID),
aurora.Yellow(eventType1),
lm.colorize.Bold(lm.Machine().ID),
lm.colorize.Yellow(eventType1),
)
for {
updateMachine, err := lm.flapsClient.Get(waitCtx, lm.Machine().ID)
Expand Down Expand Up @@ -457,10 +459,12 @@ func NewMachineDeployment(ctx context.Context, args MachineDeploymentArgs) (Mach
if appConfig.Deploy != nil {
releaseCmd = appConfig.Deploy.ReleaseCommand
}
io := iostreams.FromContext(ctx)
md := &machineDeployment{
gqlClient: client.FromContext(ctx).API().GenqClient,
flapsClient: flapsClient,
io: iostreams.FromContext(ctx),
io: io,
colorize: io.ColorScheme(),
app: app,
appConfig: appConfig,
img: img,
Expand Down Expand Up @@ -518,12 +522,12 @@ func (md *machineDeployment) runReleaseCommand(ctx context.Context) error {
return fmt.Errorf("error get release_command machine %s exit code: %w", releaseCmdMachine.Machine().ID, err)
}
if exitCode != 0 {
fmt.Fprintf(md.io.ErrOut, "Error release_command failed running on machine %s with exit code %d. Check the logs at: https://fly.io/apps/%s/monitoring\n",
aurora.Bold(releaseCmdMachine.Machine().ID), aurora.Red(exitCode), md.app.Name)
fmt.Fprintf(md.io.ErrOut, "Error release_command failed running on machine %s with exit code %s. Check the logs at: https://fly.io/apps/%s/monitoring\n",
md.colorize.Bold(releaseCmdMachine.Machine().ID), md.colorize.Red(strconv.Itoa(exitCode)), md.app.Name)
return fmt.Errorf("error release_command machine %s exited with non-zero status of %d", releaseCmdMachine.Machine().ID, exitCode)
}
md.logClearLinesAbove(1)
fmt.Fprintf(md.io.ErrOut, " release_command %s completed successfully\n", aurora.Bold(releaseCmdMachine.Machine().ID))
fmt.Fprintf(md.io.ErrOut, " release_command %s completed successfully\n", md.colorize.Bold(releaseCmdMachine.Machine().ID))
return nil
}

Expand Down Expand Up @@ -557,7 +561,7 @@ func (md *machineDeployment) DeployMachinesApp(ctx context.Context) error {
return err
}

fmt.Fprintf(io.Out, "Deploying %s app with %s strategy\n", aurora.Bold(md.app.Name), md.strategy)
fmt.Fprintf(io.Out, "Deploying %s app with %s strategy\n", md.colorize.Bold(md.app.Name), md.strategy)

// FIXME: handle deploy strategy: rolling, immediate, canary, bluegreen

Expand Down Expand Up @@ -614,7 +618,7 @@ func (md *machineDeployment) DeployMachinesApp(ctx context.Context) error {
launchInput.Config.Mounts[0].Path = md.volumeDestination
}

fmt.Fprintf(io.ErrOut, " Updating %s\n", aurora.Bold(m.Machine().ID))
fmt.Fprintf(io.ErrOut, " Updating %s\n", md.colorize.Bold(m.Machine().ID))
err := m.Update(ctx, launchInput)
if err != nil {
if md.strategy != "immediate" {
Expand Down

0 comments on commit f637ae8

Please sign in to comment.