2024-10-13 16:16:19 +03:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.a71.su/Andrew71/pye/storage"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(findUserCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
var findUserCmd = &cobra.Command{
|
|
|
|
Use: "find <uuid/email> <query>",
|
|
|
|
Short: "Find a user",
|
|
|
|
Long: `Find information about a user from their UUID or email`,
|
|
|
|
Args: cobra.ExactArgs(2),
|
|
|
|
Run: findUser,
|
|
|
|
}
|
|
|
|
|
|
|
|
func findUser(cmd *cobra.Command, args []string) {
|
|
|
|
var user storage.User
|
|
|
|
var ok bool
|
|
|
|
if args[0] == "email" {
|
|
|
|
user, ok = storage.Data.ByEmail(args[1])
|
|
|
|
} else if args[0] == "uuid" {
|
|
|
|
user, ok = storage.Data.ById(args[1])
|
|
|
|
} else {
|
2024-10-13 17:33:59 +03:00
|
|
|
fmt.Println("Expected email or uuid")
|
2024-10-13 16:16:19 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if !ok {
|
|
|
|
fmt.Println("User not found")
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Information for user:\nuuid\t- %s\nemail\t- %s\nhash\t- %s\n",
|
|
|
|
user.Uuid, user.Email, user.Hash)
|
|
|
|
}
|
|
|
|
}
|