Skip to content

Commit

Permalink
Add auth whoami command
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed Dec 11, 2020
1 parent f61a1b6 commit 2811141
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"

"github.com/lincolnloop/apppack/auth"
"github.com/logrusorgru/aurora"
. "github.com/logrusorgru/aurora"
"github.com/pkg/browser"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -58,21 +59,30 @@ var loginCmd = &cobra.Command{
// logoutCmd represents the logout command
var logoutCmd = &cobra.Command{
Use: "logout",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Short: "Logout from AppPack.io on this device",
Long: `Logout from AppPack.io on this device`,
Run: func(cmd *cobra.Command, args []string) {
err := auth.Logout()
checkErr(err)
printSuccess("Logged out.")
},
}

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// whoAmICmd represents the whoami command
var whoAmICmd = &cobra.Command{
Use: "whoami",
Short: "Print login information for the current user",
Long: `Print login information for the current user`,
Run: func(cmd *cobra.Command, args []string) {
auth.Logout()
fmt.Println(Green(fmt.Sprintf("Logged out.")))
email, err := auth.WhoAmI()
checkErr(err)
printSuccess(fmt.Sprintf("You are currently logged in as %s", aurora.Bold(*email)))
},
}

func init() {
rootCmd.AddCommand(authCmd)
authCmd.AddCommand(loginCmd)
authCmd.AddCommand(logoutCmd)
authCmd.AddCommand(whoAmICmd)
}

0 comments on commit 2811141

Please sign in to comment.