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

Commit

Permalink
feat: scafold some commands for firebase auth
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Aug 28, 2019
1 parent ccf81dc commit 6510a78
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 3 deletions.
45 changes: 45 additions & 0 deletions cmd/addUser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright © 2019 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// addUserCmd represents the addUser command
var addUserCmd = &cobra.Command{
Use: "addUser",
Short: "Add a new Firebase user",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("addUser called")
},
}

func init() {
authCmd.AddCommand(addUserCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// addUserCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// addUserCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
30 changes: 30 additions & 0 deletions cmd/addUsers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// addUsersCmd represents the addUsers command
var addUsersCmd = &cobra.Command{
Use: "addUsers",
Short: "Add new multiple Firebase Users",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("addUsers called")
},
}

func init() {
authCmd.AddCommand(addUsersCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// addUsersCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// addUsersCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
29 changes: 29 additions & 0 deletions cmd/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/spf13/cobra"
)

// authCmd represents the auth command
var authCmd = &cobra.Command{
Use: "auth",
Short: "Perform Firebase Auth Operations",
Long: `Perform Firebase Auth Operations`,
// Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("auth called")
// },
}

func init() {
rootCmd.AddCommand(authCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// authCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// authCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
42 changes: 42 additions & 0 deletions cmd/deleteUser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"fmt"
"log"
"context"

"github.com/mainawycliffe/firebase-cli/auth"
"github.com/spf13/cobra"
)

// deleteUserCmd represents the deleteUser command
var deleteUserCmd = &cobra.Command{
Use: "deleteUser",
Short: "Delete a Firebase User",
Run: func(cmd *cobra.Command, args []string) {

uid, err := cmd.Flags().GetString("uid")

if err != nil {
log.Fatalf("Error while reading uid flag: %s", err.Error())
}

fmt.Println(fmt.Sprintf("deleteUser called %v", uid))

// call firebase auth to delete firebase
err = auth.DeleteFirebaseUser(context.Background(), nil, uid)

if err != nil {
log.Fatalf("%s", err.Error())
}
},
}

func init() {
authCmd.AddCommand(deleteUserCmd)

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
deleteUserCmd.Flags().String("uid", "", "The UID of the Firebase User you want to delete (required)")
_ = deleteUserCmd.MarkFlagRequired("uid")
}
3 changes: 0 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ var rootCmd = &cobra.Command{
It provided addition functionality currently not available to via the Official
Firebase Tool such as Managing Users, Databases etc from the CLI.
`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down

0 comments on commit 6510a78

Please sign in to comment.