vikunja/pkg/cmd/user.go

132 lines
3.1 KiB
Go

// 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"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"os"
"strconv"
"time"
)
func init() {
userCmd.AddCommand(userListCmd, userCreateCmd, userDeleteCmd, userUpdateCmd, userResetPasswordCmd, userChangeEnabledCmd)
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.",
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)
}
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()
},
}
var userCreateCmd = &cobra.Command{
Use: "create",
Short: "Create a new user.",
PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInit()
},
Run: func(cmd *cobra.Command, args []string) {
},
}
var userUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update an existing user.",
PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInit()
},
Run: func(cmd *cobra.Command, args []string) {
},
}
var userDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a user.",
PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInit()
},
Run: func(cmd *cobra.Command, args []string) {
},
}
var userResetPasswordCmd = &cobra.Command{
Use: "reset-password",
Short: "Reset a users password, either through mailing them a reset link or directly.",
PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInit()
},
Run: func(cmd *cobra.Command, args []string) {
// need flags
},
}
var userChangeEnabledCmd = &cobra.Command{
Use: "toggle-status",
Short: "Enable or disable a user.",
PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInit()
},
Run: func(cmd *cobra.Command, args []string) {
// Flag to either enable or disable
},
}