This repository has been archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add 3 commands for finding users
find user by uid, email or phone
- Loading branch information
1 parent
b9fdf25
commit 7410f3e
Showing
3 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/mainawycliffe/kamanda/firebase" | ||
"github.com/mainawycliffe/kamanda/firebase/auth" | ||
"github.com/mainawycliffe/kamanda/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// byEmailCmd represents the byEmail command | ||
var byEmailCmd = &cobra.Command{ | ||
Use: "byEmail", | ||
Aliases: []string{"email"}, | ||
Short: "find a user by email address", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// args = list of uids | ||
if len(args) == 0 { | ||
utils.StdOutError("atleast one email is required!") | ||
os.Exit(1) | ||
} | ||
criteria := auth.ByUserEmailCriteria | ||
for _, email := range args { | ||
user, err := auth.GetUser(context.Background(), email, criteria) | ||
if err != nil { | ||
if firebase.IsUserNotFound(err) { | ||
utils.StdOutError("Not Found\t %s \t User was not found", email, err.Error()) | ||
continue | ||
} | ||
utils.StdOutError("Error\t %s\t %s", email, err.Error()) | ||
continue | ||
} | ||
//@todo something with the output | ||
utils.StdOutSuccess("Success\t%s\t%s", email, user.UID) | ||
} | ||
os.Exit(0) | ||
}, | ||
} | ||
|
||
func init() { | ||
findUserCmd.AddCommand(byEmailCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// byEmailCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// byEmailCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/mainawycliffe/kamanda/firebase" | ||
"github.com/mainawycliffe/kamanda/firebase/auth" | ||
"github.com/mainawycliffe/kamanda/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// byPhoneCmd represents the byPhone command | ||
var byPhoneCmd = &cobra.Command{ | ||
Use: "byPhone", | ||
Aliases: []string{"phone"}, | ||
Short: "find a user by phone number", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// args = list of phone numbers | ||
if len(args) == 0 { | ||
utils.StdOutError("atleast one Firebase user UID is required!") | ||
os.Exit(1) | ||
} | ||
criteria := auth.ByUserUIDCriteria | ||
for _, phone := range args { | ||
user, err := auth.GetUser(context.Background(), phone, criteria) | ||
if err != nil { | ||
if firebase.IsUserNotFound(err) { | ||
utils.StdOutError("Not Found\t %s \t %s", phone, err.Error()) | ||
continue | ||
} | ||
utils.StdOutError("Error\t%s\t%s", phone, err.Error()) | ||
continue | ||
} | ||
// @todo expand this list of users | ||
utils.StdOutSuccess("%s\tWas successfully Retrieved\n", user.UID) | ||
} | ||
os.Exit(0) | ||
}, | ||
} | ||
|
||
func init() { | ||
findUserCmd.AddCommand(byPhoneCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// byPhoneCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// byPhoneCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/mainawycliffe/kamanda/firebase" | ||
"github.com/mainawycliffe/kamanda/firebase/auth" | ||
"github.com/mainawycliffe/kamanda/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// findUserCmd represents the findUser command | ||
var findUserCmd = &cobra.Command{ | ||
Use: "find", | ||
Aliases: []string{"findUser"}, | ||
Short: "Find a user by uid. To find user by email or by phone use `find byEmail` or `find byPhone`", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// args = list of uids | ||
if len(args) == 0 { | ||
utils.StdOutError("atleast one Firebase user UID is required!") | ||
os.Exit(1) | ||
} | ||
criteria := auth.ByUserUIDCriteria | ||
for _, uid := range args { | ||
user, err := auth.GetUser(context.Background(), uid, criteria) | ||
if err != nil { | ||
if firebase.IsUserNotFound(err) { | ||
utils.StdOutError("Not Found\t %s \t %s", uid, err.Error()) | ||
continue | ||
} | ||
utils.StdOutError("Error \t %s \t %s", uid, err.Error()) | ||
continue | ||
} | ||
//@todo something with the output | ||
utils.StdOutSuccess("Success \t %s \t Was successfully Retrieved", user.UID) | ||
} | ||
os.Exit(0) | ||
}, | ||
} | ||
|
||
func init() { | ||
authCmd.AddCommand(findUserCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// findUserCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
findUserCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |