Skip to content

Commit 73fd1ea

Browse files
committed
chore: skip rendering group on error
1 parent 92193bb commit 73fd1ea

1 file changed

Lines changed: 53 additions & 70 deletions

File tree

internal/status/status.go

Lines changed: 53 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"sync"
1515
"time"
1616

17+
"github.com/Netflix/go-env"
1718
"github.com/docker/docker/api/types"
1819
"github.com/docker/docker/api/types/container"
1920
"github.com/go-errors/errors"
@@ -46,25 +47,6 @@ type CustomName struct {
4647
StorageS3Region string `env:"storage.s3_region,default=S3_PROTOCOL_REGION"`
4748
}
4849

49-
type OutputType string
50-
51-
const (
52-
Text OutputType = "text"
53-
Link OutputType = "link"
54-
Key OutputType = "key"
55-
)
56-
57-
type OutputItem struct {
58-
Label string
59-
Value string
60-
Type OutputType
61-
}
62-
63-
type OutputGroup struct {
64-
Name string
65-
Items []OutputItem
66-
}
67-
6850
func (c *CustomName) toValues(exclude ...string) map[string]string {
6951
values := map[string]string{
7052
c.DbURL: fmt.Sprintf("postgresql://%s@%s:%d/postgres", url.UserPassword("postgres", utils.Config.Db.Password), utils.Config.Hostname, utils.Config.Db.Port),
@@ -236,25 +218,11 @@ func printStatus(names CustomName, format string, w io.Writer, exclude ...string
236218
}
237219

238220
func PrettyPrint(w io.Writer, exclude ...string) {
239-
names := CustomName{
240-
ApiURL: "API_URL",
241-
RestURL: "REST_URL",
242-
GraphqlURL: "GRAPHQL_URL",
243-
FunctionsURL: "FUNCTIONS_URL",
244-
StorageS3URL: "STORAGE_S3_URL",
245-
McpURL: "MCP_URL",
246-
DbURL: "DB_URL",
247-
StudioURL: "STUDIO_URL",
248-
InbucketURL: "INBUCKET_URL",
249-
MailpitURL: "MAILPIT_URL",
250-
PublishableKey: "PUBLISHABLE_KEY",
251-
SecretKey: "SECRET_KEY",
252-
JWTSecret: "JWT_SECRET",
253-
AnonKey: "ANON_KEY",
254-
ServiceRoleKey: "SERVICE_ROLE_KEY",
255-
StorageS3AccessKeyId: "S3_PROTOCOL_ACCESS_KEY_ID",
256-
StorageS3SecretAccessKey: "S3_PROTOCOL_SECRET_ACCESS_KEY",
257-
StorageS3Region: "S3_PROTOCOL_REGION",
221+
logger := utils.GetDebugLogger()
222+
223+
names := CustomName{}
224+
if err := env.Unmarshal(env.EnvSet{}, &names); err != nil {
225+
fmt.Fprintln(logger, err)
258226
}
259227
values := names.toValues(exclude...)
260228

@@ -301,22 +269,34 @@ func PrettyPrint(w io.Writer, exclude ...string) {
301269
}
302270

303271
for _, group := range groups {
304-
// ensure at least one item in the group is non-empty
305-
shouldPrint := false
306-
for _, item := range group.Items {
307-
if item.Value != "" {
308-
shouldPrint = true
309-
break
310-
}
311-
}
312-
if shouldPrint {
313-
printTable(w, group.Name, group.Items)
272+
if err := group.printTable(w); err != nil {
273+
fmt.Fprintln(logger, err)
274+
} else {
314275
fmt.Fprintln(w)
315276
}
316277
}
317278
}
318279

319-
func printTable(w io.Writer, title string, rows []OutputItem) {
280+
type OutputType string
281+
282+
const (
283+
Text OutputType = "text"
284+
Link OutputType = "link"
285+
Key OutputType = "key"
286+
)
287+
288+
type OutputItem struct {
289+
Label string
290+
Value string
291+
Type OutputType
292+
}
293+
294+
type OutputGroup struct {
295+
Name string
296+
Items []OutputItem
297+
}
298+
299+
func (g *OutputGroup) printTable(w io.Writer) error {
320300
table := tablewriter.NewTable(w,
321301
// Rounded corners
322302
tablewriter.WithSymbols(tw.NewSymbols(tw.StyleRounded)),
@@ -361,33 +341,36 @@ func printTable(w io.Writer, title string, rows []OutputItem) {
361341
},
362342
},
363343
}),
364-
)
365-
366-
// Set title as header (merged across all columns)
367-
table.Header(title, title)
368344

369-
var appendError error
345+
// Set title as header (merged across all columns)
346+
tablewriter.WithHeader([]string{g.Name, g.Name}),
347+
)
370348

371349
// Add data rows with values colored based on type
372-
for _, row := range rows {
373-
if row.Value != "" {
374-
switch row.Type {
375-
case Link:
376-
appendError = table.Append(row.Label, utils.Aqua(row.Value))
377-
case Key:
378-
appendError = table.Append(row.Label, utils.Yellow(row.Value))
379-
case Text:
380-
appendError = table.Append(row.Label, row.Value)
381-
}
350+
shouldRender := false
351+
for _, row := range g.Items {
352+
if row.Value == "" {
353+
continue
354+
}
355+
value := row.Value
356+
switch row.Type {
357+
case Link:
358+
value = utils.Aqua(row.Value)
359+
case Key:
360+
value = utils.Yellow(row.Value)
361+
}
362+
if err := table.Append(row.Label, value); err != nil {
363+
return errors.Errorf("failed to append row: %w", err)
382364
}
365+
shouldRender = true
383366
}
384367

385-
if appendError != nil {
386-
fmt.Fprintln(utils.GetDebugLogger(), appendError)
368+
// Ensure at least one item in the group is non-empty
369+
if shouldRender {
370+
if err := table.Render(); err != nil {
371+
return errors.Errorf("failed to render table: %w", err)
372+
}
387373
}
388374

389-
renderError := table.Render()
390-
if renderError != nil {
391-
fmt.Fprintln(utils.GetDebugLogger(), renderError)
392-
}
375+
return nil
393376
}

0 commit comments

Comments
 (0)