Skip to content

Commit

Permalink
feat(utils): Print multiline command in plan table
Browse files Browse the repository at this point in the history
  • Loading branch information
yuaanlin committed Oct 16, 2023
1 parent 77d8608 commit 1787b33
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions pkg/zeaburpack/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,45 @@ const (
// PrintPlanAndMeta prints the build plan and meta in a table format.
func PrintPlanAndMeta(plan types.PlanType, meta types.PlanMeta, printFunc func(log string)) {
table := fmt.Sprintf(
"\n%s╔══════════════════════════ %s%s %s═════════════════════════╗\n",
"\n%s╔══════════════════════════════ %s%s %s═════════════════════════════╗\n",
blue, yellow, "Build Plan", blue,
)

table += fmt.Sprintf(
"%s║%s %-16s %s│%s %-42s %s║%s\n",
"%s║%s %-16s %s│%s %-50s %s║%s\n",
blue, reset, "provider", blue, reset, string(plan), blue, reset,
)

for k, v := range meta {
if v == "" || v == "false" {
continue
}
table += blue + "║───────────────────────────────────────────────────────────────║\n" + reset
table += fmt.Sprintf(
"%s║%s %-16s %s│%s %-42s %s║\n%s",
blue, reset, k, blue, reset, v, blue, reset,
)
table += blue + "║───────────────────────────────────────────────────────────────────────║\n" + reset
if strings.Contains(v, "\n") {
lines := strings.Split(v, "\n")
for i, line := range lines {
if i == 0 {
table += fmt.Sprintf(
"%s║%s %-16s %s│%s %-50s %s║\n",
blue, reset, k, blue, reset, line, blue,
)
continue
}
table += fmt.Sprintf(
"%s║%s %-16s %s│%s %-50s %s║\n",
blue, reset, "", blue, reset, line, blue,
)
}
} else {
table += fmt.Sprintf(
"%s║%s %-16s %s│%s %-50s %s║\n%s",
blue, reset, k, blue, reset, v, blue, reset,
)
}
}

table += fmt.Sprintf(
"%s╚═══════════════════════════════════════════════════════════════╝%s\n",
"%s╚═══════════════════════════════════════════════════════════════════════╝%s\n",
blue, reset,
)

Expand Down

0 comments on commit 1787b33

Please sign in to comment.