Skip to content

Commit

Permalink
pool-list: table renderer will handle linebreaks as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarsa committed Jul 21, 2017
1 parent 371b862 commit 644f429
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
16 changes: 2 additions & 14 deletions tsuru/client/pool.go
Expand Up @@ -80,9 +80,9 @@ func (PoolList) Run(context *cmd.Context, client *cmd.Client) error {
for _, pool := range pools {
teams := ""
if !pool.Public && !pool.Default {
teams = formatToCol(pool.Allowed["team"], 5)
teams = strings.Join(pool.Allowed["team"], ", ")
}
routers := formatToCol(pool.Allowed["router"], 5)
routers := strings.Join(pool.Allowed["router"], ", ")
t.AddRow(cmd.Row([]string{pool.Name, pool.Kind(), pool.GetProvisioner(), teams, routers}))
}
context.Stdout.Write(t.Bytes())
Expand All @@ -97,15 +97,3 @@ 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")
}
27 changes: 13 additions & 14 deletions tsuru/client/pool_test.go
Expand Up @@ -25,20 +25,19 @@ func (s *S) TestPoolListRun(c *check.C) {
Stdout: &stdout,
Stderr: &stderr,
}
expected := `+------------+---------+-------------+-----------------------------------+----------------+
| Pool | Kind | Provisioner | Teams | Routers |
+------------+---------+-------------+-----------------------------------+----------------+
| pool0 | | default | admin | |
+------------+---------+-------------+-----------------------------------+----------------+
| pool2 | | default | admin | |
+------------+---------+-------------+-----------------------------------+----------------+
| pool3 | | swarm | admin, team1, team2, team3, team4 | hipache, planb |
| | | | team5 | |
+------------+---------+-------------+-----------------------------------+----------------+
| pool1 | default | default | | |
+------------+---------+-------------+-----------------------------------+----------------+
| theonepool | public | default | | hipache |
+------------+---------+-------------+-----------------------------------+----------------+
expected := `+------------+---------+-------------+------------------------------------------+----------------+
| Pool | Kind | Provisioner | Teams | Routers |
+------------+---------+-------------+------------------------------------------+----------------+
| pool0 | | default | admin | |
+------------+---------+-------------+------------------------------------------+----------------+
| pool2 | | default | admin | |
+------------+---------+-------------+------------------------------------------+----------------+
| pool3 | | swarm | admin, team1, team2, team3, team4, team5 | hipache, planb |
+------------+---------+-------------+------------------------------------------+----------------+
| pool1 | default | default | | |
+------------+---------+-------------+------------------------------------------+----------------+
| theonepool | public | default | | hipache |
+------------+---------+-------------+------------------------------------------+----------------+
`
client := cmd.NewClient(&http.Client{Transport: &cmdtest.Transport{Message: result, Status: http.StatusOK}}, nil, manager)
command := PoolList{}
Expand Down

0 comments on commit 644f429

Please sign in to comment.