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.
Add Output Format to Find User Commands
- Loading branch information
1 parent
aeade8b
commit 1b47f83
Showing
3 changed files
with
59 additions
and
6 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 |
---|---|---|
|
@@ -2,11 +2,14 @@ package cmd | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
fAuth "firebase.google.com/go/auth" | ||
"github.com/mainawycliffe/kamanda/firebase" | ||
"github.com/mainawycliffe/kamanda/firebase/auth" | ||
"github.com/mainawycliffe/kamanda/utils" | ||
"github.com/mainawycliffe/kamanda/views" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
@@ -17,12 +20,22 @@ var byEmailCmd = &cobra.Command{ | |
Short: "Find a Firebase Auth user by email address", | ||
Example: `kamanda auth find by-email [email protected]`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
output, err := cmd.Flags().GetString("output") | ||
if err != nil { | ||
utils.StdOutError(os.Stderr, "Error reading output: %s", err.Error()) | ||
os.Exit(1) | ||
} | ||
if output != "json" && output != "yaml" && output != "" { | ||
utils.StdOutError(os.Stderr, "Unsupported output!") | ||
os.Exit(1) | ||
} | ||
// args = list of UIDs | ||
if len(args) == 0 { | ||
utils.StdOutError(os.Stderr, "at least one email is required!") | ||
os.Exit(1) | ||
} | ||
criteria := auth.ByUserEmailCriteria | ||
users := make([]*fAuth.ExportedUserRecord, 0) | ||
for _, email := range args { | ||
user, err := auth.GetUser(context.Background(), email, criteria) | ||
if err != nil { | ||
|
@@ -33,9 +46,21 @@ var byEmailCmd = &cobra.Command{ | |
utils.StdOutError(os.Stderr, "Error\t %s\t %s", email, err.Error()) | ||
continue | ||
} | ||
//@todo something with the output | ||
utils.StdOutSuccess(os.Stdout, "Success\t%s\t%s", email, user.UID) | ||
users = append(users, &fAuth.ExportedUserRecord{ | ||
UserRecord: user, | ||
}) | ||
} | ||
formatedUsers, err := utils.FormatResults(users, output) | ||
if err != nil && err.Error() != "Unknown Format" { | ||
utils.StdOutError(os.Stderr, "%s\n", err.Error()) | ||
os.Exit(1) | ||
} | ||
if formatedUsers != nil { | ||
fmt.Printf("%s\n", formatedUsers) | ||
os.Exit(0) | ||
} | ||
// draw table | ||
views.ViewUsersTable(users, "") | ||
os.Exit(0) | ||
}, | ||
} | ||
|
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
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