fix: use output writer consistently in routes list commands
Route list commands now write through the provided io.Writer instead of stdout, and the remote path returns [] for empty JSON output instead of bypassing the --json flag.
- commit
- 5a98fda9181c6ae81f1e81ed9f04649722c61513
- author
- brice · · 2026-03-14 03:00 UTC
- parent
- 4005e23
- signature
- unsigned
1 file · +12 -12
M internal/adapters/in/cli/routes.go +12 -12
| @@ -140,11 +140,6 @@ func runRoutesListRemote(ctx context.Context, client *remote.Client, jsonOut boo | |||
| 140 | 140 | return fmt.Errorf("failed to list routes: %w", err) | |
| 141 | 141 | } | |
| 142 | 142 | ||
| 143 | - | if len(routes) == 0 { | |
| 144 | - | fmt.Println(styles.Theme.Muted.Render("No routes configured")) | |
| 145 | - | return nil | |
| 146 | - | } | |
| 147 | - | ||
| 148 | 143 | // Get health status for each route (includes container status and HTTP probe) | |
| 149 | 144 | health, _ := client.GetHealth(ctx) | |
| 150 | 145 | if health == nil { | |
| @@ -155,6 +150,11 @@ func runRoutesListRemote(ctx context.Context, client *remote.Client, jsonOut boo | |||
| 155 | 150 | return routesListJSON(out, routes, health) | |
| 156 | 151 | } | |
| 157 | 152 | ||
| 153 | + | if len(routes) == 0 { | |
| 154 | + | _, _ = fmt.Fprintln(out, styles.Theme.Muted.Render("No routes configured")) | |
| 155 | + | return nil | |
| 156 | + | } | |
| 157 | + | ||
| 158 | 158 | const imageColWidth = 35 | |
| 159 | 159 | const networkColWidth = 22 | |
| 160 | 160 | rows := make([][]string, 0, len(routes)) | |
| @@ -210,9 +210,9 @@ func runRoutesListRemote(ctx context.Context, client *remote.Client, jsonOut boo | |||
| 210 | 210 | components.WithRows(rows), | |
| 211 | 211 | ) | |
| 212 | 212 | ||
| 213 | - | fmt.Println(styles.Theme.Title.Render("Routes")) | |
| 214 | - | fmt.Println() | |
| 215 | - | fmt.Println(table.View()) | |
| 213 | + | _, _ = fmt.Fprintln(out, styles.Theme.Title.Render("Routes")) | |
| 214 | + | _, _ = fmt.Fprintln(out) | |
| 215 | + | _, _ = fmt.Fprintln(out, table.View()) | |
| 216 | 216 | ||
| 217 | 217 | return nil | |
| 218 | 218 | } | |
| @@ -278,7 +278,7 @@ func runRoutesListLocal(ctx context.Context, cfgPath string, jsonOut bool, out i | |||
| 278 | 278 | } | |
| 279 | 279 | ||
| 280 | 280 | if len(routes) == 0 { | |
| 281 | - | fmt.Println(styles.Theme.Muted.Render("No routes configured")) | |
| 281 | + | _, _ = fmt.Fprintln(out, styles.Theme.Muted.Render("No routes configured")) | |
| 282 | 282 | return nil | |
| 283 | 283 | } | |
| 284 | 284 | ||
| @@ -299,9 +299,9 @@ func runRoutesListLocal(ctx context.Context, cfgPath string, jsonOut bool, out i | |||
| 299 | 299 | components.WithRows(rows), | |
| 300 | 300 | ) | |
| 301 | 301 | ||
| 302 | - | fmt.Println(styles.Theme.Title.Render("Routes (local)")) | |
| 303 | - | fmt.Println() | |
| 304 | - | fmt.Println(table.View()) | |
| 302 | + | _, _ = fmt.Fprintln(out, styles.Theme.Title.Render("Routes (local)")) | |
| 303 | + | _, _ = fmt.Fprintln(out) | |
| 304 | + | _, _ = fmt.Fprintln(out, table.View()) | |
| 305 | 305 | ||
| 306 | 306 | return nil | |
| 307 | 307 | } | |
| @@ -140,11 +140,6 @@ func runRoutesListRemote(ctx context.Context, client *remote.Client, jsonOut boo | |||||
| 140 | return fmt.Errorf("failed to list routes: %w", err) | 140 | return fmt.Errorf("failed to list routes: %w", err) | ||
| 141 | } | 141 | } | ||
| 142 | 142 | ||||
| 143 | - | if len(routes) == 0 { | |||
| 144 | - | fmt.Println(styles.Theme.Muted.Render("No routes configured")) | |||
| 145 | - | return nil | |||
| 146 | - | } | |||
| 147 | - | ||||
| 148 | // Get health status for each route (includes container status and HTTP probe) | 143 | // Get health status for each route (includes container status and HTTP probe) | ||
| 149 | health, _ := client.GetHealth(ctx) | 144 | health, _ := client.GetHealth(ctx) | ||
| 150 | if health == nil { | 145 | if health == nil { | ||
| @@ -155,6 +150,11 @@ func runRoutesListRemote(ctx context.Context, client *remote.Client, jsonOut boo | |||||
| 155 | return routesListJSON(out, routes, health) | 150 | return routesListJSON(out, routes, health) | ||
| 156 | } | 151 | } | ||
| 157 | 152 | ||||
| 153 | + | if len(routes) == 0 { | |||
| 154 | + | _, _ = fmt.Fprintln(out, styles.Theme.Muted.Render("No routes configured")) | |||
| 155 | + | return nil | |||
| 156 | + | } | |||
| 157 | + | ||||
| 158 | const imageColWidth = 35 | 158 | const imageColWidth = 35 | ||
| 159 | const networkColWidth = 22 | 159 | const networkColWidth = 22 | ||
| 160 | rows := make([][]string, 0, len(routes)) | 160 | rows := make([][]string, 0, len(routes)) | ||
| @@ -210,9 +210,9 @@ func runRoutesListRemote(ctx context.Context, client *remote.Client, jsonOut boo | |||||
| 210 | components.WithRows(rows), | 210 | components.WithRows(rows), | ||
| 211 | ) | 211 | ) | ||
| 212 | 212 | ||||
| 213 | - | fmt.Println(styles.Theme.Title.Render("Routes")) | 213 | + | _, _ = fmt.Fprintln(out, styles.Theme.Title.Render("Routes")) |
| 214 | - | fmt.Println() | 214 | + | _, _ = fmt.Fprintln(out) |
| 215 | - | fmt.Println(table.View()) | 215 | + | _, _ = fmt.Fprintln(out, table.View()) |
| 216 | 216 | ||||
| 217 | return nil | 217 | return nil | ||
| 218 | } | 218 | } | ||
| @@ -278,7 +278,7 @@ func runRoutesListLocal(ctx context.Context, cfgPath string, jsonOut bool, out i | |||||
| 278 | } | 278 | } | ||
| 279 | 279 | ||||
| 280 | if len(routes) == 0 { | 280 | if len(routes) == 0 { | ||
| 281 | - | fmt.Println(styles.Theme.Muted.Render("No routes configured")) | 281 | + | _, _ = fmt.Fprintln(out, styles.Theme.Muted.Render("No routes configured")) |
| 282 | return nil | 282 | return nil | ||
| 283 | } | 283 | } | ||
| 284 | 284 | ||||
| @@ -299,9 +299,9 @@ func runRoutesListLocal(ctx context.Context, cfgPath string, jsonOut bool, out i | |||||
| 299 | components.WithRows(rows), | 299 | components.WithRows(rows), | ||
| 300 | ) | 300 | ) | ||
| 301 | 301 | ||||
| 302 | - | fmt.Println(styles.Theme.Title.Render("Routes (local)")) | 302 | + | _, _ = fmt.Fprintln(out, styles.Theme.Title.Render("Routes (local)")) |
| 303 | - | fmt.Println() | 303 | + | _, _ = fmt.Fprintln(out) |
| 304 | - | fmt.Println(table.View()) | 304 | + | _, _ = fmt.Fprintln(out, table.View()) |
| 305 | 305 | ||||
| 306 | return nil | 306 | return nil | ||
| 307 | } | 307 | } | ||