Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utils): Print multiline command in plan table #160

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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