Skip to content

Commit

Permalink
Merge pull request zeabur#160 from zeabur/yuaanlin/print-plan-table-m…
Browse files Browse the repository at this point in the history
…ultiline
  • Loading branch information
yuaanlin authored Oct 16, 2023
2 parents 01bc4c7 + dc263cd commit cd043db
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 cd043db

Please sign in to comment.