init
This commit is contained in:
commit
49b24e5773
22 changed files with 1499 additions and 0 deletions
49
cmd/users/users.go
Normal file
49
cmd/users/users.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
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"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue