filebrowser/backend/cmd/users_update.go

41 lines
909 B
Go
Raw Normal View History

2023-09-02 17:24:55 +00:00
package cmd
import (
"github.com/spf13/cobra"
2024-10-07 22:44:53 +00:00
"github.com/gtsteffaniak/filebrowser/storage"
2023-09-02 17:24:55 +00:00
"github.com/gtsteffaniak/filebrowser/users"
2024-10-07 22:44:53 +00:00
"github.com/gtsteffaniak/filebrowser/utils"
2023-09-02 17:24:55 +00:00
)
func init() {
usersCmd.AddCommand(usersUpdateCmd)
}
var usersUpdateCmd = &cobra.Command{
Use: "update <id|username>",
Short: "Updates an existing user",
Long: `Updates an existing user. Set the flags for the
options you want to change.`,
Args: cobra.ExactArgs(1),
2024-10-07 22:44:53 +00:00
Run: cobraCmd(func(cmd *cobra.Command, args []string, store *storage.Storage) {
2023-09-02 17:24:55 +00:00
username, id := parseUsernameOrID(args[0])
var (
err error
user *users.User
)
if id != 0 {
2024-10-07 22:44:53 +00:00
user, err = store.Users.Get("", id)
2023-09-02 17:24:55 +00:00
} else {
2024-10-07 22:44:53 +00:00
user, err = store.Users.Get("", username)
2023-09-02 17:24:55 +00:00
}
2024-10-07 22:44:53 +00:00
utils.CheckErr("store.Users.Get", err)
2023-09-02 17:24:55 +00:00
2024-10-07 22:44:53 +00:00
err = store.Users.Update(user)
utils.CheckErr("store.Users.Update", err)
2023-09-02 17:24:55 +00:00
printUsers([]*users.User{user})
2024-10-07 22:44:53 +00:00
}),
2023-09-02 17:24:55 +00:00
}