chore: restyle provisioner job output format (#8106)

Reduce colors and formatting to reduce bugs and increase UNIX-feel.
This commit is contained in:
Kyle Carberry 2023-06-20 11:16:27 -05:00 committed by GitHub
parent 823127e761
commit 467b0a1004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 16 deletions

View File

@ -63,7 +63,6 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
var (
currentStage = "Queued"
currentStageStartedAt = time.Now().UTC()
didLogBetweenStage = false
errChan = make(chan error, 1)
job codersdk.ProvisionerJob
@ -71,27 +70,26 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
)
printStage := func() {
_, _ = fmt.Fprintf(writer, DefaultStyles.Prompt.Render("⧗")+"%s\n", DefaultStyles.Field.Render(currentStage))
_, _ = fmt.Fprintf(writer, "==> ⧗ %s\n", currentStage)
}
updateStage := func(stage string, startedAt time.Time) {
if currentStage != "" {
prefix := ""
if !didLogBetweenStage {
prefix = "\033[1A\r"
}
mark := DefaultStyles.Checkmark
mark := "✔"
if job.CompletedAt != nil && job.Status != codersdk.ProvisionerJobSucceeded {
mark = DefaultStyles.Crossmark
mark = "✘"
}
_, _ = fmt.Fprintf(writer, prefix+mark.String()+DefaultStyles.Placeholder.Render(" %s [%dms]")+"\n", currentStage, startedAt.Sub(currentStageStartedAt).Milliseconds())
dur := startedAt.Sub(currentStageStartedAt).Milliseconds()
if dur < 0 {
dur = 0
}
_, _ = fmt.Fprintf(writer, "=== %s %s [%dms]\n", mark, currentStage, dur)
}
if stage == "" {
return
}
currentStage = stage
currentStageStartedAt = startedAt
didLogBetweenStage = false
printStage()
}
@ -129,7 +127,7 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
return
}
}
_, _ = fmt.Fprintf(writer, "\033[2K\r\n"+DefaultStyles.FocusedPrompt.String()+DefaultStyles.Bold.Render("Gracefully canceling...")+"\n\n")
_, _ = fmt.Fprintf(writer, DefaultStyles.FocusedPrompt.String()+DefaultStyles.Bold.Render("Gracefully canceling...")+"\n\n")
err := opts.Cancel()
if err != nil {
errChan <- xerrors.Errorf("cancel: %w", err)
@ -222,10 +220,7 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
jobMutex.Unlock()
continue
}
_, _ = fmt.Fprintf(logOutput, "%s %s\n", DefaultStyles.Placeholder.Render(" "), output)
if !opts.Silent {
didLogBetweenStage = true
}
_, _ = fmt.Fprintf(logOutput, "%s\n", output)
jobMutex.Unlock()
}
}

View File

@ -272,7 +272,7 @@ func main() {
},
})
err := root.Invoke(os.Args[1:]...).Run()
err := root.Invoke(os.Args[1:]...).WithOS().Run()
if err != nil {
_, _ = fmt.Println(err.Error())
os.Exit(1)