2020-08-12 16:29:14 +00:00
|
|
|
// Copyright 2020 Vikunja and contriubtors. All rights reserved.
|
|
|
|
//
|
|
|
|
// This file is part of Vikunja.
|
|
|
|
//
|
|
|
|
// Vikunja is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Vikunja is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Vikunja. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.vikunja.io/api/pkg/initialize"
|
|
|
|
"code.vikunja.io/api/pkg/log"
|
|
|
|
"code.vikunja.io/api/pkg/user"
|
2020-08-13 10:18:25 +00:00
|
|
|
"github.com/olekukonko/tablewriter"
|
2020-08-12 16:29:14 +00:00
|
|
|
"github.com/spf13/cobra"
|
2020-08-13 10:18:25 +00:00
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
2020-08-12 16:29:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
userCmd.AddCommand(userListCmd)
|
|
|
|
rootCmd.AddCommand(userCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
var userCmd = &cobra.Command{
|
|
|
|
Use: "user",
|
|
|
|
Short: "Manage users locally through the cli.",
|
|
|
|
}
|
|
|
|
|
|
|
|
var userListCmd = &cobra.Command{
|
|
|
|
Use: "list",
|
|
|
|
Short: "Shows a list of all users on this instance.",
|
|
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
|
|
initialize.FullInit()
|
|
|
|
},
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
users, err := user.ListUsers("")
|
|
|
|
if err != nil {
|
|
|
|
log.Criticalf("Error getting users: %s", err)
|
|
|
|
}
|
2020-08-13 10:18:25 +00:00
|
|
|
|
|
|
|
table := tablewriter.NewWriter(os.Stdout)
|
|
|
|
table.SetHeader([]string{
|
|
|
|
"ID",
|
|
|
|
"Username",
|
|
|
|
"Email",
|
|
|
|
"Active",
|
|
|
|
"Created",
|
|
|
|
"Updated",
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, u := range users {
|
|
|
|
table.Append([]string{
|
|
|
|
strconv.FormatInt(u.ID, 10),
|
|
|
|
u.Username,
|
|
|
|
u.Email,
|
|
|
|
strconv.FormatBool(u.IsActive),
|
|
|
|
u.Created.Format(time.RFC3339),
|
|
|
|
u.Updated.Format(time.RFC3339),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
table.Render()
|
2020-08-12 16:29:14 +00:00
|
|
|
},
|
|
|
|
}
|