mirror of
https://github.com/psviderski/uncloud.git
synced 2026-10-08 14:14:52 +00:00
refactor: replace tabwriter with a Table for consistent table rendering across commands
This commit is contained in:
1 parent
e22cdf0b18
commit
636307d3ea
7 files changed
+62
-79
No files matched your search
@@ -3,12 +3,11 @@ package volume
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/psviderski/uncloud/internal/cli"
|
||||
"github.com/psviderski/uncloud/internal/cli/tui"
|
||||
"github.com/psviderski/uncloud/pkg/api"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -86,16 +85,13 @@ func list(ctx context.Context, uncli *cli.CLI, opts listOptions) error {
|
||||
}
|
||||
|
||||
// Print the volumes in a table format.
|
||||
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
|
||||
fmt.Fprintln(tw, "NAME\tDRIVER\tMACHINE")
|
||||
t := tui.NewTable()
|
||||
t.Headers("NAME", "DRIVER", "MACHINE")
|
||||
|
||||
for _, v := range volumes {
|
||||
fmt.Fprintf(tw, "%s\t%s\t%s\n",
|
||||
v.Volume.Name,
|
||||
v.Volume.Driver,
|
||||
v.MachineName,
|
||||
)
|
||||
t.Row(v.Volume.Name, v.Volume.Driver, v.MachineName)
|
||||
}
|
||||
|
||||
return tw.Flush()
|
||||
fmt.Println(t)
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user