client: format pool-list table
This limits the number of teams and routers to 5 per line
and also shows a wildcard instead of listing every team when
the router is public.
@@ -65,7 +65,7 @@ func (PoolList) Run(context *cmd.Context, client *cmd.Client) error {
if err != nil {
return err
}
- t := cmd.Table{Headers: cmd.Row([]string{"Pool", "Kind", "Provisioner", "Teams", "Routers"})}
+ t := cmd.Table{Headers: cmd.Row([]string{"Pool", "Kind", "Provisioner", "Teams", "Routers"}), LineSeparator: true}
if resp.StatusCode == http.StatusNoContent {
context.Stdout.Write(t.Bytes())
return nil
@@ -78,8 +78,11 @@ func (PoolList) Run(context *cmd.Context, client *cmd.Client) error {
}
sort.Sort(poolEntriesList(pools))
for _, pool := range pools {
- teams := strings.Join(pool.Allowed["team"], ", ")
- routers := strings.Join(pool.Allowed["router"], ", ")
+ teams := "*"
+ if !pool.Public {
+ teams = formatToCol(pool.Allowed["team"], 5)
+ }
+ routers := formatToCol(pool.Allowed["router"], 5)
t.AddRow(cmd.Row([]string{pool.Name, pool.Kind(), pool.GetProvisioner(), teams, routers}))
}
context.Stdout.Write(t.Bytes())
@@ -94,3 +97,15 @@ func (PoolList) Info() *cmd.Info {
MinArgs: 0,
}
}
+
+func formatToCol(values []string, itemsPerLine int) string {
+ var lines []string
+ for i := 0; i < len(values); i += 5 {
+ endIdx := i + 5
+ if endIdx > len(values) {
+ endIdx = len(values)
+ }
+ lines = append(lines, strings.Join(values[i:endIdx], ", "))
+ }
+ return strings.Join(lines, "\n")
+}
