filer/cmd/users/users.go
2023-08-25 02:26:44 +02:00

49 lines
732 B
Go

package users
import (
"fmt"
"codeberg.org/u1f320/filer/db"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
)
var Command = &cli.Command{
Name: "users",
Usage: "Manage user accounts",
Action: run,
}
func run(c *cli.Context) error {
db, err := db.New()
if err != nil {
return err
}
users, err := db.GetUsers(c.Context)
if err != nil {
return err
}
table := tablewriter.NewWriter(c.App.Writer)
table.SetHeader([]string{"ID", "Username", "Admin?"})
table.SetBorder(false)
for _, u := range users {
table.Append([]string{
fmt.Sprint(u.ID),
u.Username,
yesNo(u.IsAdmin),
})
}
table.Render()
return nil
}
func yesNo(b bool) string {
if b {
return "yes"
}
return "no"
}