Skip to content

Commit

Permalink
Merge pull request #5 from doneill/feature-jdo-21-token-auth-sub-command
Browse files Browse the repository at this point in the history
Add token auth subcommand
  • Loading branch information
doneill committed Nov 23, 2023
2 parents 799f00e + 86cc3ce commit 44664d4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (

const PROGRAM_NAME string = "er"
const CONFIG_TYPE string = ".toml"
const CONFIG_PATH string = "/Users/dano/.config/er/"

// const CONFIG_PATH string = "/Users/dano/.config/er/"

// ----------------------------------------------
// command
Expand Down Expand Up @@ -44,6 +45,6 @@ func init() {

func initConfig() {
viper.SetConfigName(PROGRAM_NAME)
viper.SetConfigType(CONFIG_TYPE)
viper.AddConfigPath(CONFIG_PATH)
viper.SetConfigType("toml")
viper.AddConfigPath(".")
}
46 changes: 46 additions & 0 deletions cmd/token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// ----------------------------------------------
// token command
// ----------------------------------------------

var tokenCmd = &cobra.Command{
Use: "token",
Short: "Display token",
Long: `Return the current users token`,
Run: func(cmd *cobra.Command, args []string) {
token()
},
}

// ----------------------------------------------
// funtions
// ----------------------------------------------

func token() {
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
fmt.Println("Error: er not configured properly, try reauthenticating")
} else {
fmt.Println("Error:", err)
}
} else {
var token = viper.Get("oauth_token")
fmt.Println(token)
}
}

// ----------------------------------------------
// initialize
// ----------------------------------------------

func init() {
authCmd.AddCommand(tokenCmd)
}

0 comments on commit 44664d4

Please sign in to comment.