pye/internal/app/find.go

41 lines
866 B
Go
Raw Permalink Normal View History

2024-10-13 21:03:44 +03:00
package app
2024-10-13 16:16:19 +03:00
import (
"fmt"
2024-10-13 21:03:44 +03:00
"git.a71.su/Andrew71/pye/internal/models/user"
"git.a71.su/Andrew71/pye/internal/storage"
2024-10-13 16:16:19 +03:00
"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) {
2024-10-13 21:03:44 +03:00
var user user.User
2024-10-13 16:16:19 +03:00
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)
}
}