Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
Add User Output to Find By UID Command
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Apr 17, 2020
1 parent 71fb352 commit aeade8b
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion cmd/findUser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -19,12 +22,22 @@ var findUserCmd = &cobra.Command{
To find user by email or by phone use "find by-email" or "find by-phone"`,
Example: `kamanda auth find [UID1] [UID2]`,
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 Firebase user UID is required!")
os.Exit(1)
}
criteria := auth.ByUserUIDCriteria
users := make([]*fAuth.ExportedUserRecord, 0)
for _, uid := range args {
user, err := auth.GetUser(context.Background(), uid, criteria)
if err != nil {
Expand All @@ -36,8 +49,22 @@ To find user by email or by phone use "find by-email" or "find by-phone"`,
continue
}
//@todo something with the output
utils.StdOutSuccess(os.Stdout, "Success \t %s \t Was successfully Retrieved", 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)
},
}
Expand Down

0 comments on commit aeade8b

Please sign in to comment.