mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
feat: add generic table formatter (#3415)
This commit is contained in:
27
cli/users.go
27
cli/users.go
@ -1,12 +1,8 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/coder/coder/cli/cliui"
|
||||
"github.com/coder/coder/codersdk"
|
||||
)
|
||||
|
||||
@ -25,26 +21,3 @@ func users() *cobra.Command {
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// displayUsers will return a table displaying all users passed in.
|
||||
// filterColumns must be a subset of the user fields and will determine which
|
||||
// columns to display
|
||||
func displayUsers(filterColumns []string, users ...codersdk.User) string {
|
||||
tableWriter := cliui.Table()
|
||||
header := table.Row{"id", "username", "email", "created at", "status"}
|
||||
tableWriter.AppendHeader(header)
|
||||
tableWriter.SetColumnConfigs(cliui.FilterTableColumns(header, filterColumns))
|
||||
tableWriter.SortBy([]table.SortBy{{
|
||||
Name: "username",
|
||||
}})
|
||||
for _, user := range users {
|
||||
tableWriter.AppendRow(table.Row{
|
||||
user.ID.String(),
|
||||
user.Username,
|
||||
user.Email,
|
||||
user.CreatedAt.Format(time.Stamp),
|
||||
user.Status,
|
||||
})
|
||||
}
|
||||
return tableWriter.Render()
|
||||
}
|
||||
|
Reference in New Issue
Block a user