Skip to content

Commit

Permalink
lxc/auth: avoid fmt.Sprintf (slow) and avoid strings.Join twice for CSV
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Deziel <[email protected]>
  • Loading branch information
simondeziel committed Jan 20, 2025
1 parent 956b107 commit 3c312ae
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lxc/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1594,10 +1594,12 @@ func (c *cmdPermissionList) run(cmd *cobra.Command, args []string) error {
var rowsAssigned []string
for k, v := range p.entitlementsAssigned {
// Pretty format for tables.
assignedRow := fmt.Sprintf("%s ==> (%s)", k, strings.Join(v, ", "))
var assignedRow string
if c.flagFormat == cli.TableFormatCSV {
// Machine readable format for CSV.
assignedRow = fmt.Sprintf("%s:(%s)", k, strings.Join(v, ","))
assignedRow = k + ":(" + strings.Join(v, ",") + ")"
} else {
assignedRow = k + " ==> (" + strings.Join(v, ", ") + ")"
}

rowsAssigned = append(rowsAssigned, assignedRow)
Expand Down

0 comments on commit 3c312ae

Please sign in to comment.